diff options
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/backend/hello.c | 2 | ||||
| -rw-r--r-- | validation/backend/sum.c | 3 | ||||
| -rw-r--r-- | validation/bitfield-sizes.c | 30 | ||||
| -rw-r--r-- | validation/c11-atomic.c | 2 | ||||
| -rw-r--r-- | validation/eval/premature-examination.c | 27 | ||||
| -rw-r--r-- | validation/nocast.c | 10 | ||||
| -rw-r--r-- | validation/restrict.c | 2 |
7 files changed, 69 insertions, 7 deletions
diff --git a/validation/backend/hello.c b/validation/backend/hello.c index b0e514be..eb89846f 100644 --- a/validation/backend/hello.c +++ b/validation/backend/hello.c @@ -1,4 +1,4 @@ -#include <stdio.h> +int puts(const char *s); int main(int argc, char *argv[]) { diff --git a/validation/backend/sum.c b/validation/backend/sum.c index fa51120e..38ebf41e 100644 --- a/validation/backend/sum.c +++ b/validation/backend/sum.c @@ -1,5 +1,4 @@ -#include <stdio.h> -#include <stdlib.h> +int printf(const char * fmt, ...); static int sum(int n) { diff --git a/validation/bitfield-sizes.c b/validation/bitfield-sizes.c new file mode 100644 index 00000000..9f76d074 --- /dev/null +++ b/validation/bitfield-sizes.c @@ -0,0 +1,30 @@ +struct a { + int a:31; + int b:32; + long c:63; + long d:64; + int x:33; // KO + long y:65; // KO +}; +static struct a a; + +struct b { + int m1:-1; // KO + int x1:2147483648; // KO + int :0; + int a0:0; // KO +}; +static struct b b; + +/* + * check-name: bitfield-sizes + * check-command: sparse -m64 $file + * + * check-error-start +bitfield-sizes.c:12:18: error: bitfield 'm1' has invalid width (-1) +bitfield-sizes.c:13:26: error: bitfield 'x1' has invalid width (2147483648) +bitfield-sizes.c:15:17: error: bitfield 'a0' has invalid width (0) +bitfield-sizes.c:6:15: error: bitfield 'x' is wider (33) than its type (int) +bitfield-sizes.c:7:15: error: bitfield 'y' is wider (65) than its type (long) + * check-error-end + */ diff --git a/validation/c11-atomic.c b/validation/c11-atomic.c index e87d06cd..fc2c27ae 100644 --- a/validation/c11-atomic.c +++ b/validation/c11-atomic.c @@ -66,7 +66,7 @@ void baz(void) /* * check-name: C11 _Atomic type qualifier - * check-command: sparse -Wno-decl $file; + * check-command: sparse -Wno-decl $file * * check-error-start c11-atomic.c:11:6: error: symbol 'f02' redeclared with different type (originally declared at c11-atomic.c:3) - incompatible argument 1 (different modifiers) diff --git a/validation/eval/premature-examination.c b/validation/eval/premature-examination.c new file mode 100644 index 00000000..bd2ffa90 --- /dev/null +++ b/validation/eval/premature-examination.c @@ -0,0 +1,27 @@ +extern int i; + +int foo(void) +{ + return *i; +} + +int bar(void) +{ + return i[0]; +} + +int *qux(void) +{ + return &i[0]; +} + +/* + * check-name: premature-examination + * check-command: sparse -Wno-decl $file + * + * check-error-start +eval/premature-examination.c:5:16: error: cannot dereference this type +eval/premature-examination.c:10:17: error: cannot dereference this type +eval/premature-examination.c:15:18: error: cannot dereference this type + * check-error-end + */ diff --git a/validation/nocast.c b/validation/nocast.c index 6c5da968..2113227c 100644 --- a/validation/nocast.c +++ b/validation/nocast.c @@ -26,8 +26,8 @@ static ulong_nc_t good_deref(ulong_nc_t *t) /* assign value */ static ulong_nc_t t; -static ulong_nc_t good_assign_self = t; -static unsigned long good_assign_sametype = t; + + /* assign pointer */ static ulong_nc_t *good_ptr = &t; @@ -150,6 +150,12 @@ static unsigned long bad_fromcast(ulong_nc_t v) return (unsigned long) v; } +static void assign_value(void) +{ + ulong_nc_t good_assign_self = t; + unsigned long good_assign_sametype = t; +} + /* * check-name: nocast.c * diff --git a/validation/restrict.c b/validation/restrict.c index 92bfdae8..80c437b0 100644 --- a/validation/restrict.c +++ b/validation/restrict.c @@ -66,7 +66,7 @@ void baz(void) /* * check-name: restrict qualifier - * check-command: sparse -Wno-decl $file; + * check-command: sparse -Wno-decl $file * * check-error-start restrict.c:11:6: error: symbol 'f02' redeclared with different type (originally declared at restrict.c:3) - incompatible argument 1 (different modifiers) |
