xref: /illumos-gate/usr/src/tools/smatch/src/validation/typeof-mods.c (revision 1f5207b7604fb44407eb4342aff613f7c4508508)
1 #define	__noderef	__attribute__((noderef))
2 #define	__bitwise	__attribute__((bitwise))
3 #define	__nocast	__attribute__((nocast))
4 #define	__safe		__attribute__((safe))
5 
6 static void test_spec(void)
7 {
8 	unsigned int obj, *ptr;
9 	typeof(obj) var = obj;
10 	typeof(ptr) ptr2 = ptr;
11 	typeof(*ptr) var2 = obj;
12 	typeof(*ptr) *ptr3 = ptr;
13 	typeof(obj) *ptr4 = ptr;
14 	obj = obj;
15 	ptr = ptr;
16 	ptr = &obj;
17 	obj = *ptr;
18 }
19 
20 static void test_const(void)
21 {
22 	const int obj, *ptr;
23 	typeof(obj) var = obj;
24 	typeof(ptr) ptr2 = ptr;
25 	typeof(*ptr) var2 = obj;
26 	typeof(*ptr) *ptr3 = ptr;
27 	typeof(obj) *ptr4 = ptr;
28 	ptr = ptr;
29 	ptr = &obj;
30 }
31 
32 static void test_volatile(void)
33 {
34 	volatile int obj, *ptr;
35 	typeof(obj) var = obj;
36 	typeof(ptr) ptr2 = ptr;
37 	typeof(*ptr) var2 = obj;
38 	typeof(*ptr) *ptr3 = ptr;
39 	typeof(obj) *ptr4 = ptr;
40 	obj = obj;
41 	ptr = ptr;
42 	ptr = &obj;
43 	obj = *ptr;
44 }
45 
46 static void test_bitwise(void)
47 {
48 	typedef int __bitwise type_t;
49 	type_t obj, *ptr;
50 	typeof(obj) var = obj;
51 	typeof(ptr) ptr2 = ptr;
52 	typeof(*ptr) var2 = obj;
53 	typeof(*ptr) *ptr3 = ptr;
54 	typeof(obj) *ptr4 = ptr;
55 	obj = obj;
56 	ptr = ptr;
57 	ptr = &obj;
58 	obj = *ptr;
59 }
60 
61 static void test_static(void)
62 {
63 	static int obj, *ptr;
64 	typeof(obj) var = obj;
65 	typeof(ptr) ptr2 = ptr;
66 	typeof(*ptr) var2 = obj;
67 	typeof(*ptr) *ptr3 = ptr;
68 	typeof(obj) *ptr4 = ptr;
69 	obj = obj;
70 	ptr = ptr;
71 	ptr = &obj;
72 	obj = *ptr;
73 }
74 
75 static void test_tls(void)
76 {
77 	__thread int obj, *ptr;
78 	typeof(obj) var = obj;
79 	typeof(ptr) ptr2 = ptr;
80 	typeof(*ptr) var2 = obj;
81 	typeof(*ptr) *ptr3 = ptr;
82 	typeof(obj) *ptr4 = ptr;
83 	obj = obj;
84 	ptr = ptr;
85 	ptr = &obj;
86 	obj = *ptr;
87 }
88 
89 static void test_nocast(void)
90 {
91 	int __nocast obj, *ptr;
92 	typeof(obj) var = obj;
93 	typeof(ptr) ptr2 = ptr;
94 	typeof(*ptr) var2 = obj;
95 	typeof(*ptr) *ptr3 = ptr;
96 	typeof(obj) *ptr4 = ptr;
97 	obj = obj;
98 	ptr = ptr;
99 	ptr = &obj;
100 	obj = *ptr;
101 }
102 
103 /*
104  * check-name: typeof-mods
105  *
106  * check-error-start
107  * check-error-end
108  */
109