From 4e6482d05be433b819e3ec9ab6f058d575f084ea Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 15 Mar 2019 10:23:11 +0100 Subject: [PATCH] re PR c++/89709 (ICE with constexpr and "-O") PR c++/89709 * tree.c (inchash::add_expr): Strip any location wrappers. * fold-const.c (operand_equal_p): Move stripping of location wrapper after hash verification. * g++.dg/cpp0x/constexpr-89709.C: New test. From-SVN: r269702 --- gcc/ChangeLog | 5 +++++ gcc/fold-const.c | 6 +++--- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp0x/constexpr-89709.C | 18 ++++++++++++++++++ gcc/tree.c | 2 ++ 5 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-89709.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5bd943b27fe..d7a4f3832d7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2019-03-15 Jakub Jelinek + PR c++/89709 + * tree.c (inchash::add_expr): Strip any location wrappers. + * fold-const.c (operand_equal_p): Move stripping of location wrapper + after hash verification. + PR debug/89704 * dwarf2out.c (add_const_value_attribute): Return false for MINUS, SIGN_EXTEND and ZERO_EXTEND. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index dbc96798e65..ec28b431eb8 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -2942,9 +2942,6 @@ combine_comparisons (location_t loc, int operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) { - STRIP_ANY_LOCATION_WRAPPER (arg0); - STRIP_ANY_LOCATION_WRAPPER (arg1); - /* When checking, verify at the outermost operand_equal_p call that if operand_equal_p returns non-zero then ARG0 and ARG1 has the same hash value. */ @@ -2967,6 +2964,9 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) return 0; } + STRIP_ANY_LOCATION_WRAPPER (arg0); + STRIP_ANY_LOCATION_WRAPPER (arg1); + /* If either is ERROR_MARK, they aren't equal. */ if (TREE_CODE (arg0) == ERROR_MARK || TREE_CODE (arg1) == ERROR_MARK || TREE_TYPE (arg0) == error_mark_node diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8780192ddd2..4e267d3f041 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-03-15 Jakub Jelinek + PR c++/89709 + * g++.dg/cpp0x/constexpr-89709.C: New test. + PR debug/89704 * gcc.dg/debug/pr89704.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-89709.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-89709.C new file mode 100644 index 00000000000..30b319abf3d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-89709.C @@ -0,0 +1,18 @@ +// PR c++/89709 +// { dg-do compile { target c++11 } } +// { dg-options "-O" } + +struct A { int i; }; +A a; + +constexpr int * +foo () +{ + return &a.i; +} + +bool +bar () +{ + return foo () == &a.i; +} diff --git a/gcc/tree.c b/gcc/tree.c index 02721cfc8a0..d061a0422ff 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -7743,6 +7743,8 @@ add_expr (const_tree t, inchash::hash &hstate, unsigned int flags) return; } + STRIP_ANY_LOCATION_WRAPPER (t); + if (!(flags & OEP_ADDRESS_OF)) STRIP_NOPS (t); -- 2.30.2