/* * Summary: * Wrong statement reordering * Description: * If you run this program, it will produce an output of 1. * The reason is that the assignment V1=0 which should be * executed before the call to cl_throw() is moved after * this call, and hence when cl_throw() invokes longjmp() * the variable is not assigned a value. * Operating system: * Ubuntu 5.10 * Machine: * Pentium 4 * Compiler: (gcc -v) * Using built-in specs. * Target: i486-linux-gnu * Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --with-gxx-include-dir=/usr/include/c++/4.0.2 --enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls --without-included-gettext --enable-threads=posix --program-suffix=-4.0 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --enable-checking=release i486-linux-gnu * Thread model: posix * gcc version 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9) */
typedef int __jmp_buf[6]; typedef struct { unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))]; } __sigset_t; typedef struct __jmp_buf_tag { __jmp_buf __jmpbuf; int __mask_was_saved; __sigset_t __saved_mask; } jmp_buf[1]; extern int setjmp (jmp_buf __env) __attribute__ ((__nothrow__)); extern void longjmp (struct __jmp_buf_tag __env[1], int __val) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__)); extern int printf (__const char *__restrict __format, ...); static jmp_buf foo; extern void cl_throw(); void cl_throw() { longjmp(foo, 1); } int L1foo(int V0) { volatile int V1 = V0; if (setjmp (foo)) { goto L9; } V1= 0; cl_throw(); L9:; return V1; } int main () { printf("%d\n", L1foo(1)); return 0; } -- Summary: Wrong statement reordering Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: worm at arrakis dot es GCC host triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24635