CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
74 lines
3.5 KiB
C++
74 lines
3.5 KiB
C++
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s
|
|
|
|
struct S {
|
|
int *x;
|
|
int y;
|
|
};
|
|
|
|
S &getSomeReference();
|
|
void test(S *p) {
|
|
S &r = *p; //expected-note {{'r' initialized here}}
|
|
if (p) return;
|
|
//expected-note@-1{{Taking false branch}}
|
|
//expected-note@-2{{Assuming 'p' is null}}
|
|
r.y = 5; // expected-warning {{Access to field 'y' results in a dereference of a null pointer (loaded from variable 'r')}}
|
|
// expected-note@-1{{Access to field 'y' results in a dereference of a null pointer (loaded from variable 'r')}}
|
|
}
|
|
|
|
void testRefParam(int *ptr) {
|
|
int &ref = *ptr; // expected-note {{'ref' initialized here}}
|
|
if (ptr)
|
|
// expected-note@-1{{Assuming 'ptr' is null}}
|
|
// expected-note@-2{{Taking false branch}}
|
|
return;
|
|
|
|
extern void use(int &ref);
|
|
use(ref); // expected-warning{{Forming reference to null pointer}}
|
|
// expected-note@-1{{Forming reference to null pointer}}
|
|
}
|
|
|
|
int testRefToNullPtr() {
|
|
int *p = 0; // expected-note {{'p' initialized to a null pointer value}}
|
|
int *const &p2 = p; // expected-note{{'p2' initialized here}}
|
|
int *p3 = p2; // expected-note {{'p3' initialized to a null pointer value}}
|
|
return *p3; // expected-warning {{Dereference of null pointer}}
|
|
// expected-note@-1{{Dereference of null pointer}}
|
|
}
|
|
|
|
int testRefToNullPtr2() {
|
|
int *p = 0; // expected-note {{'p' initialized to a null pointer value}}
|
|
int *const &p2 = p; // expected-note{{'p2' initialized here}}
|
|
return *p2; //expected-warning {{Dereference of null pointer}}
|
|
// expected-note@-1{{Dereference of null pointer}}
|
|
}
|
|
|
|
void testMemberNullPointerDeref() {
|
|
struct Wrapper {char c; int *ptr; };
|
|
Wrapper w = {'a', nullptr}; // expected-note {{'w.ptr' initialized to a null pointer value}}
|
|
*w.ptr = 1; //expected-warning {{Dereference of null pointer}}
|
|
// expected-note@-1{{Dereference of null pointer}}
|
|
}
|
|
|
|
void testMemberNullReferenceDeref() {
|
|
struct Wrapper {char c; int &ref; };
|
|
Wrapper w = {.c = 'a', .ref = *(int *)0 }; // expected-note {{'w.ref' initialized to a null pointer value}}
|
|
// expected-warning@-1 {{binding dereferenced null pointer to reference has undefined behavior}}
|
|
w.ref = 1; //expected-warning {{Dereference of null pointer}}
|
|
// expected-note@-1{{Dereference of null pointer}}
|
|
}
|
|
|
|
void testReferenceToPointerWithNullptr() {
|
|
int *i = nullptr; // expected-note {{'i' initialized to a null pointer value}}
|
|
struct Wrapper {char c; int *&a;};
|
|
Wrapper w {'c', i}; // expected-note{{'w.a' initialized here}}
|
|
*(w.a) = 25; // expected-warning {{Dereference of null pointer}}
|
|
// expected-note@-1 {{Dereference of null pointer}}
|
|
}
|
|
|
|
void testNullReferenceToPointer() {
|
|
struct Wrapper {char c; int *&a;};
|
|
Wrapper w {'c', *(int **)0 }; // expected-note{{'w.a' initialized to a null pointer value}}
|
|
// expected-warning@-1 {{binding dereferenced null pointer to reference has undefined behavior}}
|
|
w.a = nullptr; // expected-warning {{Dereference of null pointer}}
|
|
// expected-note@-1 {{Dereference of null pointer}}
|
|
} |