1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config suppress-inlined-defensive-checks=true -verify %s
3 // Perform inline defensive checks.
12 return *p; // expected-warning {{Dereference of null pointer}}
15 int test02(int *p, int *x) {
21 return *p; // expected-warning {{Dereference of null pointer}}
24 int test03(int *p, int *x) {
28 return *p; // False negative
32 return *p; // expected-warning {{Dereference of null pointer}}
42 int test11(int *q, int *x) {
48 return *p; // expected-warning{{Dereference of null pointer}}
63 int test21(int *q, int *x) {
69 return *p; // expected-warning{{Dereference of null pointer}}
72 int test22(int *q, int *x) {
80 int test23(int *q, int *x) {
87 return *p; // False negative
96 void test24(char *buffer) {
101 // Ensure idc works on pointers with constant offset.
102 void idcchar(const char *s2) {
106 void testConstantOffset(char *value) {
107 char *cursor = value + 5;
114 // Ensure idc works for integer zero values (ex: suppressed div by zero).
115 void idcZero(int assume) {
120 int idcTriggerZeroValue(int m) {
122 return 5/m; // no-warning
125 int idcTriggerZeroValueThroughCall(int i) {
126 return 5/i; // no-warning
128 void idcTrackZeroValueThroughCall(int x) {
130 idcTriggerZeroValueThroughCall(x);
133 int idcTriggerZeroThroughDoubleAssignemnt(int i) {
134 return 5/i; // no-warning
136 void idcTrackZeroThroughDoubleAssignemnt(int x) {
140 idcTriggerZeroValueThroughCall(z);
148 void idcTrackZeroValueThroughUnaryPointerOperators(struct S *s) {
150 *(&(s->f1)) = 7; // no-warning
153 void idcTrackZeroValueThroughUnaryPointerOperatorsWithOffset1(struct S *s) {
156 *x = 7; // no-warning
159 void idcTrackZeroValueThroughUnaryPointerOperatorsWithOffset2(struct S *s) {
161 int *x = &(s->f2) - 1;
162 *x = 7; // no-warning
165 void idcTrackZeroValueThroughUnaryPointerOperatorsWithAssignment(struct S *s) {
168 *x = 7; // no-warning
171 void idcTrackZeroValueThroughManyUnaryPointerOperatorsWithAssignment(struct S *s) {
174 *x = 7; // no-warning
177 void idcTrackZeroValueThroughManyUnaryPointerOperatorsWithAssignmentAndUnaryIncrement(struct S *s) {
179 int *x = &*&((++s)->f1);
180 *x = 7; // no-warning
188 void idcTrackZeroValueThroughUnaryPointerOperatorsWithArrayField(struct S2 *s) {
190 *(&(s->a[0])) = 7; // no-warning
193 void idcTrackConstraintThroughSymbolicRegion(int **x) {
195 // FIXME: Should not warn.
196 **x = 7; // expected-warning{{Dereference of null pointer}}
199 void idcTrackConstraintThroughSymbolicRegionAndParens(int **x) {
201 // FIXME: Should not warn.
202 *(*x) = 7; // expected-warning{{Dereference of null pointer}}
205 int *idcPlainNull(int coin) {
212 void idcTrackZeroValueThroughSymbolicRegion(int coin, int **x) {
213 *x = idcPlainNull(coin);
214 **x = 7; // no-warning
217 void idcTrackZeroValueThroughSymbolicRegionAndParens(int coin, int **x) {
218 *x = idcPlainNull(coin);
219 *(*x) = 7; // no-warning
227 struct WithInt arr[1];
230 struct WithArray *idcPlainNullWithArray(int coin) {
233 static struct WithArray S;
237 void idcTrackZeroValueThroughSymbolicRegionWithArray(int coin, struct WithArray **s) {
238 *s = idcPlainNullWithArray(coin);
239 (*s)->arr[0].i = 1; // no-warning
241 (*s)->arr->i = 1; // no-warning