This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/55146] New: jumptables with byte entries produce wrong code with -Os/-O2 for SH-1


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]