diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-08-15 16:49:17 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-08-15 17:08:03 +0200 |
commit | c73a5a4bbcb30f176be5b82969b5d681b8481bc5 (patch) | |
tree | c1dae75edf7348a8df2dd7a37b1ccd2d153df256 | |
parent | 49f7e13a7ac9a582d11e9c1ad01e71740f486601 (diff) | |
download | sparse-c73a5a4bbcb30f176be5b82969b5d681b8481bc5.tar.gz |
union-cast: add some testcases
Casts to union type are a GCC extension and are similar to
compound literals.
However, sparse doesn't know about them and treats them like
other casts to non-scalars.
Add some testcases for this and its upcoming warning flag.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | validation/eval/union-cast-no.c | 24 | ||||
-rw-r--r-- | validation/eval/union-cast.c | 25 |
2 files changed, 49 insertions, 0 deletions
diff --git a/validation/eval/union-cast-no.c b/validation/eval/union-cast-no.c new file mode 100644 index 00000000..d06b348d --- /dev/null +++ b/validation/eval/union-cast-no.c @@ -0,0 +1,24 @@ +union u { + int i; + char x[8]; +}; + +static union u foo(int i) +{ + return (union u)i; +} + +static union u bar(long l) +{ + return (union u)l; +} + +/* + * check-name: union-cast-no + * check-command: sparse -Wno-union-cast $file + * check-known-to-fail + * + * check-error-start +eval/union-cast-no.c:13:17: warning: cast to non-scalar + * check-error-end + */ diff --git a/validation/eval/union-cast.c b/validation/eval/union-cast.c new file mode 100644 index 00000000..1d816753 --- /dev/null +++ b/validation/eval/union-cast.c @@ -0,0 +1,25 @@ +union u { + int i; + char x[8]; +}; + +static union u foo(int a) +{ + return (union u)a; +} + +static union u bar(long a) +{ + return (union u)a; +} + +/* + * check-name: union-cast + * check-command: sparse -Wunion-cast $file + * check-known-to-fail + * + * check-error-start +eval/union-cast.c:8:17: warning: cast to union type +eval/union-cast.c:13:17: warning: cast to non-scalar + * check-error-end + */ |