https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128642
Bug ID: 128642
Summary: [14/15/16/17 Regression] wrong code at -O2: errno set
by pow() in a constprop/isra clone is lost since
r12-4457
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: jeffchen006 at gmail dot com
Target Milestone: ---
#include <errno.h>
#include <math.h>
#include <stdio.h>
static double foo(double x) {
return pow(x, 3.0) + pow(x, 4.0);
}
int main(void) {
foo(1e300);
errno = 0;
foo(1e300);
printf("%d\n", errno);
}
$ gcc -O0 t.c -lm && ./a.out
34
$ gcc -O2 t.c -lm && ./a.out
0
Expected: 34. pow(1e300, 3.0) overflows and sets errno to ERANGE (34). -O2
prints 0.
Suspected cause: PTA determine_global_memory_access: the modref writes_errno
flag is not counted as a global memory write when the call has no arguments
(foo.constprop.isra). First bad 99b287b8ef5 (2021, modref).
Avoided by: -fno-ipa-modref, -fno-tree-pta, -fno-ipa-cp.
Known to fail: 12.5.0, 13.4.0, 14.3.0, 15.2.0, 16.2.0, 17.0.
Known to work: 11.4.0.
-O0 -fsanitize=undefined,address is clean.
gcc version 17.0.0 20261111 (experimental) (a2a11abfad3), x86_64-pc-linux-gnu
Configured with: --enable-languages=c,c++ --disable-multilib
--disable-bootstrap --enable-checking=release