diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-12-19 21:03:55 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-12-19 21:03:55 +0100 |
| commit | 41c40878c422428749f29a5fa2c7b198a8ef9921 (patch) | |
| tree | 9e957d1fa5e3a7931bc6e003f8868bb01a77c944 /validation | |
| parent | 1cf02bb504bdb0e3a54e52e173cf48d1928a00ce (diff) | |
| parent | 6002ded74587a1469fcd930dd46dc89eb3307982 (diff) | |
| download | sparse-dev-41c40878c422428749f29a5fa2c7b198a8ef9921.tar.gz | |
Merge branch 'bitwise-ptr'
* warn on casts to/from bitwise pointers
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/bitwise-cast-ptr.c | 33 | ||||
| -rw-r--r-- | validation/bitwise-cast.c | 6 |
2 files changed, 39 insertions, 0 deletions
diff --git a/validation/bitwise-cast-ptr.c b/validation/bitwise-cast-ptr.c new file mode 100644 index 00000000..3f2bfdaf --- /dev/null +++ b/validation/bitwise-cast-ptr.c @@ -0,0 +1,33 @@ +#define __bitwise __attribute__((bitwise)) +#define __force __attribute__((force)) + +typedef unsigned int u32; +typedef unsigned int __bitwise __be32; + +static __be32* tobi(u32 *x) +{ + return x; // should warn, implicit cast +} + +static __be32* tobe(u32 *x) +{ + return (__be32 *) x; // should warn, explicit cast +} + +static __be32* tobf(u32 *x) +{ + return (__force __be32 *) x; // should not warn, forced cast + return (__be32 __force *) x; // should not warn, forced cast +} + +/* + * check-name: cast of bitwise pointers + * check-command: sparse -Wbitwise -Wbitwise-pointer $file + * + * check-error-start +bitwise-cast-ptr.c:9:16: warning: incorrect type in return expression (different base types) +bitwise-cast-ptr.c:9:16: expected restricted __be32 [usertype] * +bitwise-cast-ptr.c:9:16: got unsigned int [usertype] *x +bitwise-cast-ptr.c:14:17: warning: cast to restricted __be32 [usertype] *<noident> + * check-error-end + */ diff --git a/validation/bitwise-cast.c b/validation/bitwise-cast.c index baeca29e..0583461c 100644 --- a/validation/bitwise-cast.c +++ b/validation/bitwise-cast.c @@ -29,6 +29,12 @@ static __be32 quux(void) return (__be32)1729; } +/* Explicit case of nonzero forced, legal */ +static __be32 quuy(void) +{ + return (__attribute__((force)) __be32) 1730; +} + /* * check-name: conversions to bitwise types * check-command: sparse -Wbitwise $file |
