http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55554
Bug #: 55554 Summary: GCC generates illegal instruction for optimization level >=O1 when invoking casted pointer to function Classification: Unclassified Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: avshaba...@gmail.com Created attachment 28843 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28843 smallest possible program that reproduces an error The attached program generates an illegal instruction error when compiled on Mac OS X 10.8.2. == GCC info == $ gcc -v Using built-in specs. Target: i686-apple-darwin11 Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~67/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~67/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1 Thread model: posix gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) == BUG == To reproduce the bug compile with O1 and higher: $ gcc -std=c99 -fomit-frame-pointer -O1 gccbug.c -o gccbug $ ./gccbug Illegal instruction: 4 == WORKAROUND == Compile with O0: $ gcc -std=c99 -fomit-frame-pointer -O0 -g gccbug.c -o gccbug $ ./gccbug OK OK OK OK Please, feel free to contact me if you happen to know *any* (GCC-specific) workaround for the specified issue.