Commandline:
avr-gcc -S -mmcu=atmega128 -Os 
-fno-inline-small-functions -fno-split-wide-types bug.c

Sourcecode:

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;

typedef union
{
  struct {
    uint8_t sekunden;
    uint8_t minuten;
  } x;
  uint16_t sekmin;
} zeit_t;


void testmich2 (zeit_t tmp) {
  // just something that cannot be optimized out
  asm volatile("nop");
}

void testmich (zeit_t zeit) {

  zeit_t tmp;

  tmp.x = zeit.x;

  do {
    testmich2(tmp);

    if (tmp.x.sekunden)
      tmp.x.sekunden--;
    else {
      tmp.x.sekunden = 59;
      tmp.x.minuten--;
    }
  } while (tmp.x.sekunden || tmp.x.minuten);
}

int main (void) {
  zeit_t zeit;

  zeit.x.minuten = 1;
  zeit.x.sekunden = 2;

  testmich(zeit);

  return 0;
}


The statements

if (tmp.x.sekunden)
      tmp.x.sekunden--;

translate to:

        mov r18,r28
        subi r18,lo8(-(-1))
        movw r28,r18

which is wrong; r19 (used by movw) has a not defined value.


-- 
           Summary: wrong code with -fno-split-wide-types
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: frank at mynety dot net


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

Reply via email to