[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Analysis / globals.cpp
blobfc74161375f13b8ad2ae062ac51d74d4826f22fb
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify -std=c++2a %s
4 static const unsigned long long scull = 0;
5 void static_int()
7 *(int*)scull = 0; // expected-warning{{Dereference of null pointer}}
10 const unsigned long long cull = 0;
11 void const_int()
13 *(int*)cull = 0; // expected-warning{{Dereference of null pointer}}
16 static int * const spc = 0;
17 void static_ptr()
19 *spc = 0; // expected-warning{{Dereference of null pointer}}
22 int * const pc = 0;
23 void const_ptr()
25 *pc = 0; // expected-warning{{Dereference of null pointer}}
28 const unsigned long long cull_nonnull = 4;
29 void nonnull_int()
31 *(int*)(cull_nonnull - 4) = 0; // expected-warning{{Dereference of null pointer}}
34 int * const pc_nonnull = (int*)sizeof(int);
35 void nonnull_ptr()
37 *(pc_nonnull - 1) = 0; // expected-warning{{Dereference of null pointer}}
40 int * const constcast = const_cast<int * const>((int*)sizeof(int));
41 void cast1()
43 *(constcast - 1) = 0; // expected-warning{{Dereference of null pointer}}
46 int * const recast = reinterpret_cast<int*>(sizeof(int));
47 void cast2()
49 *(recast - 1) = 0; // expected-warning{{Dereference of null pointer}}
52 int * const staticcast = static_cast<int * const>((int*)sizeof(int));
53 void cast3()
55 *(staticcast - 1) = 0; // expected-warning{{Dereference of null pointer}}
58 struct Foo { int a; };
59 Foo * const dyncast = dynamic_cast<Foo * const>((Foo*)sizeof(Foo));
60 void cast4()
62 // Do not handle dynamic_cast for now, because it may change the pointer value.
63 (dyncast - 1)->a = 0; // no-warning
66 typedef int * const intptrconst;
67 int * const funccast = intptrconst(sizeof(int));
68 void cast5()
70 *(funccast - 1) = 0; // expected-warning{{Dereference of null pointer}}
73 struct S1
75 int * p;
77 const S1 s1 = {
78 .p = (int*)sizeof(int)
80 void conststruct()
82 *(s1.p - 1) = 0; // expected-warning{{Dereference of null pointer}}
85 struct S2
87 int * const p;
89 S2 s2 = {
90 .p = (int*)sizeof(int)
92 void constfield()
94 *(s2.p - 1) = 0; // expected-warning{{Dereference of null pointer}}
97 int * const parr[1] = { (int*)sizeof(int) };
98 void constarr()
100 *(parr[0] - 1) = 0; // expected-warning{{Dereference of null pointer}}
103 struct S3
105 int * p = (int*)sizeof(int);
107 void recordinit()
109 S3 s3;
110 *(s3.p - 1) = 0; // expected-warning{{Dereference of null pointer}}
113 extern int ext_int;
115 void update_original_declaration() {
116 ext_int = 2;
119 extern int ext_int;
121 int test_redeclaration() {
122 ext_int = 1;
123 update_original_declaration();
124 int int_int = 3 / (ext_int - 1); // no-warning
125 return int_int / (ext_int - 2); // expected-warning{{Division by zero}}