diff options
| author | John Keeping <john@keeping.me.uk> | 2014-03-09 11:32:51 +0000 |
|---|---|---|
| committer | Christopher Li <sparse@chrisli.org> | 2014-04-01 00:19:50 -0700 |
| commit | 7698bae699639892d639b8a9c270efdb8c46725c (patch) | |
| tree | 5b73fae2ac4791097fc63c973dbf098ae14d5de0 /validation | |
| parent | 5798e4cf8fdb3090e4d4864e6d9824de69dfc786 (diff) | |
| download | sparse-dev-7698bae699639892d639b8a9c270efdb8c46725c.tar.gz | |
Support GCC's transparent unions
This stops warnings in code using socket operations with a modern glibc,
which otherwise result in warnings of the form:
warning: incorrect type in argument 2 (invalid types)
expected union __CONST_SOCKADDR_ARG [usertype] __addr
got struct sockaddr *<noident>
Since transparent unions are only applicable to function arguments, we
create a new function to check that the types are compatible
specifically in this context.
Also change the wording of the existing warning slightly since sparse
does now support them. The warning is left in case people want to avoid
using transparent unions.
Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/transparent-union.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/validation/transparent-union.c b/validation/transparent-union.c new file mode 100644 index 00000000..149c7d94 --- /dev/null +++ b/validation/transparent-union.c @@ -0,0 +1,25 @@ +struct a { + int field; +}; +struct b { + int field; +}; + +typedef union { + struct a *a; + struct b *b; +} transparent_arg __attribute__((__transparent_union__)); + +static void foo(transparent_arg arg) +{ +} + +static void bar(void) +{ + struct b arg = { 0 }; + foo((struct a *) &arg); +} + +/* + * check-name: Transparent union attribute. + */ |
