https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128138
Bug ID: 128138
Summary: [17 Regression] wrong code with -fno-math-errno:
pow(-Inf, 3.5) is folded to -Inf instead of +Inf
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: yuki.tanaka at defaultcase dot de
Target Milestone: ---
double a(void)
{
return __builtin_pow(-__builtin_inf(), 3.5);
}
int main(void)
{
if (a() != __builtin_inf())
__builtin_abort();
return 0;
}
Compiler Explorer (GCC 16.1 vs. 17):
https://godbolt.org/z/cj1c8sEqs
-O2 -fno-math-errno -lm
x86-64 GCC 17:
"a":
movsd xmm0, QWORD PTR .LC0[rip]
ret
"main":
push rax
call "abort"
.LC0:
.long 0
.long -1048576
3.5 is not an odd integer, so pow(-Inf, 3.5) is +Inf, but trunk folds it to
-Inf. GCC 16.1 does not fold it and calls pow, which returns +Inf. Without
-fno-math-errno trunk is fine.
With 1e300 instead of 3.5, trunk crashes in real_isoddinteger (internal
compiler error: Segmentation fault).
Possibly related to r17-5455-ga327f4cf837 ("fold-const: Constant fold
pow(-Inf,0.5) at compile-time").