xref: /illumos-gate/usr/src/tools/smatch/src/validation/constexpr-pointer-arith.c (revision 8226594fdd4479be135127f43632f1f995074654)
1 static int a = 1;
2 static int b[2] = {1, 1};
3 
4 static int *c = &b[1];					// OK
5 static int *d = (int*)0 + 1;				// OK
6 static int *e = &b[1] + 1;				// OK
7 static int *f = b + 1;					// OK
8 static int *g = d + 1;					// KO
9 static int *h = &a + 1;				// OK
10 static int *i = &b[1] + 1;				// OK
11 static int *j = b + 1;					// OK
12 static int *k = d + 1;					// KO
13 static int *l = &*&b[1];				// OK
14 static int *m = &*(&a + 1);				// OK
15 static int *n = &*(&b[1] + 1);				// OK
16 static int *o = &*(b + 1);				// OK
17 static int *p = &*(d + 1);				// KO
18 
19 /*
20  * check-name: consrexprness pointer arithmetic
21  * check-command: sparse -Wconstexpr-not-const $file
22  *
23  * check-error-start
24 constexpr-pointer-arith.c:8:19: warning: non-constant initializer for static object
25 constexpr-pointer-arith.c:12:19: warning: non-constant initializer for static object
26 constexpr-pointer-arith.c:17:22: warning: non-constant initializer for static object
27  * check-error-end
28  */
29