diff options
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/Waddress-space-all-attr.c | 14 | ||||
| -rw-r--r-- | validation/Waddress-space-from.c | 63 | ||||
| -rw-r--r-- | validation/Waddress-space-strict.c | 1 | ||||
| -rw-r--r-- | validation/Wcast-to-as.c | 36 | ||||
| -rw-r--r-- | validation/constexpr-constcond.c | 10 | ||||
| -rw-r--r-- | validation/constexpr-shift.c | 12 | ||||
| -rw-r--r-- | validation/enum-sign-extend.c | 12 | ||||
| -rw-r--r-- | validation/eval-bad-assign1.c | 14 | ||||
| -rw-r--r-- | validation/eval-bad-assign2.c | 22 | ||||
| -rw-r--r-- | validation/expand/bad-shift.c | 64 | ||||
| -rw-r--r-- | validation/ioc-typecheck.c | 4 |
11 files changed, 242 insertions, 10 deletions
diff --git a/validation/Waddress-space-all-attr.c b/validation/Waddress-space-all-attr.c index 5b2d0f92..b0c17693 100644 --- a/validation/Waddress-space-all-attr.c +++ b/validation/Waddress-space-all-attr.c @@ -13,27 +13,27 @@ static void expl(obj_t __kernel *k, obj_t __iomem *o, obj_t __user *p, obj_t __percpu *pc, obj_t __rcu *r) { - (ulong)(k); + (ulong)(k); (__UINTPTR_TYPE__)(k); (void *)(k); (obj_t*)(k); (obj_t __kernel*)(k); - (ulong)(o); + (ulong)(o); (__UINTPTR_TYPE__)(o); (void *)(o); (obj_t*)(o); (obj_t __iomem*)(o); - (ulong)(p); + (ulong)(p); (__UINTPTR_TYPE__)(p); (void *)(p); (obj_t*)(p); (obj_t __user*)(p); - (ulong)(pc); + (ulong)(pc); (__UINTPTR_TYPE__)(pc); (void *)(pc); (obj_t*)(pc); (obj_t __percpu*)(pc); - (ulong)(r); + (ulong)(r); (__UINTPTR_TYPE__)(r); (void *)(r); (obj_t*)(r); (obj_t __rcu*)(r); @@ -45,15 +45,19 @@ static void expl(obj_t __kernel *k, obj_t __iomem *o, * * check-error-start Waddress-space-all-attr.c:21:10: warning: cast removes address space '<asn:2>' of expression +Waddress-space-all-attr.c:21:22: warning: cast removes address space '<asn:2>' of expression Waddress-space-all-attr.c:22:10: warning: cast removes address space '<asn:2>' of expression Waddress-space-all-attr.c:23:10: warning: cast removes address space '<asn:2>' of expression Waddress-space-all-attr.c:26:10: warning: cast removes address space '<asn:1>' of expression +Waddress-space-all-attr.c:26:22: warning: cast removes address space '<asn:1>' of expression Waddress-space-all-attr.c:27:10: warning: cast removes address space '<asn:1>' of expression Waddress-space-all-attr.c:28:10: warning: cast removes address space '<asn:1>' of expression Waddress-space-all-attr.c:31:10: warning: cast removes address space '<asn:3>' of expression +Waddress-space-all-attr.c:31:23: warning: cast removes address space '<asn:3>' of expression Waddress-space-all-attr.c:32:10: warning: cast removes address space '<asn:3>' of expression Waddress-space-all-attr.c:33:10: warning: cast removes address space '<asn:3>' of expression Waddress-space-all-attr.c:36:10: warning: cast removes address space '<asn:4>' of expression +Waddress-space-all-attr.c:36:22: warning: cast removes address space '<asn:4>' of expression Waddress-space-all-attr.c:37:10: warning: cast removes address space '<asn:4>' of expression Waddress-space-all-attr.c:38:10: warning: cast removes address space '<asn:4>' of expression * check-error-end diff --git a/validation/Waddress-space-from.c b/validation/Waddress-space-from.c new file mode 100644 index 00000000..317a205b --- /dev/null +++ b/validation/Waddress-space-from.c @@ -0,0 +1,63 @@ + +#define __kernel __attribute__((address_space(0))) +#define __user __attribute__((address_space(__user))) +#define __iomem __attribute__((address_space(__iomem))) +#define __percpu __attribute__((address_space(__percpu))) +#define __rcu __attribute__((address_space(__rcu))) + + +typedef struct s obj_t; + +static void expl(obj_t __kernel *k, obj_t __iomem *o, + obj_t __user *p, obj_t __percpu *pc, + obj_t __rcu *r) +{ + (__UINTPTR_TYPE__)(k); // OK + (unsigned long)(k); // OK + (void *)(k); // OK + (obj_t*)(k); // OK + (obj_t __kernel*)(k); // OK + + (__UINTPTR_TYPE__)(o); // OK + (unsigned long)(o); // OK + (void *)(o); + (obj_t*)(o); + (obj_t __iomem*)(o); // OK + + (__UINTPTR_TYPE__)(p); // OK + (unsigned long)(p); // OK + (void *)(p); + (obj_t*)(p); + (obj_t __user*)(p); // OK + + (__UINTPTR_TYPE__)(pc); // OK + (unsigned long)(pc); // OK + (void *)(pc); + (obj_t*)(pc); + (obj_t __percpu*)(pc); // OK + + (__UINTPTR_TYPE__)(r); // OK + (unsigned long)(r); // OK + (void *)(r); + (obj_t*)(r); + (obj_t __rcu*)(r); // OK +} + +/* + * check-name: Waddress-space-from + * check-command: sparse -Wno-cast-from-as $file + * check-description: Test the removal of AS from a pointer but only + * in the non-strict variant where casts to ulong (or uintptr_t) + * are allowed. + * + * check-error-start +Waddress-space-from.c:23:10: warning: cast removes address space '__iomem' of expression +Waddress-space-from.c:24:10: warning: cast removes address space '__iomem' of expression +Waddress-space-from.c:29:10: warning: cast removes address space '__user' of expression +Waddress-space-from.c:30:10: warning: cast removes address space '__user' of expression +Waddress-space-from.c:35:10: warning: cast removes address space '__percpu' of expression +Waddress-space-from.c:36:10: warning: cast removes address space '__percpu' of expression +Waddress-space-from.c:41:10: warning: cast removes address space '__rcu' of expression +Waddress-space-from.c:42:10: warning: cast removes address space '__rcu' of expression + * check-error-end + */ diff --git a/validation/Waddress-space-strict.c b/validation/Waddress-space-strict.c index 7987eb1d..a1c5b277 100644 --- a/validation/Waddress-space-strict.c +++ b/validation/Waddress-space-strict.c @@ -27,7 +27,6 @@ static void expl(ulong u, void *v, obj_t *o, obj_t __user *p) * check-command: sparse -Wcast-from-as -Wcast-to-as $file * * check-error-start -Waddress-space-strict.c:9:10: warning: cast adds address space '<asn:1>' to expression Waddress-space-strict.c:12:10: warning: cast adds address space '<asn:1>' to expression Waddress-space-strict.c:17:10: warning: cast adds address space '<asn:1>' to expression Waddress-space-strict.c:19:10: warning: cast removes address space '<asn:1>' of expression diff --git a/validation/Wcast-to-as.c b/validation/Wcast-to-as.c new file mode 100644 index 00000000..8c512091 --- /dev/null +++ b/validation/Wcast-to-as.c @@ -0,0 +1,36 @@ +#define __user __attribute__((address_space(1))) + +typedef __UINTPTR_TYPE__ uintptr_t; +typedef unsigned long ulong; +typedef struct s obj_t; + +static void expl(ulong u, uintptr_t uip, void *v, obj_t *o, obj_t __user *p) +{ + (obj_t*)(u); + (obj_t __user*)(u); + + (obj_t*)(uip); + (obj_t __user*)(uip); + + (obj_t*)(v); + (obj_t __user*)(v); + + (ulong)(o); + (void *)(o); + (obj_t*)(o); + (obj_t __user*)(o); + + (ulong)(p); + (obj_t __user*)(p); + +} + +/* + * check-name: cast-to-as + * check-command: sparse -Wcast-to-as $file + * + * check-error-start +Wcast-to-as.c:16:10: warning: cast adds address space '<asn:1>' to expression +Wcast-to-as.c:21:10: warning: cast adds address space '<asn:1>' to expression + * check-error-end + */ diff --git a/validation/constexpr-constcond.c b/validation/constexpr-constcond.c new file mode 100644 index 00000000..d98da3dc --- /dev/null +++ b/validation/constexpr-constcond.c @@ -0,0 +1,10 @@ +extern int var; + +static int a[] = { + [0 ? var : 1] = 0, + [1 ? 2 : var] = 0, +}; + +/* + * check-name: constexprness in constant conditionals + */ diff --git a/validation/constexpr-shift.c b/validation/constexpr-shift.c new file mode 100644 index 00000000..df01b74e --- /dev/null +++ b/validation/constexpr-shift.c @@ -0,0 +1,12 @@ +#define __is_constexpr(x) \ + (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) + +static void test(int x) { + static int b[] = { + [__builtin_choose_expr(__is_constexpr(1 << 1), 1, x)] = 0, + }; +} + +/* + * check-name: constexpr-shift + */ diff --git a/validation/enum-sign-extend.c b/validation/enum-sign-extend.c new file mode 100644 index 00000000..d852c934 --- /dev/null +++ b/validation/enum-sign-extend.c @@ -0,0 +1,12 @@ +enum num { + a = 0x80000000, + b = -1, +}; + +_Static_assert([typeof(b)] == [long], "type"); +_Static_assert(b == -1L, "value"); + +/* + * check-name: enum-sign-extend + * check-command: sparse -m64 $file + */ diff --git a/validation/eval-bad-assign1.c b/validation/eval-bad-assign1.c new file mode 100644 index 00000000..57138c7a --- /dev/null +++ b/validation/eval-bad-assign1.c @@ -0,0 +1,14 @@ +static void kos(int *r, int a) +{ + r = ({ __builtin_types_compatible_p(int, int); }); +} + +/* + * check-name: eval-bad-assign1 + * + * check-error-start +eval-bad-assign1.c:3:11: warning: incorrect type in assignment (different base types) +eval-bad-assign1.c:3:11: expected int *r +eval-bad-assign1.c:3:11: got int + * check-error-end + */ diff --git a/validation/eval-bad-assign2.c b/validation/eval-bad-assign2.c new file mode 100644 index 00000000..4d08cb90 --- /dev/null +++ b/validation/eval-bad-assign2.c @@ -0,0 +1,22 @@ +struct s { + char c[1]; +}; + +struct s fun(void); + + +static void foo(void) +{ + char c[1]; + c = fun().c; +} + +/* + * check-name: eval-bad-assign2 + * + * check-error-start +eval-bad-assign2.c:11:11: warning: incorrect type in assignment (invalid types) +eval-bad-assign2.c:11:11: expected char c[1] +eval-bad-assign2.c:11:11: got char * + * check-error-end + */ diff --git a/validation/expand/bad-shift.c b/validation/expand/bad-shift.c new file mode 100644 index 00000000..22c4341f --- /dev/null +++ b/validation/expand/bad-shift.c @@ -0,0 +1,64 @@ +#define MAX (sizeof(int) * __CHAR_BIT__) + +static int lmax(int a) +{ + return 1 << MAX; +} + +static int lneg(int a) +{ + return 1 << -1; +} + +static int rmax(int a) +{ + return 1 >> MAX; +} + +static int rneg(int a) +{ + return 1 >> -1; +} + +/* + * check-name: bad-shift + * check-command: test-linearize -Wno-decl $file + * + * check-output-start +lmax: +.L0: + <entry-point> + shl.32 %r1 <- $1, $32 + ret.32 %r1 + + +lneg: +.L2: + <entry-point> + shl.32 %r3 <- $1, $0xffffffff + ret.32 %r3 + + +rmax: +.L4: + <entry-point> + asr.32 %r5 <- $1, $32 + ret.32 %r5 + + +rneg: +.L6: + <entry-point> + asr.32 %r7 <- $1, $0xffffffff + ret.32 %r7 + + + * check-output-end + * + * check-error-start +expand/bad-shift.c:5:18: warning: shift too big (32) for type int +expand/bad-shift.c:10:18: warning: shift count is negative (-1) +expand/bad-shift.c:15:18: warning: shift too big (32) for type int +expand/bad-shift.c:20:18: warning: shift count is negative (-1) + * check-error-end + */ diff --git a/validation/ioc-typecheck.c b/validation/ioc-typecheck.c index 34b37d31..7780773b 100644 --- a/validation/ioc-typecheck.c +++ b/validation/ioc-typecheck.c @@ -4,8 +4,4 @@ static unsigned iocnrs[] = { }; /* * check-name: integer constant & conditional expression - * check-known-to-fail - * - * check-error-start - * check-error-end */ |
