public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c/55108] New: bad compile-time evaluation of members of initialized union @ 2012-10-28 16:04 acn1 at cam dot ac.uk 2012-10-29 14:44 ` [Bug target/55108] " rguenth at gcc dot gnu.org ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: acn1 at cam dot ac.uk @ 2012-10-28 16:04 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55108 Bug #: 55108 Summary: bad compile-time evaluation of members of initialized union Classification: Unclassified Product: gcc Version: 4.6.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: acn1@cam.ac.uk Created attachment 28548 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28548 internal file "bad.i" obtained using -save-temp, as requested. gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper Target: arm-linux-gnueabihf Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-8+rpi1' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf Thread model: posix gcc version 4.6.3 (Debian 4.6.3-8+rpi1) File bad.c contains #include <stdio.h> int main(int argc, char *argv[]) { union { double d; unsigned char c[8]; } u = {1.0/7.0}; printf("Bytes from float are %x %x %x %x\n", u.c[0] & 0xff, u.c[1] & 0xff, u.c[2] & 0xff, u.c[3] & 0xff); return 0; } My hope is that the aliasing is OK both because the float is aliased with chars and because I believed that GCC was kind about unions. The output is acn1@raspberrypi ~ $ gcc -O0 bad.c -o bad0 acn1@raspberrypi ~ $ gcc -O1 bad.c -o bad1 -Wall -Wextra bad.c: In function ‘main’: bad.c:3:14: warning: unused parameter ‘argc’ [-Wunused-parameter] bad.c:3:26: warning: unused parameter ‘argv’ [-Wunused-parameter] acn1@raspberrypi ~ $ ./bad0 Bytes from float are 92 24 49 92 <<< expected output acn1@raspberrypi ~ $ ./bad1 Bytes from float are 92 924924 9249 92 <<< output > 0xff unexpected acn1@raspberrypi ~ $ To my mind whatever else might be going on the "& 0xff" that I have should not let me get such large numbers displayed! The ".i" file is attached. gcc is evaluating the components of the union at compile time and not respecting the "unsigned char" width or the subseqent "& 0xff". ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/55108] bad compile-time evaluation of members of initialized union 2012-10-28 16:04 [Bug c/55108] New: bad compile-time evaluation of members of initialized union acn1 at cam dot ac.uk @ 2012-10-29 14:44 ` rguenth at gcc dot gnu.org 2012-10-30 14:13 ` rearnsha at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: rguenth at gcc dot gnu.org @ 2012-10-29 14:44 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55108 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target| |arm-linux-gnueabihf Component|c |target --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> 2012-10-29 14:44:21 UTC --- Works for me on x86_64. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/55108] bad compile-time evaluation of members of initialized union 2012-10-28 16:04 [Bug c/55108] New: bad compile-time evaluation of members of initialized union acn1 at cam dot ac.uk 2012-10-29 14:44 ` [Bug target/55108] " rguenth at gcc dot gnu.org @ 2012-10-30 14:13 ` rearnsha at gcc dot gnu.org 2012-10-30 14:16 ` rearnsha at gcc dot gnu.org ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: rearnsha at gcc dot gnu.org @ 2012-10-30 14:13 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55108 Richard Earnshaw <rearnsha at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2012-10-30 Ever Confirmed|0 |1 Known to fail| |4.6.3, 4.7.0 --- Comment #2 from Richard Earnshaw <rearnsha at gcc dot gnu.org> 2012-10-30 14:13:15 UTC --- Confirmed. It seems the compiler is incorrectly eliminating some zero-extend operations. We have Ra:SI = Rx:SI >> 8 Rb:QI = subreg:QI (Ra:SI 0) Rc:SI = subreg:SI (Rb:QI 0) Rd:SI = Rc:SI & 255 cse1 pass then decides incorrectly (and presumably because of the paradoxical subreg) that Rd == Rc and discards the mask operation. Also seen in 4.7, haven't been able to test trunk. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/55108] bad compile-time evaluation of members of initialized union 2012-10-28 16:04 [Bug c/55108] New: bad compile-time evaluation of members of initialized union acn1 at cam dot ac.uk 2012-10-29 14:44 ` [Bug target/55108] " rguenth at gcc dot gnu.org 2012-10-30 14:13 ` rearnsha at gcc dot gnu.org @ 2012-10-30 14:16 ` rearnsha at gcc dot gnu.org 2013-02-03 23:25 ` mikpe at it dot uu.se 2013-02-04 0:06 ` pinskia at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: rearnsha at gcc dot gnu.org @ 2012-10-30 14:16 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55108 --- Comment #3 from Richard Earnshaw <rearnsha at gcc dot gnu.org> 2012-10-30 14:15:43 UTC --- At armv6t2 and later we have a ubfx instruction available and that is enough to mask this bug. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/55108] bad compile-time evaluation of members of initialized union 2012-10-28 16:04 [Bug c/55108] New: bad compile-time evaluation of members of initialized union acn1 at cam dot ac.uk ` (2 preceding siblings ...) 2012-10-30 14:16 ` rearnsha at gcc dot gnu.org @ 2013-02-03 23:25 ` mikpe at it dot uu.se 2013-02-04 0:06 ` pinskia at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: mikpe at it dot uu.se @ 2013-02-03 23:25 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55108 --- Comment #4 from Mikael Pettersson <mikpe at it dot uu.se> 2013-02-03 23:24:37 UTC --- On armv5tel-linux-gnueabi this bug is reproducible with gcc-4.6 but not with gcc-4.7 or 4.8. The wrong-code was made latent for 4.7.0 by r179556 aka PR38885, a missed-optimization fix. Bisecting with that fix disabled (a simple #if 0 / #endif wrapper around the new code) showed that the wrong-code was fixed properly for 4.8 by r187648 aka PR53352, a fix for incorrect CSE of unions on ARM. Backporting r187648 to 4.6 fixes this PR's test case with 4.6 on armv5tel. Anyone backporting r187648 to 4.7 or 4.6 should also backport the test case fixup in r187654. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/55108] bad compile-time evaluation of members of initialized union 2012-10-28 16:04 [Bug c/55108] New: bad compile-time evaluation of members of initialized union acn1 at cam dot ac.uk ` (3 preceding siblings ...) 2013-02-03 23:25 ` mikpe at it dot uu.se @ 2013-02-04 0:06 ` pinskia at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2013-02-04 0:06 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55108 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |DUPLICATE --- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-02-04 00:05:48 UTC --- dup then . *** This bug has been marked as a duplicate of bug 53352 *** ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-02-04 0:06 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-10-28 16:04 [Bug c/55108] New: bad compile-time evaluation of members of initialized union acn1 at cam dot ac.uk 2012-10-29 14:44 ` [Bug target/55108] " rguenth at gcc dot gnu.org 2012-10-30 14:13 ` rearnsha at gcc dot gnu.org 2012-10-30 14:16 ` rearnsha at gcc dot gnu.org 2013-02-03 23:25 ` mikpe at it dot uu.se 2013-02-04 0:06 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).