db/fixup_kernel.sh: fix clear_user() handling
[smatch.git] / validation / autotype.c
blob98683c93d2e8837cec46b6c6a244083166b35565
1 #ifdef __CHECKER__
2 #define is_type(X, T) _Static_assert([typeof(X)] == [T], "")
3 #else
4 #define is_type(X, T) _Static_assert(1, "")
5 #endif
7 struct s {
8 int x;
9 int bf:3;
12 extern char ch;
13 extern const int ci;
15 __auto_type i = 0; is_type(i, int);
16 __auto_type m = 1UL; is_type(m, unsigned long);
17 __auto_type l = (int)0L; is_type(l, int);
18 __auto_type c = (char)'\n'; is_type(c, char);
19 __auto_type p = &i; is_type(p, int *);
20 __auto_type f = 0.0; is_type(f, double);
21 __auto_type s = (struct s){0}; is_type(s, struct s);
22 __auto_type pci = &ci; is_type(pci, const int *);
24 // ~~: not valid for bitfield
25 __auto_type b = (struct s){0}.bf; is_type(b, int);
27 static __auto_type si = 0; is_type(si, int);
28 const __auto_type ci = 0; is_type(ci, const int);
29 __auto_type ch = (char) '\n'; is_type(ch, char);
31 static int foo(int a)
33 __auto_type i = a; is_type(i, int);
34 __auto_type c = ch; is_type(c, char);
35 __auto_type ct = ci; is_type(&ct, const int *);
37 return ct += i + c;
42 #define __as __attribute__((address_space(42)))
43 extern int __as aa;
45 __auto_type pa = &aa; is_type(pa, int __as *);
48 * check-name: autotype
49 * check-command: sparse -Wno-decl $file
51 * check-error-start
52 autotype.c:25:13: warning: __auto_type on bitfield
53 autotype.c:37:16: error: assignment to const expression
54 * check-error-end