[Bug tree-optimization/55559] [4.6/4.7/4.8 Regression] Marshalling double through union with inlines, incorrect behavior with -O2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9 --- Comment #8 from rguenther at suse dot de rguenther at suse dot de 2012-12-04 09:02:00 UTC --- On Mon, 3 Dec 2012, mpreda at gmail dot com wrote: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9 --- Comment #7 from Mihai Preda mpreda at gmail dot com 2012-12-03 22:13:03 UTC --- Thanks, I didn't realize that (unsigned)-1.0 is undefined. For the behavior I was expecting it's enough to use an intermediary cast through int, e.g. (unsigned)(int)-1.0. Yes, that makes it implementation-defined (and all implementations I know of do what you expect, modulo-two reduction). It may be nice to generate a consistent (-O0/-O1) result for (unsigned)-1.0 though, even if not required by the standard. That's unfortunately generally impossible.
[Bug tree-optimization/55559] [4.6/4.7/4.8 Regression] Marshalling double through union with inlines, incorrect behavior with -O2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9 Richard Biener rguenth at gcc dot gnu.org changed: What|Removed |Added Status|NEW |ASSIGNED Known to work||4.3.6 AssignedTo|unassigned at gcc dot |rguenth at gcc dot gnu.org |gnu.org | Target Milestone|--- |4.6.4 Summary|Marshalling double through |[4.6/4.7/4.8 Regression] |union with inlines, |Marshalling double through |incorrect behavior with -O2 |union with inlines, ||incorrect behavior with -O2 --- Comment #4 from Richard Biener rguenth at gcc dot gnu.org 2012-12-03 11:43:53 UTC --- Mine then.
[Bug tree-optimization/55559] [4.6/4.7/4.8 Regression] Marshalling double through union with inlines, incorrect behavior with -O2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9 Richard Biener rguenth at gcc dot gnu.org changed: What|Removed |Added Keywords|wrong-code | Status|ASSIGNED|RESOLVED Resolution||INVALID --- Comment #5 from Richard Biener rguenth at gcc dot gnu.org 2012-12-03 12:30:20 UTC --- We ask fold_unary to fold fold_unary_ignore_overflow_loc (loc=2147483655, code=FIX_TRUNC_EXPR, type=0x76d17690, op0=0x76e23858) at /space/rguenther/src/svn/trunk/gcc/fold-const.c:8363 (gdb) call debug_tree (type) integer_type 0x76d17690 unsigned int public unsigned SI size integer_cst 0x76d1a0c0 type integer_type 0x76d170a8 bitsizetype constant 32 unit size integer_cst 0x76d1a0e0 type integer_type 0x76d17000 sizetype constant 4 align 32 symtab 0 alias set -1 canonical type 0x76d17690 precision 32 min integer_cst 0x76d1a100 0 max integer_cst 0x76d1a0a0 4294967295 pointer_to_this pointer_type 0x76d270a8 (gdb) call debug_tree (op0) real_cst 0x76e23858 type real_type 0x76d17f18 double sizes-gimplified DF size integer_cst 0x76d02d40 constant 64 unit size integer_cst 0x76d02d60 constant 8 align 64 symtab 0 alias set -1 canonical type 0x76d17f18 precision 64 pointer_to_this pointer_type 0x76d1f150 constant -1.0e+0 which ends up in fold_convert_const_int_from_real which returns 0 with TREE_OVERFLOW set. Note that you end up converting the double -1.0 to unsigned which according to C99 6.3.1.4 ends up invoking undefined behavior. GCC's behavior is not ill-defined, your testcase is. That behavior changed is fine as it is unsefined.
[Bug tree-optimization/55559] [4.6/4.7/4.8 Regression] Marshalling double through union with inlines, incorrect behavior with -O2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9 --- Comment #6 from Paolo Carlini paolo.carlini at oracle dot com 2012-12-03 12:51:45 UTC --- I knew that a PR using marshalling couldn't be right ;)
[Bug tree-optimization/55559] [4.6/4.7/4.8 Regression] Marshalling double through union with inlines, incorrect behavior with -O2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9 --- Comment #7 from Mihai Preda mpreda at gmail dot com 2012-12-03 22:13:03 UTC --- Thanks, I didn't realize that (unsigned)-1.0 is undefined. For the behavior I was expecting it's enough to use an intermediary cast through int, e.g. (unsigned)(int)-1.0. It may be nice to generate a consistent (-O0/-O1) result for (unsigned)-1.0 though, even if not required by the standard.