[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Analysis / conditional-path-notes.c
blob5ef81d81a0fd4dc41b82727b58189fada4859938
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) {
6 int *x = p ? p : 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) {
15 if (p) return;
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')}}
21 (void)x;
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')}}
29 (void)x;
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')}}
37 (void)x;
40 void testBinaryCondOp(int *p) {
41 int *x = p ?: 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) {
49 if (p) return;
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')}}
55 (void)x;
58 void testDiagnosableBranch(int a) {
59 if (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) {
68 if (a && 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) {
79 if (a - 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}}