User account creation filtered due to spam.

Bug 51861 - Incorrect generated code with __builtin_unreachable() on MIPS
Summary: Incorrect generated code with __builtin_unreachable() on MIPS
Status: RESOLVED DUPLICATE of bug 51187
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2012-01-14 23:43 UTC by Maarten ter Huurne
Modified: 2012-01-15 00:03 UTC (History)
0 users

See Also:
Host: i686-linux
Target: mipsel-linux
Build: i686-linux
Known to work:
Known to fail:
Last reconfirmed:

Minimal test case (282 bytes, text/plain)
2012-01-14 23:43 UTC, Maarten ter Huurne

Note You need to log in before you can comment on or make changes to this bug.
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=
Comment 1 Andrew Pinski 2012-01-15 00:03:46 UTC
Fixed by aka .  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 ***