https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95429

            Bug ID: 95429
           Summary: Wrong code generated for -Os with target m68k on
                    Ubuntu
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: i...@abp-labs.com
  Target Milestone: ---

Created attachment 48638
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48638&action=edit
C source file compiled with -E option.

Hello,

I am using m68k-linux-gnu-gcc to compile code for my homebrew computer.

With the version gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04), the assembly
for the following code is correct:

RTC_Msg1.nbBytes = 9;
RTC_buffer[0] = 8;
RTC_buffer[1] = RTC_buffer[5] = (uint8_t)(year_bcd >> 24);
RTC_buffer[2] = RTC_buffer[6] = (uint8_t)(year_bcd >> 16);
RTC_buffer[3] = RTC_buffer[7] = (uint8_t)(year_bcd >> 8);
RTC_buffer[4] = RTC_buffer[8] = (uint8_t)(year_bcd);

gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
157c 0009 0001  moveb #9,%a2@(1)
1f7c 0008 0012  moveb #8,%sp@(18)
2002            movel %d2,%d0
4240            clrw %d0
4840            swap %d0
e048            lsrw #8,%d0
1f40 0017       moveb %d0,%sp@(23)
1f40 0013       moveb %d0,%sp@(19)
2002            movel %d2,%d0
4240            clrw %d0
4840            swap %d0
1f40 0018       moveb %d0,%sp@(24)
1f40 0014       moveb %d0,%sp@(20)
2002            movel %d2,%d0
e088            lsrl #8,%d0
1f40 0019       moveb %d0,%sp@(25)
1f40 0015       moveb %d0,%sp@(21)
1f42 001a       moveb %d2,%sp@(26)
1f42 0016       moveb %d2,%sp@(22)

With the version 9.3.0 provided in Ubuntu 20.04 packages, the following code is
generated and there is an illegal address trap during execution (write a long
at an odd address in the stack):

gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu1)
157c 0009 0001  moveb #9,%a2@(1)
1f7c 0008 001c  moveb #8,%sp@(28)
2f42 001d       movel %d2,%sp@(29) /* long on odd address! */
2f42 0021       movel %d2,%sp@(33) /* long on odd address! */

Options are:
-MMD -Os -m68000 -Wall -mpcrel -fdata-sections -ffunction-sections
-fomit-frame-pointer -fno-builtin -fno-ident -Iarch/m68k/include

If I use -O0 instead of -Os, the assembly is OK:

13fc 0009 0006  moveb #9,639fb
39fb 
1ebc 0008       moveb #8,%sp@
202f 000a       movel %sp@(10),%d0
4240            clrw %d0
4840            swap %d0
e048            lsrw #8,%d0
2000            movel %d0,%d0
1f40 0005       moveb %d0,%sp@(5)
102f 0005       moveb %sp@(5),%d0
1f40 0001       moveb %d0,%sp@(1)
202f 000a       movel %sp@(10),%d0
4240            clrw %d0
4840            swap %d0
2000            movel %d0,%d0
1f40 0006       moveb %d0,%sp@(6)
102f 0006       moveb %sp@(6),%d0
1f40 0002       moveb %d0,%sp@(2)
202f 000a       movel %sp@(10),%d0
e088            lsrl #8,%d0
2000            movel %d0,%d0
1f40 0007       moveb %d0,%sp@(7)
102f 0007       moveb %sp@(7),%d0
1f40 0003       moveb %d0,%sp@(3)
202f 000a       movel %sp@(10),%d0
1f40 0008       moveb %d0,%sp@(8)
102f 0008       moveb %sp@(8),%d0
1f40 0004       moveb %d0,%sp@(4)

Attached the C source file compiled with -E option.

Thanks in advance for the support!

Reply via email to