1 // RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference -analyzer-output=text -verify
2 // RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference -analyzer-output=plist -o %t
3 // RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/conditional-path-notes.c.plist -
5 void testCondOp(int *p
) {
7 // expected-note@-1 {{Assuming 'p' is null}}
8 // expected-note@-2 {{'?' condition is false}}
9 // expected-note@-3 {{'x' initialized to a null pointer value}}
10 *x
= 1; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
11 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'x')}}
14 void testCondProblem(int *p
) {
16 // expected-note@-1 {{Assuming 'p' is null}}
17 // expected-note@-2 {{Taking false branch}}
19 int x
= *p
? 0 : 1; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}}
20 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
24 void testLHSProblem(int *p
) {
25 int x
= !p
? *p
: 1; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}}
26 // expected-note@-1 {{Assuming 'p' is null}}
27 // expected-note@-2 {{'?' condition is true}}
28 // expected-note@-3 {{Dereference of null pointer (loaded from variable 'p')}}
32 void testRHSProblem(int *p
) {
33 int x
= p
? 1 : *p
; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}}
34 // expected-note@-1 {{Assuming 'p' is null}}
35 // expected-note@-2 {{'?' condition is false}}
36 // expected-note@-3 {{Dereference of null pointer (loaded from variable 'p')}}
40 void testBinaryCondOp(int *p
) {
42 // expected-note@-1 {{'?' condition is false}}
43 // expected-note@-2 {{'x' initialized to a null pointer value}}
44 *x
= 1; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
45 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'x')}}
48 void testBinaryLHSProblem(int *p
) {
50 // expected-note@-1 {{Assuming 'p' is null}}
51 // expected-note@-2 {{Taking false branch}}
53 int x
= *p
?: 1; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}}
54 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
58 void testDiagnosableBranch(int a
) {
60 // expected-note@-1 {{Assuming 'a' is not equal to 0}}
61 // expected-note@-2 {{Taking true branch}}
62 *(volatile int *)0 = 1; // expected-warning{{Dereference of null pointer}}
63 // expected-note@-1 {{Dereference of null pointer}}
67 void testDiagnosableBranchLogical(int a
, int b
) {
69 // expected-note@-1 {{Assuming 'a' is not equal to 0}}
70 // expected-note@-2 {{Left side of '&&' is true}}
71 // expected-note@-3 {{Assuming 'b' is not equal to 0}}
72 // expected-note@-4 {{Taking true branch}}
73 *(volatile int *)0 = 1; // expected-warning{{Dereference of null pointer}}
74 // expected-note@-1 {{Dereference of null pointer}}
78 void testNonDiagnosableBranchArithmetic(int a
, int b
) {
80 // expected-note@-1 {{Taking true branch}}
81 // expected-note@-2 {{Assuming the condition is true}}
82 *(volatile int *)0 = 1; // expected-warning{{Dereference of null pointer}}
83 // expected-note@-1 {{Dereference of null pointer}}