[Bug c++/109745] [13 Regression] Incorrect code generated with -O1 when having a constexpr object modifying a mutable member

2023-05-12 Thread carlosgalvezp at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109745

--- Comment #8 from Carlos Galvez  ---
Thanks a lot for the quick fix!

[Bug c++/109745] [13 Regression] Incorrect code generated with -O1 when having a constexpr object modifying a mutable member

2023-05-12 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109745

Patrick Palka  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #7 from Patrick Palka  ---
Fixed for GCC 13.2, thanks for the bug report and the nice reproducer!

[Bug c++/109745] [13 Regression] Incorrect code generated with -O1 when having a constexpr object modifying a mutable member

2023-05-12 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109745

--- Comment #6 from CVS Commits  ---
The releases/gcc-13 branch has been updated by Patrick Palka
:

https://gcc.gnu.org/g:7f962e7003a51cc752ed79cbc7fe55ca66981c7a

commit r13-7326-g7f962e7003a51cc752ed79cbc7fe55ca66981c7a
Author: Patrick Palka 
Date:   Thu May 11 16:31:33 2023 -0400

c++: 'mutable' subobject of constexpr variable [PR109745]

r13-2701-g7107ea6fb933f1 made us correctly accept during constexpr
evaluation 'mutable' member accesses of objects constructed during
that evaluation, while continuing to reject such accesses for constexpr
objects constructed outside of that evaluation, by considering the
CONSTRUCTOR_MUTABLE_POISON flag during cxx_eval_component_reference.

However, this flag is set only for the outermost CONSTRUCTOR of a
constexpr variable initializer, so if we're accessing a 'mutable' member
of a nested CONSTRUCTOR, the flag won't be set and we won't reject the
access.  This can lead to us accepting invalid code, as in the first
testcase, or even wrong code generation due to our speculative constexpr
evaluation, as in the second and third testcase.

This patch fixes this by setting CONSTRUCTOR_MUTABLE_POISON recursively
rather than only on the outermost CONSTRUCTOR.

PR c++/109745

gcc/cp/ChangeLog:

* typeck2.cc (poison_mutable_constructors): Define.
(store_init_value): Use it instead of setting
CONSTRUCTOR_MUTABLE_POISON directly.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-mutable4.C: New test.
* g++.dg/cpp0x/constexpr-mutable5.C: New test.
* g++.dg/cpp1y/constexpr-mutable2.C: New test.

(cherry picked from commit 02777f20be4f40160f1b4ed34fa59ba75245b5b7)

[Bug c++/109745] [13 Regression] Incorrect code generated with -O1 when having a constexpr object modifying a mutable member

2023-05-11 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109745

Patrick Palka  changed:

   What|Removed |Added

Summary|[13/14 Regression]  |[13 Regression] Incorrect
   |Incorrect code generated|code generated with -O1
   |with -O1 when having a  |when having a constexpr
   |constexpr object modifying  |object modifying a mutable
   |a mutable member|member
   Keywords||accepts-invalid

--- Comment #5 from Patrick Palka  ---
Fixed on trunk so far.