* [Bug c/103031] [12 Regression] Missing static initializer folding with -frounding-math
2021-11-01 20:44 [Bug middle-end/103031] New: [12 Regression] Missing static initializer folding with -frounding-math jsm28 at gcc dot gnu.org
2021-11-01 20:47 ` [Bug middle-end/103031] " pinskia at gcc dot gnu.org
@ 2021-11-02 7:43 ` rguenth at gcc dot gnu.org
2021-11-03 15:00 ` cvs-commit at gcc dot gnu.org
2021-11-03 15:01 ` jsm28 at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-02 7:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103031
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-11-02
Priority|P3 |P1
Status|UNCONFIRMED |NEW
Target Milestone|--- |12.0
Ever confirmed|0 |1
Component|middle-end |c
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
I suppose the frontend is calling fold_convert directly rather than
fold_build1_initializer (FLOAT_EXPR, ...).
The frontend ends up building this via
#0 0x0000000000d53d87 in convert_to_real_1 (
type=<real_type 0x7ffff6566348 double>, expr=<integer_cst 0x7ffff6544540>,
fold_p=true) at /home/rguenther/src/gcc3/gcc/convert.c:319
#1 0x0000000000d53f0a in convert_to_real (
type=<real_type 0x7ffff6566348 double>, expr=<integer_cst 0x7ffff6544540>)
at /home/rguenther/src/gcc3/gcc/convert.c:347
#2 0x0000000000b3cb90 in convert (type=<real_type 0x7ffff6566348 double>,
expr=<integer_cst 0x7ffff6544540>)
at /home/rguenther/src/gcc3/gcc/c/c-convert.c:138
#3 0x0000000000b9f602 in convert_and_check (loc=242464,
type=<real_type 0x7ffff6566348 double>, expr=<integer_cst 0x7ffff6544540>)
at /home/rguenther/src/gcc3/gcc/c-family/c-common.c:1767
#4 0x0000000000b1055e in convert_for_assignment (location=242464, expr_loc=0,
type=<real_type 0x7ffff6566348 double>, rhs=<integer_cst 0x7ffff6544540>,
origtype=<tree 0x0>, errtype=ic_init, null_pointer_constant=false,
fundecl=<tree 0x0>, function=<tree 0x0>, parmnum=0, warnopt=0)
at /home/rguenther/src/gcc3/gcc/c/c-typeck.c:7032
#5 0x0000000000b18c6e in digest_init (init_loc=242464,
type=<real_type 0x7ffff6566348 double>, init=<integer_cst 0x7ffff6544540>,
origtype=<tree 0x0>, null_pointer_constant=false, strict_string=true,
require_constant=1) at /home/rguenther/src/gcc3/gcc/c/c-typeck.c:8217
#6 0x0000000000b16df8 in store_init_value (init_loc=242464,
decl=<var_decl 0x7ffff7ff5c60 x>, init=<integer_cst 0x7ffff6544540>,
--Type <RET> for more, q to quit, c to continue without paging--
origtype=<tree 0x0>) at /home/rguenther/src/gcc3/gcc/c/c-typeck.c:7762
#7 0x0000000000ace0e7 in finish_decl (decl=<var_decl 0x7ffff7ff5c60 x>,
init_loc=242464, init=<integer_cst 0x7ffff6544540>, origtype=<tree 0x0>,
asmspec_tree=<tree 0x0>) at /home/rguenther/src/gcc3/gcc/c/c-decl.c:5363
maybe convert_for_assignment needs to do something similar as
START/END_FOLD_INIT around the convert_and_check or convert_for_assignment
is not the correct thing to call here. It's also odd that convert_to_real
says fold_p == true to convert_to_real_1 but that function doesn't actually
fold anything (maybe that's just all dead code). I'm quite sure that
initializer_constant_valid_p isn't the one that has to accept a FLOAT_EXPR
here.
C frontend maintainers need to sort this out.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/103031] [12 Regression] Missing static initializer folding with -frounding-math
2021-11-01 20:44 [Bug middle-end/103031] New: [12 Regression] Missing static initializer folding with -frounding-math jsm28 at gcc dot gnu.org
2021-11-01 20:47 ` [Bug middle-end/103031] " pinskia at gcc dot gnu.org
2021-11-02 7:43 ` [Bug c/103031] " rguenth at gcc dot gnu.org
@ 2021-11-03 15:00 ` cvs-commit at gcc dot gnu.org
2021-11-03 15:01 ` jsm28 at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-03 15:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103031
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Joseph Myers <jsm28@gcc.gnu.org>:
https://gcc.gnu.org/g:600dcd74b8e614c996b492d97878660faf484094
commit r12-4872-g600dcd74b8e614c996b492d97878660faf484094
Author: Joseph Myers <joseph@codesourcery.com>
Date: Wed Nov 3 14:58:25 2021 +0000
c: Fold implicit integer-to-floating conversions in static initializers
with -frounding-math [PR103031]
Recent fixes to avoid inappropriate folding of some conversions to
floating-point types with -frounding-math also prevented such folding
in C static initializers, when folding (in the default rounding mode,
exceptions discarded) is required for correctness.
Folding for static initializers is handled via functions in
fold-const.c calling START_FOLD_INIT and END_FOLD_INIT to adjust flags
such as flag_rounding_math that should not apply in static initializer
context, but no such function was being called for the folding of
these implicit conversions to the type of the object being
initialized, only for explicit conversions as part of the initializer.
Arrange for relevant folding (a fold call in convert, in particular)
to use this special initializer handling (via a new fold_init
function, in particular).
Because convert is used by language-independent code but defined in
each front end, this isn't as simple as just adding a new default
argument to it. Instead, I added a new convert_init function; that
then gets called by c-family code, and C and C++ need convert_init
implementations (the C++ one does nothing different from convert and
will never actually get called because the new convert_and_check
argument will never be true from C++), but other languages don't.
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
gcc/
PR c/103031
* fold-const.c (fold_init): New function.
* fold-const.h (fold_init): New prototype.
gcc/c-family/
PR c/103031
* c-common.c (convert_and_check): Add argument init_const. Call
convert_init if init_const.
* c-common.h (convert_and_check): Update prototype.
(convert_init): New prototype.
gcc/c/
PR c/103031
* c-convert.c (c_convert): New function, based on convert.
(convert): Make into wrapper of c_convert.
(convert_init): New function.
* c-typeck.c (enum impl_conv): Add ic_init_const.
(convert_for_assignment): Handle ic_init_const like ic_init. Add
new argument to convert_and_check call.
(digest_init): Pass ic_init_const to convert_for_assignment for
initializers required to be constant.
gcc/cp/
PR c/103031
* cvt.c (convert_init): New function.
gcc/testsuite/
PR c/103031
* gcc.dg/init-rounding-math-1.c: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread