aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2024-08-29 15:13:03 -0400
committerMarek Polacek <polacek@redhat.com>2024-09-10 11:48:15 -0400
commit2801a49d1144bce5568b527d1972952ad3420f66 (patch)
tree379a3bbbfa6382e871b535b8ed5f9a270d5b6a04 /gcc
parente783a4a683762487cb003ae48235f3d44875de1b (diff)
downloadgcc-2801a49d1144bce5568b527d1972952ad3420f66.zip
gcc-2801a49d1144bce5568b527d1972952ad3420f66.tar.gz
gcc-2801a49d1144bce5568b527d1972952ad3420f66.tar.bz2
c++: mutable temps in rodata [PR116369]
Here we wrongly mark the reference temporary for g TREE_READONLY, so it's put in .rodata and so we can't modify its subobject even when the subobject is marked mutable. This is so since r9-869. r14-1785 fixed a similar problem, but not in set_up_extended_ref_temp. PR c++/116369 gcc/cp/ChangeLog: * call.cc (set_up_extended_ref_temp): Don't mark a temporary TREE_READONLY if its type is TYPE_HAS_MUTABLE_P. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/initlist-opt7.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/call.cc4
-rw-r--r--gcc/testsuite/g++.dg/tree-ssa/initlist-opt7.C13
2 files changed, 16 insertions, 1 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index fa7f05d..d30f36d 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -13964,7 +13964,9 @@ set_up_extended_ref_temp (tree decl, tree expr, vec<tree, va_gc> **cleanups,
init = cp_fully_fold (init);
if (TREE_CONSTANT (init))
{
- if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
+ if (literal_type_p (type)
+ && CP_TYPE_CONST_NON_VOLATILE_P (type)
+ && !TYPE_HAS_MUTABLE_P (type))
{
/* 5.19 says that a constant expression can include an
lvalue-rvalue conversion applied to "a glvalue of literal type
diff --git a/gcc/testsuite/g++.dg/tree-ssa/initlist-opt7.C b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt7.C
new file mode 100644
index 0000000..2420db5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt7.C
@@ -0,0 +1,13 @@
+// PR c++/116369
+// { dg-do run { target c++11 } }
+
+struct f{
+ mutable int t;
+};
+
+const f &g = {1};
+
+int main()
+{
+ g.t++;
+}