xref: /illumos-gate/usr/src/tools/smatch/src/validation/constexpr-addr-of-static.c (revision f52943a93040563107b95bccb9db87d9971ef47d)
1 static int a = 1;
2 static int b[2] = {1, 1};
3 static void c(void) {}
4 
5 static int *d = &a;		// OK
6 static int *e = d;		// KO
7 static int *f = b;		// OK
8 
9 static void (*g)(void) = c;	// OK
10 static void (*h)(void) = &c;	// OK
11 
12 static int *i = &*&a;		// OK
13 static int *j = &*b;		// OK
14 static int *k = &*d;		// KO
15 
16 
17 static void l(void) {
18 	int a = 1;
19 	static int *b = &a;	// KO
20 }
21 
22 static void m(void) {
23 	static int a = 1;
24 	static int *b = &a;	// OK
25 }
26 
27 /*
28  * check-name: constexpr static object address
29  * check-command: sparse -Wconstexpr-not-const $file
30  *
31  * check-error-start
32 constexpr-addr-of-static.c:6:17: warning: non-constant initializer for static object
33 constexpr-addr-of-static.c:14:19: warning: non-constant initializer for static object
34 constexpr-addr-of-static.c:19:26: warning: non-constant initializer for static object
35  * check-error-end
36  */
37