https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123826
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Roger Sayle <[email protected]>: https://gcc.gnu.org/g:a70bdd86984c0b6cd8520e30ec713e3101c5d45f commit r16-7264-ga70bdd86984c0b6cd8520e30ec713e3101c5d45f Author: Roger Sayle <[email protected]> Date: Tue Feb 3 17:06:25 2026 +0000 PR middle-end/123826: __builtin_pow vs. errno. This is my proposed solution to PR middle-end/123826. Initially I thought this would be a "one line change", adding a test for flag_errno_math to gimple_expand_builtin_pow. Unfortunately this revealed a second later problem, where pow (with constant arguments) was still getting evaluated at compile-time, even when the result is known to overflow. It's ancient history, but shortly after I added support for pow as a builtin, I contributed code to evaluate it at compile-time when the exponent is an integer constant. Since then we now use MPFR to evaluate libm math functions at compile-time. However the vestigial call to evaluate pow via real_powi still exists, and gets invoked after do_mpfr_arg2/mpfr_pow correctly determines that we shouldn't evaluate pow at compile-time. This patch reorganizes fold_const_pow paying attention to signaling NaNs (PR 61441) and flag_errno_math. Most importantly normal cases like pow(2.0,3.0) and pow(3.0,0.5) still get evaluated at compile-time. 2026-02-03 Roger Sayle <[email protected]> gcc/ChangeLog PR middle-end/123826 * tree-ssa-math-opts.cc (gimple_expand_builtin_pow): Add test for flag_errno_math. * fold-const-call.cc (fold_const_pow): Reorganize, eliminating call to real_powi, and letting do_mpfr_arg2 do all the heavy lifting. gcc/testsuite/ChangeLog PR middle-end/123826 * gcc.dg/errno-2.c: New test case. * gcc.dg/errno-3.c: Likewise.
