http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50063

             Bug #: 50063
           Summary: [avr]: wrong code for gcc.dg/torture/pta-ptrarith-3.c
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: g...@gcc.gnu.org
                CC: eric.wedding...@atmel.com
            Target: avr


Testcase gcc.dg/torture/pta-ptrarith-3.c
  
http://gcc.gnu.org/viewcvs/trunk/gcc/testsuite/gcc.dg/torture/pta-ptrarith-3.c?revision=145490&view=markup
produces wrong code for current trunk and avr-gcc 4.6.1

struct X 
{
  int *p;
  int *q;
  int *r;
};

int __attribute__((noinline))
foo (int i, int j, int k, int off)
{
  struct X x;
  int **p, *q;
  x.p = &i;
  x.q = &j;
  x.r = &k;
  p = &x.q;
  p += off;
  /* *p points to { i, j, k } */
  q = *p;
  return *q;
}

With -Os -mmcu=atmega88 4.6.1 output is (wrong):

foo:
    push r28     ;  42    *pushqi/1    [length = 1]
    push r29     ;  43    *pushqi/1    [length = 1]
    in r28,__SP_L__     ;  44    *movhi_sp/2    [length = 2]
    in r29,__SP_H__
    sbiw r28,12     ;  45    *addhi3/3    [length = 1]
    in __tmp_reg__,__SREG__     ;  46    *movhi_sp/1    [length = 5]
    cli
    out __SP_H__,r29
    out __SREG__,__tmp_reg__
    out __SP_L__,r28
/* prologue: function */
/* frame size = 12 */
/* stack size = 14 */
.L__stack_usage = 14
    std Y+8,r25     ;  2    *movhi/3    [length = 2]
    std Y+7,r24
    std Y+10,r23     ;  3    *movhi/3    [length = 2]
    std Y+9,r22
    std Y+12,r21     ;  4    *movhi/3    [length = 2]
    std Y+11,r20
    lsl r18     ;  55    *ashlhi3_const/2    [length = 2]
    rol r19
    add r18,r28     ;  16    *addhi3/1    [length = 2]
    adc r19,r29
    movw r26,r18     ;  41    *movhi/1    [length = 1]
    adiw r26,3     ;  18    *movhi/2    [length = 4]
    ld r30,X+
    ld r31,X
    sbiw r26,3+1
    ld r24,Z     ;  35    *movqi/4    [length = 1]
    ldd r25,Z+1     ;  36    *movqi/4    [length = 1]
/* epilogue start */
    adiw r28,12     ;  49    *addhi3/2    [length = 1]
    in __tmp_reg__,__SREG__     ;  50    *movhi_sp/1    [length = 5]
    cli
    out __SP_H__,r29
    out __SREG__,__tmp_reg__
    out __SP_L__,r28
    pop r29     ;  51    popqi    [length = 1]
    pop r28     ;  52    popqi    [length = 1]
    ret     ;  53    return_from_epilogue    [length = 1]



With 4.5.2 and same options, the test case runs on exit:


foo:
    push r29     ;  42    *pushhi/1    [length = 2]
    push r28
    in r28,__SP_L__     ;  43    *movhi_sp/2    [length = 2]
    in r29,__SP_H__
    sbiw r28,12     ;  44    *addhi3/3    [length = 1]
    in __tmp_reg__,__SREG__     ;  45    *movhi_sp/1    [length = 5]
    cli
    out __SP_H__,r29
    out __SREG__,__tmp_reg__
    out __SP_L__,r28
/* prologue: function */
/* frame size = 12 */
/* stack size = 14 */
.L__stack_usage = 14
    std Y+8,r25     ;  2    *movhi/3    [length = 2]
    std Y+7,r24
    std Y+10,r23     ;  3    *movhi/3    [length = 2]
    std Y+9,r22
    std Y+12,r21     ;  4    *movhi/3    [length = 2]
    std Y+11,r20
    movw r24,r28     ;  38    *movhi/1    [length = 1]
    adiw r24,7     ;  9    *addhi3/2    [length = 1]
    std Y+2,r25     ;  10    *movhi/3    [length = 2]
    std Y+1,r24
    movw r24,r28     ;  39    *movhi/1    [length = 1]
    adiw r24,9     ;  11    *addhi3/2    [length = 1]
    std Y+4,r25     ;  12    *movhi/3    [length = 2]
    std Y+3,r24
    movw r24,r28     ;  40    *movhi/1    [length = 1]
    adiw r24,11     ;  13    *addhi3/2    [length = 1]
    std Y+6,r25     ;  14    *movhi/3    [length = 2]
    std Y+5,r24
    lsl r18     ;  53    *ashlhi3_const/2    [length = 2]
    rol r19
    add r18,r28     ;  16    *addhi3/1    [length = 2]
    adc r19,r29
    movw r26,r18     ;  41    *movhi/1    [length = 1]
    adiw r26,3     ;  18    *movhi/2    [length = 4]
    ld r30,X+
    ld r31,X
    sbiw r26,3+1
    ld r24,Z     ;  35    *movqi/4    [length = 1]
    ldd r25,Z+1     ;  36    *movqi/4    [length = 1]
/* epilogue start */
    adiw r28,12     ;  48    *addhi3/2    [length = 1]
    in __tmp_reg__,__SREG__     ;  49    *movhi_sp/1    [length = 5]
    cli
    out __SP_H__,r29
    out __SREG__,__tmp_reg__
    out __SP_L__,r28
    pop r28     ;  50    pophi    [length = 2]
    pop r29
    ret     ;  51    return_from_epilogue    [length = 1]

Reply via email to