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

            Bug ID: 98627
           Summary: GCC emits unaligned memory access instructions causing
                    address error exceptions with the 68000 architecture
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: noring at nocrew dot org
  Target Milestone: ---

The 68000 architecture requires that (16-bit) word and (32-bit) long memory
accesses are aligned with even addresses, but GCC frequently emits code that
breaks this when compiling with optimisations (O1 or higher). This causes
address error exceptions, which are fatal errors that crash programs.

For example, consider

struct s { char a, b, c, d, e; };
struct s f(char a)
{
        return (struct s) { .a = a, .d = 'd' };
}

that GCC with O1 will compile into

00000000 <f>:
   0:   2049            moveal %a1,%a0
   2:   202f 0004       movel %sp@(4),%d0
   6:   42a9 0001       clrl %a1@(1)        /* <<<--- unaligned long clear */
   a:   1280            moveb %d0,%a1@
   c:   137c 0064 0003  moveb #100,%a1@(3)
  12:   4e75            rts

where offset 6 has "clrl %a1@(1)", which is an unaligned 32-bit long clear. GCC
can emit several similar variants of this, for example unaligned 16-bit word
clears, and possibly others.

Reply via email to