Commit eddd715c by Jason Merrill Committed by Jakub Jelinek

re PR c++/83993 (ICE: constant not recomputed when ADDR_EXPR changed)

	PR c++/83993
	* constexpr.c (cxx_eval_outermost_constant_expr): Build NOP_EXPR
	around non-constant ADDR_EXPRs rather than clearing TREE_CONSTANT
	on ADDR_EXPR.

	* g++.dg/init/pr83993-2.C: New test.

From-SVN: r257265
parent 08b3748c
2018-01-31 Jason Merrill <jason@redhat.com>
Jakub Jelinek <jakub@redhat.com>
PR c++/83993
* constexpr.c (cxx_eval_outermost_constant_expr): Build NOP_EXPR
around non-constant ADDR_EXPRs rather than clearing TREE_CONSTANT
on ADDR_EXPR.
2018-01-31 Jakub Jelinek <jakub@redhat.com>
PR c++/83993
......
......@@ -4840,8 +4840,12 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
return error_mark_node;
else if (non_constant_p && TREE_CONSTANT (r))
{
/* This isn't actually constant, so unset TREE_CONSTANT. */
if (EXPR_P (r))
/* This isn't actually constant, so unset TREE_CONSTANT.
Don't clear TREE_CONSTANT on ADDR_EXPR, as the middle-end requires
it to be set if it is invariant address, even when it is not
a valid C++ constant expression. Wrap it with a NOP_EXPR
instead. */
if (EXPR_P (r) && TREE_CODE (r) != ADDR_EXPR)
r = copy_node (r);
else if (TREE_CODE (r) == CONSTRUCTOR)
r = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (r), r);
......
2018-01-31 Jakub Jelinek <jakub@redhat.com>
PR c++/83993
* g++.dg/init/pr83993-2.C: New test.
PR c++/83993
* g++.dg/init/pr83993-1.C: New test.
* g++.dg/cpp0x/pr83993.C: New test.
......
// PR c++/83993
// { dg-do compile }
// { dg-options "-w" }
int a[5];
extern int b[];
int *const c = &a[6];
int *const d = &b[1];
int
foo ()
{
return c[-4] + d[-1];
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment