https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100394
Bug ID: 100394
Summary: wrong-code with EH and pure/const functions
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
Target Milestone: ---
// { dg-do run }
// { dg-options "-O2" }
int x, y;
int __attribute__((pure,noinline)) foo () { if (x) throw; return y; }
int __attribute__((noinline)) bar()
{
int a[2];
x = 1;
try {
int res = foo ();
a[0] = res;
} catch (...) {
return 0;
}
return 1;
}
int main()
{
if (bar ())
__builtin_abort ();
return 0;
}
aborts at all (non-)optimization levels. In an unpatched tree the call to
foo() is elided.
> g++-10 t.C
> ./a.out
terminate called without an active exception
Aborted (core dumped)