See description and how to repeat below:
[EMAIL PROTECTED]:~> cat foo.c #include <stdio.h> int i; void foo(long long l, void *buf) { float f= (float) l; i= (long long) f != l; *(float*) buf= f; } int main() { float f; long long l= 1073741825; foo(l, &f); printf("%lld %d %f\n", l, i, f); } [EMAIL PROTECTED]:~> gcc foo.c; ./a.out 1073741825 1 1073741824.000000 [EMAIL PROTECTED]:~> gcc -O1 foo.c; ./a.out 1073741825 0 1073741824.000000 [EMAIL PROTECTED]:~> gcc -O3 foo.c; ./a.out 1073741825 0 1073741825.000000 [EMAIL PROTECTED]:~> gcc -O3 -ffloat-store foo.c; ./a.out 1073741825 1 1073741824.000000 [EMAIL PROTECTED]:~> gcc -v Reading specs from /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.3/specs Configured with: ../gcc-3.4.3/configure --enable-threads=posix --enable-language=c,c++ : (reconfigured) ../gcc-3.4.3/configure --enable-threads=posix --enable-languages=c,c++ : (reconfigured) ../gcc-3.4.3/configure --enable-threads=posix --enable-languages=c,c++ Thread model: posix gcc version 3.4.3 While I see no problem with cases 1 and 3, the case 2 (-O1) seems to be broken: gcc fails to check that truncation happened, although it's there. Environment: System: Linux dragonfly 2.6.5-7.108-default #1 Wed Aug 25 13:34:40 UTC 2004 i686 i686 i386 GNU/Linux Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: ../gcc-3.4.3/configure --enable-threads=posix --enable-language=c,c++ : (reconfigured) ../gcc-3.4.3/configure --enable-threads=posix --enable-languages=c,c++ : (reconfigured) ../gcc-3.4.3/configure --enable-threads=posix --enable-languages=c,c++ How-To-Repeat: See the program given in description. ------- Additional Comments From konstantin at mysql dot com 2004-12-15 13:29 ------- Fix: I know of no workaround. -- Summary: check if float -> long store truncation happened fails with -O1 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: konstantin at mysql dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19011