aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2020-02-07 16:28:20 -0500
committerJason Merrill <jason@redhat.com>2020-02-08 11:14:58 -0500
commit173c8defa6e82f1bc003173b6ee1e4eb2830d1c2 (patch)
tree8224edef4128d22964c207c4dcae64f6f37cf46e /gcc/cp/constexpr.c
parent61f5369f7ecf1eff9cd7a7016324d60eec338806 (diff)
downloadgcc-173c8defa6e82f1bc003173b6ee1e4eb2830d1c2.zip
gcc-173c8defa6e82f1bc003173b6ee1e4eb2830d1c2.tar.gz
gcc-173c8defa6e82f1bc003173b6ee1e4eb2830d1c2.tar.bz2
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.
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r--gcc/cp/constexpr.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index aa47ded..1b35bc1 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