]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Preserve location in maybe_constant_value.
authorJason Merrill <jason@redhat.com>
Wed, 26 Feb 2020 18:03:23 +0000 (13:03 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 26 Feb 2020 19:09:02 +0000 (14:09 -0500)
If cxx_eval_outermost_constant_expr doesn't change the argument, we really
shouldn't unshare it when we try to fold it again.

gcc/cp/ChangeLog
2020-02-26  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.

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp1z/decomp48.C

index 6f62352a18e01015fb9ca4217f23d473e6a3b5aa..ca4bc4cc1b50bf7743bde8aeec7f2d0e9aea1ce6 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-26  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.
+
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/61414
index f0d4cb5e8e77fa29578a69a158e700e929e90be5..a7728285dc5103bdcec15947c6e7d2e3134e0301 100644 (file)
@@ -5582,7 +5582,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, decl);
   gcc_checking_assert (r == t
index 35413c79a9daf32906cd1bd34a008ac0037b7f8f..3c50b02a6c247165b45192a9b1912650ec795aeb 100644 (file)
@@ -18,7 +18,7 @@ f2 ()
 {
   S v {1, 2};
   auto& [s, t] = v;    // { dg-warning "structured bindings only available with" "" { target c++14_down } }
-  return s;            // { dg-warning "reference to local variable 'v' returned" }
+  return s;            // { dg-warning "reference to local variable 'v' returned" "" { target *-*-* } .-1 }
 }
 
 int &
@@ -33,7 +33,7 @@ f4 ()
 {
   int a[3] = {1, 2, 3};
   auto& [s, t, u] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
-  return s;            // { dg-warning "reference to local variable 'a' returned" }
+  return s;            // { dg-warning "reference to local variable 'a' returned" "" { target *-*-* } .-1 }
 }
 
 int &
@@ -78,7 +78,7 @@ f10 ()
 {
   S v {1, 2};
   auto& [s, t] = v;    // { dg-warning "structured bindings only available with" "" { target c++14_down } }
-  return &s;           // { dg-warning "address of local variable 'v' returned" }
+  return &s;           // { dg-warning "address of local variable 'v' returned" "" { target *-*-* } .-1 }
 }
 
 int *
@@ -93,7 +93,7 @@ f12 ()
 {
   int a[3] = {1, 2, 3};
   auto& [s, t, u] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
-  return &s;           // { dg-warning "address of local variable 'a' returned" }
+  return &s;           // { dg-warning "address of local variable 'a' returned" "" { target *-*-* } .-1 }
 }
 
 int *