From: Jakub Jelinek Date: Thu, 13 Feb 2020 20:00:09 +0000 (+0100) Subject: c: Fix ICE with cast to VLA [93576] X-Git-Tag: releases/gcc-9.3.0~134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7276dd4c7480dd952f0d4a9322ca04ca29f5126f;p=thirdparty%2Fgcc.git 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 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. --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index b17ed98a9aed..5ba4516e114a 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2020-02-13 Jakub Jelinek + + PR c/93576 + * c-decl.c (grokdeclarator): If this_size_varies, only push size into + *expr if it has side effects. + 2020-01-22 Joseph Myers Backport from mainline: diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index f77fb1739ca7..859a62412583 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -6368,11 +6368,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; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 114a1087936a..24e5e88d7632 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2020-02-13 Jakub Jelinek + PR c/93576 + * gcc.dg/pr93576.c: New test. + PR target/93696 * gcc.target/i386/pr93696-1.c: New test. * gcc.target/i386/pr93696-2.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr93576.c b/gcc/testsuite/gcc.dg/pr93576.c new file mode 100644 index 000000000000..13c34f3771ff --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr93576.c @@ -0,0 +1,10 @@ +/* PR c/93576 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +void +foo (void) +{ + int b[] = { 0 }; + (char (*)[(1, 7, 2)]) 0; +}