diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-05-27 18:11:54 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-05-27 18:15:26 +0200 |
| commit | ed5dcc156b3651d089059c4f93c70229490c086c (patch) | |
| tree | 642c7940641bb1d8cf687f16efaab85b99286aa7 /validation | |
| parent | 943416a743501230f89879fa63d8186694df2e55 (diff) | |
| parent | 0062618881aa58f885ac78dc20c6fd2823c751b0 (diff) | |
| download | sparse-dev-ed5dcc156b3651d089059c4f93c70229490c086c.tar.gz | |
Merge branch 'vla-sizeof' into tip
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/vla-sizeof-ice.c | 19 | ||||
| -rw-r--r-- | validation/vla-sizeof0.c | 20 | ||||
| -rw-r--r-- | validation/vla-sizeof1.c | 21 | ||||
| -rw-r--r-- | validation/vla-sizeof2.c | 21 | ||||
| -rw-r--r-- | validation/vla-sizeof3.c | 21 | ||||
| -rw-r--r-- | validation/vla-sizeof4.c | 22 |
6 files changed, 124 insertions, 0 deletions
diff --git a/validation/vla-sizeof-ice.c b/validation/vla-sizeof-ice.c new file mode 100644 index 00000000..472da6a4 --- /dev/null +++ b/validation/vla-sizeof-ice.c @@ -0,0 +1,19 @@ +// credit goes to Martin Uecker for the awesome ICE_P macro + +#define ICE_P(x) \ + (__builtin_types_compatible_p(typeof(0?((void*)((long)(x)*0l)):(int*)1),int*)) + +#define T(x) __builtin_choose_expr(ICE_P(x), 1, 0) +#define TEST(x, r) _Static_assert(T(x) == r, #x " => " #r) + +static void test(int n) +{ + char foo[n++]; + + TEST(sizeof(foo), 0); +} + +/* + * check-name: vla-sizeof-ice + * check-command: sparse -Wno-vla $file + */ diff --git a/validation/vla-sizeof0.c b/validation/vla-sizeof0.c new file mode 100644 index 00000000..a58fd300 --- /dev/null +++ b/validation/vla-sizeof0.c @@ -0,0 +1,20 @@ +#define N 2 +#define T int + +static unsigned int foo(int x) +{ + T a[(1,N)]; + + return sizeof(a) == (N * sizeof(T)); +} + +/* + * check-name: vla-sizeof cte,cte + * check-command: test-linearize -Wvla $file + * + * check-output-ignore + * check-output-contains: ret\\.32 *\\$1 + * + * check-error-start + * check-error-end + */ diff --git a/validation/vla-sizeof1.c b/validation/vla-sizeof1.c new file mode 100644 index 00000000..ed7f5d4e --- /dev/null +++ b/validation/vla-sizeof1.c @@ -0,0 +1,21 @@ +#define N 2 +#define T int + +static unsigned int foo(int x) +{ + T a[(x,N)]; + + return sizeof(a) == (N * sizeof(T)); +} + +/* + * check-name: vla-sizeof var,cte + * check-command: test-linearize -Wvla $file + * + * check-output-ignore + * check-output-contains: ret\\.32 *\\$1 + * + * check-error-start +vla-sizeof1.c:6:15: warning: Variable length array is used. + * check-error-end + */ diff --git a/validation/vla-sizeof2.c b/validation/vla-sizeof2.c new file mode 100644 index 00000000..57927d16 --- /dev/null +++ b/validation/vla-sizeof2.c @@ -0,0 +1,21 @@ +#define N 2 +#define T int + +static unsigned long foo(int x) +{ + T a[x]; + + return sizeof(a) == (x * sizeof(T)); +} + +/* + * check-name: vla-sizeof var + * check-command: test-linearize -Wvla $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$1 + * + * check-error-start +vla-sizeof2.c:6:13: warning: Variable length array is used. + * check-error-end + */ diff --git a/validation/vla-sizeof3.c b/validation/vla-sizeof3.c new file mode 100644 index 00000000..21edb007 --- /dev/null +++ b/validation/vla-sizeof3.c @@ -0,0 +1,21 @@ +#define N 2UL +#define T int + +static unsigned long foo(int x) +{ + T a[x][N]; + + return sizeof(a) == (N * x * sizeof(T)); +} + +/* + * check-name: vla-sizeof var X cte + * check-command: test-linearize -Wvla $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$1 + * + * check-error-start +vla-sizeof3.c:6:13: warning: Variable length array is used. + * check-error-end + */ diff --git a/validation/vla-sizeof4.c b/validation/vla-sizeof4.c new file mode 100644 index 00000000..e7478613 --- /dev/null +++ b/validation/vla-sizeof4.c @@ -0,0 +1,22 @@ +#define N 2 +#define T int + +static unsigned long foo(int x, int y) +{ + T a[x][y]; + + return sizeof(a) == (x * (y * sizeof(T))); +} + +/* + * check-name: vla-sizeof var X var + * check-command: test-linearize -Wvla $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$1 + * + * check-error-start +vla-sizeof4.c:6:16: warning: Variable length array is used. +vla-sizeof4.c:6:13: warning: Variable length array is used. + * check-error-end + */ |
