public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/55146] New: jumptables with byte entries produce wrong code with -Os/-O2 for SH-1
@ 2012-10-31  8:26 marcin.bukat at gmail dot com
  2012-12-09  2:58 ` [Bug target/55146] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: marcin.bukat at gmail dot com @ 2012-10-31  8:26 UTC (permalink / raw)
  To: gcc-bugs


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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-06-15 18:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-31  8:26 [Bug target/55146] New: jumptables with byte entries produce wrong code with -Os/-O2 for SH-1 marcin.bukat at gmail dot com
2012-12-09  2:58 ` [Bug target/55146] " pinskia at gcc dot gnu.org
2012-12-10  9:15 ` olegendo at gcc dot gnu.org
2012-12-10 21:20 ` marcin.bukat at gmail dot com
2013-01-30 22:38 ` olegendo at gcc dot gnu.org
2013-02-04 22:44 ` olegendo at gcc dot gnu.org
2013-03-09 13:00 ` olegendo at gcc dot gnu.org
2013-03-10  0:23 ` kkojima at gcc dot gnu.org
2014-06-15 18:53 ` olegendo at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).