diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-03-30 17:58:18 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-03-31 03:23:38 +0200 |
| commit | 4d963a28d371ce75f65a70aa29f14cec5f08d8ff (patch) | |
| tree | 35a59db5c1321503fa368973d16f6a093c527b0e /validation | |
| parent | ad10d37861692e1099115385b91dd2fc1716a20a (diff) | |
| download | sparse-dev-4d963a28d371ce75f65a70aa29f14cec5f08d8ff.tar.gz | |
constexpr: flag __builtin_bswap() as constexpr
__builtin_bswap() is used in the kernel in situations like:
switch (protocol) {
case htons(ETH_P_IP):
break;
}
which requires that the constant is effectively an integer constant,
not an integer constant expression.
Since this builtin, like the others, are not defined by the standard,
let's relax the diagnostic and flag them as integer constant if its
argument is also a constant (simple integer or an expression).
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/constexpr-pure-builtin.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/validation/constexpr-pure-builtin.c b/validation/constexpr-pure-builtin.c new file mode 100644 index 00000000..f4cd67ed --- /dev/null +++ b/validation/constexpr-pure-builtin.c @@ -0,0 +1,23 @@ +// requires constant integer expressions +static int bar[] = { + [__builtin_bswap16(0x1234)] = 0, // OK + [__builtin_bswap32(0x1234)] = 0, // OK + [__builtin_bswap64(0x1234)] = 0, // OK +}; + +// requires constant integers +static int foo(unsigned long long a) +{ + switch (a) { + case __builtin_bswap16(1 << 8): + case __builtin_bswap32(2L << 24): + case __builtin_bswap64(3LL << 56): + return 0; + default: + return 1; + } +} + +/* + * check-name: constness of pure/const builtins + */ |
