https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93491
Bug ID: 93491
Summary: Wrong optimization: const-function moved over control
flow leading to crashes
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: ch3root at openwall dot com
Target Milestone: ---
In the following example, the call to the function `g` is guarded by the `f(0)`
call and is never evaluated but the optimizer moved it over the guard while
hoisting it from the loop:
----------------------------------------------------------------------
#include <stdlib.h>
__attribute__((noipa))
void f(int i)
{
exit(i);
}
__attribute__((const,noipa))
int g(int i)
{
return 1 / i;
}
int main()
{
while (1) {
f(0);
f(g(0));
}
}
----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out
$ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out
Floating point exception
----------------------------------------------------------------------
gcc x86-64 version: gcc (GCC) 10.0.1 20200129 (experimental)
----------------------------------------------------------------------