public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: unpropagated CONSTRUCTOR_MUTABLE_POISON [PR110463]
@ 2023-06-29 15:22 Patrick Palka
  2023-06-29 15:36 ` Marek Polacek
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2023-06-29 15:22 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/13?

-- >8 --

cp_fold is neglecting to propagate CONSTRUCTOR_MUTABLE_POISON when folding
a CONSTRUCTOR initializer, which for the below testcase causes us to fail
to reject a mutable member access of a constexpr variable during constexpr
evaluation.

	PR c++/110463

gcc/cp/ChangeLog:

	* cp-gimplify.cc (cp_fold) <case CONSTRUCTOR>: Propagate
	CONSTRUCTOR_MUTABLE_POISON.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/constexpr-mutable6.C: New test.
---
 gcc/cp/cp-gimplify.cc                          |  2 ++
 .../g++.dg/cpp0x/constexpr-mutable6.C          | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C

diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 853b1e44236..f5734197774 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -3079,6 +3079,8 @@ cp_fold (tree x, fold_flags_t flags)
 	    x = build_constructor (TREE_TYPE (x), nelts);
 	    CONSTRUCTOR_PLACEHOLDER_BOUNDARY (x)
 	      = CONSTRUCTOR_PLACEHOLDER_BOUNDARY (org_x);
+	    CONSTRUCTOR_MUTABLE_POISON (x)
+	      = CONSTRUCTOR_MUTABLE_POISON (org_x);
 	  }
 	if (VECTOR_TYPE_P (TREE_TYPE (x)))
 	  x = fold (x);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C
new file mode 100644
index 00000000000..2c946e388ab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C
@@ -0,0 +1,18 @@
+// PR c++/110463
+// { dg-do compile { target c++11 } }
+
+struct U {
+  mutable int x = 1;
+};
+
+struct V {
+  mutable int y = 1+1;
+};
+
+int main() {
+  constexpr U u = {};
+  constexpr int x = u.x; // { dg-error "mutable" }
+
+  constexpr V v = {};
+  constexpr int y = v.y; // { dg-error "mutable" }
+}
-- 
2.41.0.199.ga9e066fa63


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] c++: unpropagated CONSTRUCTOR_MUTABLE_POISON [PR110463]
  2023-06-29 15:22 [PATCH] c++: unpropagated CONSTRUCTOR_MUTABLE_POISON [PR110463] Patrick Palka
@ 2023-06-29 15:36 ` Marek Polacek
  2023-06-29 17:44   ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Polacek @ 2023-06-29 15:36 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, jason

On Thu, Jun 29, 2023 at 11:22:55AM -0400, Patrick Palka via Gcc-patches wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/13?
> 
> -- >8 --
> 
> cp_fold is neglecting to propagate CONSTRUCTOR_MUTABLE_POISON when folding
> a CONSTRUCTOR initializer, which for the below testcase causes us to fail
> to reject a mutable member access of a constexpr variable during constexpr
> evaluation.

LGTM.
 
> 	PR c++/110463
> 
> gcc/cp/ChangeLog:
> 
> 	* cp-gimplify.cc (cp_fold) <case CONSTRUCTOR>: Propagate
> 	CONSTRUCTOR_MUTABLE_POISON.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp0x/constexpr-mutable6.C: New test.
> ---
>  gcc/cp/cp-gimplify.cc                          |  2 ++
>  .../g++.dg/cpp0x/constexpr-mutable6.C          | 18 ++++++++++++++++++
>  2 files changed, 20 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C
> 
> diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
> index 853b1e44236..f5734197774 100644
> --- a/gcc/cp/cp-gimplify.cc
> +++ b/gcc/cp/cp-gimplify.cc
> @@ -3079,6 +3079,8 @@ cp_fold (tree x, fold_flags_t flags)
>  	    x = build_constructor (TREE_TYPE (x), nelts);
>  	    CONSTRUCTOR_PLACEHOLDER_BOUNDARY (x)
>  	      = CONSTRUCTOR_PLACEHOLDER_BOUNDARY (org_x);
> +	    CONSTRUCTOR_MUTABLE_POISON (x)
> +	      = CONSTRUCTOR_MUTABLE_POISON (org_x);
>  	  }
>  	if (VECTOR_TYPE_P (TREE_TYPE (x)))
>  	  x = fold (x);
> diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C
> new file mode 100644
> index 00000000000..2c946e388ab
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C
> @@ -0,0 +1,18 @@
> +// PR c++/110463
> +// { dg-do compile { target c++11 } }
> +
> +struct U {
> +  mutable int x = 1;
> +};
> +
> +struct V {
> +  mutable int y = 1+1;
> +};
> +
> +int main() {
> +  constexpr U u = {};
> +  constexpr int x = u.x; // { dg-error "mutable" }
> +
> +  constexpr V v = {};
> +  constexpr int y = v.y; // { dg-error "mutable" }
> +}
> -- 
> 2.41.0.199.ga9e066fa63
> 

