]> gcc.gnu.org Git - gcc.git/commit
c++: Relax too strict assert in stabilize_expr [PR111160]
authorSimon Martin <simon@nasilyan.com>
Tue, 11 Jun 2024 09:44:28 +0000 (11:44 +0200)
committerSimon Martin <simon@nasilyan.com>
Tue, 2 Jul 2024 10:48:34 +0000 (12:48 +0200)
commit49058fecbfd09a3354064e7d695b4a1056ce7547
treed68f945533e46080e05628139c5d8f1fe2ca34c4
parente9c0cbf0155cf4df57afb0ac8e18a7a1fc746e4a
c++: Relax too strict assert in stabilize_expr [PR111160]

The case in the ticket is an ICE on invalid due to an assert in stabilize_expr,
but the underlying issue can actually trigger on this *valid* code:

=== cut here ===
struct TheClass {
  TheClass() {}
  TheClass(volatile TheClass& t) {}
  TheClass operator=(volatile TheClass& t) volatile { return t; }
};
void the_func() {
  volatile TheClass x, y, z;
  (false ? x : y) = z;
}
=== cut here ===

The problem is that stabilize_expr asserts that it returns an expression
without TREE_SIDE_EFFECTS, which can't be if the involved type is volatile.

This patch relaxes the assert to accept having TREE_THIS_VOLATILE on the
returned expression.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/111160

gcc/cp/ChangeLog:

* tree.cc (stabilize_expr): Stabilized expressions can have
TREE_SIDE_EFFECTS if they're volatile.

gcc/testsuite/ChangeLog:

* g++.dg/overload/error8.C: New test.
* g++.dg/overload/volatile2.C: New test.
gcc/cp/tree.cc
gcc/testsuite/g++.dg/overload/error8.C [new file with mode: 0644]
gcc/testsuite/g++.dg/overload/volatile2.C [new file with mode: 0644]
This page took 0.054716 seconds and 5 git commands to generate.