This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/55146] New: jumptables with byte entries produce wrong code with -Os/-O2 for SH-1
- From: "marcin.bukat at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 31 Oct 2012 08:25:46 +0000
- Subject: [Bug target/55146] New: jumptables with byte entries produce wrong code with -Os/-O2 for SH-1
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55146
Bug #: 55146
Summary: jumptables with byte entries produce wrong code with
-Os/-O2 for SH-1
Classification: Unclassified
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: target
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: marcin.bukat@gmail.com
Created attachment 28580
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28580
testcase C file
Switch statement with enough cases inside is translated to jumptable. If the
offsets are small enough, byte entries are used. If there is odd number of
cases this implies padding byte (since all SH instructions are 2 byte wide). In
the corner case this padding byte can cause the offset to switch from positive
to negative since move.b instruction used to fetch jumptable entry sign extends
the byte. This bug is very old and dates back at least to 4.0.3 days. See
attachment.
When compiled with sh-elf-gcc -Os -c test-jens.c -o sh-test.o it produces wrong
jumping code. http://pastebin.com/ZgJK3bgS has slightly commented disassembly
to point out what I mean.
The workaround is to decrease MIN_OFFSET by one for byte case in
gcc/config/sh/sh.h . This is not a proper fix though.