[gcc(refs/users/marxin/heads/marxin-gcc-benchmark-branch)] c++: Preserve location in maybe_constant_value.

Martin Liska marxin@gcc.gnu.org
Mon Mar 30 10:54:05 GMT 2020


https://gcc.gnu.org/g:173c8defa6e82f1bc003173b6ee1e4eb2830d1c2

commit 173c8defa6e82f1bc003173b6ee1e4eb2830d1c2
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 7 16:28:20 2020 -0500

    c++: Preserve location in maybe_constant_value.
    
    If cxx_eval_outermost_constant_expr doesn't change the argument, we really
    shouldn't unshare it when we try to fold it again.
    
            PR c++/92852
            * constexpr.c (maybe_constant_value): Don't unshare if the cached
            value is the same as the argument.

Diff:
---
 gcc/cp/ChangeLog   |  4 ++++
 gcc/cp/constexpr.c | 10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0894457b7a3..3e5e547fd87 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
 2020-02-08  Jason Merrill  <jason@redhat.com>
 
+	PR c++/92852
+	* constexpr.c (maybe_constant_value): Don't unshare if the cached
+	value is the same as the argument.
+
 	* typeck.c (maybe_warn_about_returning_address_of_local): Add
 	location parameter.
 
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index aa47ded52c0..1b35bc107e9 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -6651,7 +6651,15 @@ maybe_constant_value (tree t, tree decl, bool manifestly_const_eval)
   if (cv_cache == NULL)
     cv_cache = hash_map<tree, tree>::create_ggc (101);
   if (tree *cached = cv_cache->get (t))
-    return unshare_expr_without_location (*cached);
+    {
+      r = *cached;
+      if (r != t)
+	{
+	  r = unshare_expr_without_location (r);
+	  protected_set_expr_location (r, EXPR_LOCATION (t));
+	}
+      return r;
+    }
 
   r = cxx_eval_outermost_constant_expr (t, true, true, false, false, decl);
   gcc_checking_assert (r == t


More information about the Gcc-cvs mailing list