Add a DECL_EXPR for VLA pointer casts (PR 84305)
commit20ebaa3da2bf2e1a67425dcda6e984766e51fbaa
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 13 Feb 2018 10:28:54 +0000 (13 10:28 +0000)
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 13 Feb 2018 10:28:54 +0000 (13 10:28 +0000)
tree0654e3daa5437c9ec3e2a82ea51acd552ef3142f
parent660ca68fd78c3232ab01738a8620cec71ccb74fc
Add a DECL_EXPR for VLA pointer casts (PR 84305)

This PR was about a case in which we ended up with a MULT_EXPR
that was shared between an ungimplified VLA type and a pointer
calculation.  The SSA names used in the pointer calculation were
later freed, but they were still there in the VLA, and caused an
ICE when remapping the types during inlinling.

The fix is to add a DECL_EXPR that forces the VLA type sizes to be
gimplified too, but the tricky part is deciding where.  As the comment
in grokdeclarator says, we can't just add it to the statement list,
since the size might only be conditionally evaluated.  It might also
end up being evaluated out of sequence.

The patch gets around that by putting the DECL_EXPR in a BIND_EXPR
and adding the BIND_EXPR to the list of things that need to be
evaluated for the declarator.

2018-02-13  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/c/
PR c/84305
* c-decl.c (grokdeclarator): Create an anonymous TYPE_DECL
in PARM and TYPENAME contexts too, but attach it to a BIND_EXPR
and include the BIND_EXPR in the list of things that need to be
pre-evaluated.

gcc/testsuite/
PR c/84305
* gcc.c-torture/compile/pr84305.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257620 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr84305.c [new file with mode: 0644]