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

--- Comment #1 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
Created attachment 65440
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65440&action=edit
pr127098.c: C test case

#define NI __attribute((noipa))

typedef char U __attribute__ ((vector_size (16)));

NI void fun (long i, U u)
{
  (void) i;
  if (u[0] != 1)
    __builtin_abort ();
}

U u = { 1 };

int main (void)
{
  fun (0, u);

  return 0;
}

This is a simpler test case with wrong code in main, AFAIKT for all
optimization levels including -O0.  The code in main is:

main:
;; Set up the frame pointer.
        in r28,__SP_L__  ;  116 [c=4 l=2]  *movhi/7
        in r29,__SP_H__
;; SP -= 16: Allocates space on the stack to pass u.
        in r24,__SP_L__  ;  69  [c=4 l=2]  *movhi/7
        in r25,__SP_H__
        sbiw r24,16      ;  70  [c=8 l=1]  *addhi3/2
        in __tmp_reg__,__SREG__  ;  71  [c=4 l=5]  *movhi/6
        cli
        out __SP_H__,r25
        out __SREG__,__tmp_reg__
        out __SP_L__,r24
;; Load u[0].
        lds r24,u        ;  72  [c=4 l=2]  movqi_insn/3
;; Set Z = r31:r30 = SP to access the argument location.
        in r30,__SP_L__  ;  73  [c=4 l=2]  *movhi/7
        in r31,__SP_H__
;; BUG: Stores u[0] at Z+16.
;; The correct offset would be Z+1 (since SP is post-decrement).
;; The code tramples return address etc,
;; and u[] is not set up as expected.
        std Z+16,r24     ;  74  [c=4 l=1]  movqi_insn/2
;; BUG continues for all elements of u[]...
        lds r24,u+1      ;  75  [c=4 l=2]  movqi_insn/3
        std Z+17,r24     ;  76  [c=4 l=1]  movqi_insn/2
        ...

Reply via email to