diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-17 21:52:42 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-18 01:19:06 +0100 |
| commit | 626c474204e8262467a316099b6074cab964237c (patch) | |
| tree | d9777c8a74671da0a2cc78bc6005f96188504603 | |
| parent | bbb3d7fcbe6d2bba07ee4664acbbab5e6e8c8b2a (diff) | |
| download | sparse-dev-626c474204e8262467a316099b6074cab964237c.tar.gz | |
casts should drop qualifiers
Casts should drop qualifiers but Sparse doesn't do this yet.
The fix seems pretty simple: after having evaluated the type of
the cast, if this type is a SYM_NODE and contains qualifiers,
make a copy of the type with the qualifiers removed and use
this copy as the type.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | evaluate.c | 13 | ||||
| -rw-r--r-- | validation/eval/unqual-cast.c | 14 |
2 files changed, 27 insertions, 0 deletions
@@ -61,6 +61,18 @@ static inline int valid_subexpr_type(struct expression *expr) && valid_expr_type(expr->right); } +static struct symbol *unqualify_type(struct symbol *ctype) +{ + if (ctype->type == SYM_NODE && (ctype->ctype.modifiers & MOD_QUALIFIER)) { + struct symbol *unqual = alloc_symbol(ctype->pos, 0); + + *unqual = *ctype; + unqual->ctype.modifiers &= ~MOD_QUALIFIER; + return unqual; + } + return ctype; +} + static struct symbol *evaluate_symbol_expression(struct expression *expr) { struct expression *addr; @@ -3025,6 +3037,7 @@ static struct symbol *evaluate_cast(struct expression *expr) return evaluate_compound_literal(expr, source); ctype = examine_symbol_type(expr->cast_type); + ctype = unqualify_type(ctype); expr->ctype = ctype; expr->cast_type = ctype; diff --git a/validation/eval/unqual-cast.c b/validation/eval/unqual-cast.c new file mode 100644 index 00000000..4106ec3b --- /dev/null +++ b/validation/eval/unqual-cast.c @@ -0,0 +1,14 @@ +#define cvr const volatile restrict + +_Static_assert([typeof((cvr int) 0)] == [int]); +_Static_assert([typeof((cvr int *) 0)] == [cvr int *]); + +static int *function(volatile int x) +{ + extern typeof((typeof(x)) (x)) y; + return &y; +} + +/* + * check-name: unqual-cast + */ |
