From c477e13bd7d3f369cde2fbb171d8aa9501759373 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 17 May 2005 08:45:49 +0200 Subject: [PATCH] re PR tree-optimization/21610 (ICE in make_decl_rtl) PR tree-optimization/21610 * c-typeck.c (decl_constant_value_for_broken_optimization): If not returning DECL, call unshare_expr. * gcc.c-torture/compile/20050516-1.c: New test. From-SVN: r99815 --- gcc/ChangeLog | 6 ++++++ gcc/c-typeck.c | 12 ++++++++++-- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.c-torture/compile/20050516-1.c | 12 ++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/20050516-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7bab2815525..99e010889bc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-05-17 Jakub Jelinek + + PR tree-optimization/21610 + * c-typeck.c (decl_constant_value_for_broken_optimization): If not + returning DECL, call unshare_expr. + 2005-05-17 Hans-Peter Nilsson * config/cris/cris.md: Unquote preparation and output statements. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 806a20ade96..b96328d89b9 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -1249,10 +1249,18 @@ decl_constant_value (tree decl) static tree decl_constant_value_for_broken_optimization (tree decl) { + tree ret; + if (pedantic || DECL_MODE (decl) == BLKmode) return decl; - else - return decl_constant_value (decl); + + ret = decl_constant_value (decl); + /* Avoid unwanted tree sharing between the initializer and current + function's body where the tree can be modified e.g. by the + gimplifier. */ + if (ret != decl && TREE_STATIC (decl)) + ret = unshare_expr (ret); + return ret; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2e99a3620b4..e6911746563 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2005-05-17 Jakub Jelinek + PR tree-optimization/21610 + * gcc.c-torture/compile/20050516-1.c: New test. + PR fortran/15080 * gfortran.fortran-torture/execute/forall_3.f90: Remove comment about the test failing. diff --git a/gcc/testsuite/gcc.c-torture/compile/20050516-1.c b/gcc/testsuite/gcc.c-torture/compile/20050516-1.c new file mode 100644 index 00000000000..2cdf6960807 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20050516-1.c @@ -0,0 +1,12 @@ +/* PR tree-optimization/21610 */ + +struct S { char s; }; +struct T { struct S t; }; + +struct S *const p = &((struct T * const) (0x4000))->t; + +void +foo (void) +{ + p->s = 0; +} -- 2.30.2