GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.

Bug 51861

Summary: Incorrect generated code with __builtin_unreachable() on MIPS
Product: gcc Reporter: Maarten ter Huurne <maarten>
Component: targetAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P3    
Version: 4.5.1   
Target Milestone: ---   
Host: i686-linux Target: mipsel-linux
Build: i686-linux Known to work:
Known to fail: Last reconfirmed:
Attachments: Minimal test case

Description Maarten ter Huurne 2012-01-14 23:43:15 UTC
Created attachment 26326 [details]
Minimal test case

If I compile the attached test case for little endian MIPS with the options "-O2 -march=mips32", the generated code will hang at runtime instead of returning the correct value (30).

Minor changes to the code can produce a correct answer, a segfault, or various wrong answers. The test case is relatively large for a minimal test case (about 30 lines), but I couldn't reduce it any further.

The original problem also occurs with GCC 4.6.1; I haven't tested the test case with that version.

The problem occurs at -O2 and -O3, not at lower optimization levels; I haven't tested higher levels.

Without the "-march=mips32" option I get the wrong answer (20), but no hang.

When compiling for x86_64 the problem does not occur.

The problem occurs with both the C and the C++ compiler.

When compiling to an object file, the fetch_value() function is just 5 instructions when the generated code is bad, while it is over 20 instructions when the generated code is correct (for example, at -O1 or if the unused "case 4:" is commented out). So perhaps an invalid optimization is performed.

For easier testing, you can enable the printf: this doesn't change the behavior related to the bug, but it does violate the demand for test cases to have no external dependencies, so I used the return value of main() for the submitted version.



GCC was configured with: /home/mth/opendingux-buildroot/output/toolchain/gcc-4.5.1/configure --prefix=/opt/opendingux-toolchain/usr --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=mipsel-unknown-linux-uclibc --enable-languages=c,c++ --with-sysroot=/opt/opendingux-toolchain --with-build-time-tools=/opt/opendingux-toolchain/usr/mipsel-unknown-linux-uclibc/bin --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-libssp --disable-multilib --disable-tls --enable-shared --with-gmp=/home/mth/opendingux-buildroot/output/toolchain/gmp --with-mpfr=/home/mth/opendingux-buildroot/output/toolchain/mpfr --with-mpc=/home/mth/opendingux-buildroot/output/toolchain/mpc --disable-nls --enable-threads --disable-decimal-float --with-float=soft --with-abi=32 --with-tune=mips32 --with-pkgversion='Buildroot 2010.11-g76b414b' --with-bugurl=http://bugs.buildroot.net/
Comment 1 Andrew Pinski 2012-01-15 00:03:46 UTC
Fixed by http://gcc.gnu.org/ml/gcc-patches/2011-11/msg01991.html aka http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51187 .  This is already fixed.  The issue is unreachable with switch statements and delay slot scheduling was causing the issue.

*** This bug has been marked as a duplicate of bug 51187 ***