aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-02-13 21:00:09 +0100
committerJakub Jelinek <jakub@redhat.com>2020-02-13 21:00:09 +0100
commitbacdd5e978dad84e9c547b0d5c7fed14b8d75157 (patch)
tree32caf6b07a31366dba4ec9afff384714d0719f29 /gcc/c
parent0a649b83751ce593e20bc9bda92ae52e64fd5cda (diff)
downloadgcc-bacdd5e978dad84e9c547b0d5c7fed14b8d75157.zip
gcc-bacdd5e978dad84e9c547b0d5c7fed14b8d75157.tar.gz
gcc-bacdd5e978dad84e9c547b0d5c7fed14b8d75157.tar.bz2
c: Fix ICE with cast to VLA [93576]
The following testcase ICEs, because the PR84305 changes try to evaluate the size earlier. If size has side-effects, that is desirable, and the side-effects will actually be wrapped in a SAVE_EXPR. The problem on this testcase is that there are no side-effects, and c_fully_fold doesn't fold those COMPOUND_EXPRs to constant, and while before gimplification we unshare trees found in the expressions, the unsharing doesn't involve TYPE_SIZE etc. of used types. Gimplification is destructive though, so when we gimplify the two nested COMPOUND_EXPRs and then try to gimplify it the second time for the TYPE_SIZEs, we ICE. Now, we could use unshare_expr in what we push to *expr, SAVE_EXPRs and their operands in there aren't unshared, but I really don't see a point of evaluating expressions that don't have side-effects before, so instead this just pushes there expressions that do have side-effects. 2020-02-13 Jakub Jelinek <jakub@redhat.com> PR c/93576 * c-decl.c (grokdeclarator): If this_size_varies, only push size into *expr if it has side effects. * gcc.dg/pr93576.c: New test.
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-decl.c13
2 files changed, 14 insertions, 5 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 995f315..e88337b 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-13 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/93576
+ * c-decl.c (grokdeclarator): If this_size_varies, only push size into
+ *expr if it has side effects.
+
2020-01-30 Jeff Law <law@redhat.com>
PR c/88660
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 8281af7..1aa410d 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -6512,11 +6512,14 @@ grokdeclarator (const struct c_declarator *declarator,
}
if (this_size_varies)
{
- if (*expr)
- *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
- *expr, size);
- else
- *expr = size;
+ if (TREE_SIDE_EFFECTS (size))
+ {
+ if (*expr)
+ *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
+ *expr, size);
+ else
+ *expr = size;
+ }
*expr_const_operands &= size_maybe_const;
}
}