diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-19 09:18:01 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-19 09:18:01 +0100 |
commit | 349ac6d1489f9b98f67b7f9b94625a60249409e0 (patch) | |
tree | e0bf0760205d82229807b5389e192db72e4de8eb | |
parent | 626c474204e8262467a316099b6074cab964237c (diff) | |
parent | fd1491b217595b1da31a7c72303cbffff0aba56a (diff) | |
download | sparse-349ac6d1489f9b98f67b7f9b94625a60249409e0.tar.gz |
Merge branch 'unqual'
* unqual: comma expressions should drop qualifiers
* unqual: statement expressions should drop qualifiers
-rw-r--r-- | evaluate.c | 6 | ||||
-rw-r--r-- | validation/eval/unqual-comma.c | 12 | ||||
-rw-r--r-- | validation/eval/unqual-postop.c | 23 | ||||
-rw-r--r-- | validation/eval/unqual-stmt-expr.c | 12 | ||||
-rw-r--r-- | validation/eval/unqual02.c | 26 |
5 files changed, 77 insertions, 2 deletions
@@ -63,6 +63,8 @@ static inline int valid_subexpr_type(struct expression *expr) static struct symbol *unqualify_type(struct symbol *ctype) { + if (!ctype) + return ctype; if (ctype->type == SYM_NODE && (ctype->ctype.modifiers & MOD_QUALIFIER)) { struct symbol *unqual = alloc_symbol(ctype->pos, 0); @@ -1026,7 +1028,7 @@ static struct symbol *evaluate_binop(struct expression *expr) static struct symbol *evaluate_comma(struct expression *expr) { - expr->ctype = degenerate(expr->right); + expr->ctype = unqualify_type(degenerate(expr->right)); if (expr->ctype == &null_ctype) expr->ctype = &ptr_ctype; expr->flags &= expr->left->flags & expr->right->flags; @@ -3948,7 +3950,7 @@ struct symbol *evaluate_statement(struct statement *stmt) return NULL; if (stmt->expression->ctype == &null_ctype) stmt->expression = cast_to(stmt->expression, &ptr_ctype); - return degenerate(stmt->expression); + return unqualify_type(degenerate(stmt->expression)); case STMT_COMPOUND: { struct statement *s; diff --git a/validation/eval/unqual-comma.c b/validation/eval/unqual-comma.c new file mode 100644 index 00000000..11546d22 --- /dev/null +++ b/validation/eval/unqual-comma.c @@ -0,0 +1,12 @@ +#define __unqual_typeof(x) typeof(((void)0, (x))) + +int *foo(volatile int x); +int *foo(volatile int x) +{ + extern __unqual_typeof(x) y; + return &y; +} + +/* + * check-name: unqual-comma + */ diff --git a/validation/eval/unqual-postop.c b/validation/eval/unqual-postop.c new file mode 100644 index 00000000..fb3082dc --- /dev/null +++ b/validation/eval/unqual-postop.c @@ -0,0 +1,23 @@ +static void test_volatile(void) +{ + volatile int x = 0; + int *pp; + + typeof(++x) v1; pp = &v1; // KO + typeof(x++) v2; pp = &v2; // KO +} + +/* + * check-name: unqual-postop + * check-command: sparse -Wno-declaration-after-statement $file + * check-known-to-fail + * + * check-error-start +eval/unqual-postop.c:6:40: warning: incorrect type in assignment (different modifiers) +eval/unqual-postop.c:6:40: expected int *pp +eval/unqual-postop.c:6:40: got int volatile * +eval/unqual-postop.c:7:40: warning: incorrect type in assignment (different modifiers) +eval/unqual-postop.c:7:40: expected int *pp +eval/unqual-postop.c:7:40: got int volatile * + * check-error-end + */ diff --git a/validation/eval/unqual-stmt-expr.c b/validation/eval/unqual-stmt-expr.c new file mode 100644 index 00000000..280c2fe8 --- /dev/null +++ b/validation/eval/unqual-stmt-expr.c @@ -0,0 +1,12 @@ +#define __unqual_typeof(x) typeof(({ x; })) + +int *foo(volatile int x); +int *foo(volatile int x) +{ + extern __unqual_typeof(x) y; + return &y; +} + +/* + * check-name: unqual-stmt-expr + */ diff --git a/validation/eval/unqual02.c b/validation/eval/unqual02.c new file mode 100644 index 00000000..f136cbd5 --- /dev/null +++ b/validation/eval/unqual02.c @@ -0,0 +1,26 @@ +static void test_const(volatile int x) +{ + const int x = 0; + typeof(1?x:x) i3; i3 = 0; // should be OK + typeof(+x) i4; i4 = 0; // should be OK + typeof(-x) i5; i5 = 0; // should be OK + typeof(!x) i6; i6 = 0; // should be OK + typeof(x+x) i7; i7 = 0; // should be OK +} + +static void test_volatile(void) +{ + volatile int x = 0; + int *pp; + + typeof(1?x:x) i3; pp = &i3; // should be OK + typeof(+x) i4; pp = &i4; // should be OK + typeof(-x) i5; pp = &i5; // should be OK + typeof(!x) i6; pp = &i6; // should be OK + typeof(x+x) i7; pp = &i7; // should be OK +} + +/* + * check-name: unqual02 + * check-command: sparse -Wno-declaration-after-statement $file + */ |