diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2022-06-26 23:36:26 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2022-06-27 15:30:26 +0200 |
| commit | d33c81e7b6f32c4cb9a0d7ba20ee4eb875dfc44f (patch) | |
| tree | efb5f0e7712ffc8b7a225d5c21c61d7e274d7ffd /validation | |
| parent | 346ad756651e6c7c72f3012a4e1d57a49c327bc4 (diff) | |
| download | sparse-dev-bitwise-ones.tar.gz | |
bitwise: early expansion of simple constantsbitwise-ones
C has only positive constants: -1 is really an expression,
the unary '-' operator applied to the constant 1. '-1' as
a constant value only exists after the expansion of constant
expressions.
This is rather unfortunate since it inhibits easy testing
of such constants in the evaluation phase, like here for
restricted_value().
So, expand expressions like +CTE, -CTE or ~CTE before
calling restricted_value().
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/bitwise-cast.c | 13 | ||||
| -rw-r--r-- | validation/bitwise-is-signed.c | 1 |
2 files changed, 13 insertions, 1 deletions
diff --git a/validation/bitwise-cast.c b/validation/bitwise-cast.c index 1075a3e9..01af56c7 100644 --- a/validation/bitwise-cast.c +++ b/validation/bitwise-cast.c @@ -48,6 +48,19 @@ static __be32 bar1(void) return (__be32)0xffffffff; } +/* Implicit casts of minus one, legal */ +static __be32 foom(void) +{ + __be32 x = -1; + return x; +} + +/* Explicit cast of minus one, legal */ +static __be32 barm(void) +{ + return (__be32)-1; +} + /* * check-name: conversions to bitwise types * check-command: sparse -Wbitwise $file diff --git a/validation/bitwise-is-signed.c b/validation/bitwise-is-signed.c index dd9c1471..99d16bd2 100644 --- a/validation/bitwise-is-signed.c +++ b/validation/bitwise-is-signed.c @@ -15,7 +15,6 @@ int fou(void) { return !is_signed_type(u); } /* * check-name: bitwise-is-signed * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 |