Marek


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] c++: unpropagated CONSTRUCTOR_MUTABLE_POISON [PR110463]
  2023-06-29 15:36 ` Marek Polacek
@ 2023-06-29 17:44   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2023-06-29 17:44 UTC (permalink / raw)
  To: Marek Polacek, Patrick Palka; +Cc: gcc-patches

On 6/29/23 11:36, Marek Polacek wrote:
> On Thu, Jun 29, 2023 at 11:22:55AM -0400, Patrick Palka via Gcc-patches wrote:
>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
>> trunk/13?
>>
>> -- >8 --
>>
>> cp_fold is neglecting to propagate CONSTRUCTOR_MUTABLE_POISON when folding
>> a CONSTRUCTOR initializer, which for the below testcase causes us to fail
>> to reject a mutable member access of a constexpr variable during constexpr
>> evaluation.
> 
> LGTM.

Agreed, OK.

>> 	PR c++/110463
>>
>> gcc/cp/ChangeLog:
>>
>> 	* cp-gimplify.cc (cp_fold) <case CONSTRUCTOR>: Propagate
>> 	CONSTRUCTOR_MUTABLE_POISON.
>>
>> gcc/testsuite/ChangeLog:
>>
>> 	* g++.dg/cpp0x/constexpr-mutable6.C: New test.
>> ---
>>   gcc/cp/cp-gimplify.cc                          |  2 ++
>>   .../g++.dg/cpp0x/constexpr-mutable6.C          | 18 ++++++++++++++++++
>>   2 files changed, 20 insertions(+)
>>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C
>>
>> diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
>> index 853b1e44236..f5734197774 100644
>> --- a/gcc/cp/cp-gimplify.cc
>> +++ b/gcc/cp/cp-gimplify.cc
>> @@ -3079,6 +3079,8 @@ cp_fold (tree x, fold_flags_t flags)
>>   	    x = build_constructor (TREE_TYPE (x), nelts);
>>   	    CONSTRUCTOR_PLACEHOLDER_BOUNDARY (x)
>>   	      = CONSTRUCTOR_PLACEHOLDER_BOUNDARY (org_x);
>> +	    CONSTRUCTOR_MUTABLE_POISON (x)
>> +	      = CONSTRUCTOR_MUTABLE_POISON (org_x);
>>   	  }
>>   	if (VECTOR_TYPE_P (TREE_TYPE (x)))
>>   	  x = fold (x);
>> diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C
>> new file mode 100644
>> index 00000000000..2c946e388ab
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C
>> @@ -0,0 +1,18 @@
>> +// PR c++/110463
>> +// { dg-do compile { target c++11 } }
>> +
>> +struct U {
>> +  mutable int x = 1;
>> +};
>> +
>> +struct V {
>> +  mutable int y = 1+1;
>> +};
>> +
>> +int main() {
>> +  constexpr U u = {};
>> +  constexpr int x = u.x; // { dg-error "mutable" }
>> +
>> +  constexpr V v = {};
>> +  constexpr int y = v.y; // { dg-error "mutable" }
>> +}
>> -- 
>> 2.41.0.199.ga9e066fa63
>>
> 
> Marek
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-29 17:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-29 15:22 [PATCH] c++: unpropagated CONSTRUCTOR_MUTABLE_POISON [PR110463] Patrick Palka
2023-06-29 15:36 ` Marek Polacek
2023-06-29 17:44   ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).