public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/41894]  New: wrong code with -fno-split-wide-types
@ 2009-10-31 21:44 frank at mynety dot net
  2009-10-31 23:02 ` [Bug target/41894] " hutchinsonandy at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: frank at mynety dot net @ 2009-10-31 21:44 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-09-20  3:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
2009-10-31 23:02 ` [Bug target/41894] " hutchinsonandy at gcc dot gnu dot org
2009-10-31 23:10 ` j at uriah dot heep dot sax dot de
2009-10-31 23:12 ` j at uriah dot heep dot sax dot de
2009-10-31 23:55 ` eric dot weddington at atmel dot com
2009-11-01 17:24 ` hutchinsonandy at gcc dot gnu dot org
2009-11-01 17:27 ` hutchinsonandy at gcc dot gnu dot org
2009-11-01 17:28 ` hutchinsonandy at gcc dot gnu dot org
2009-11-01 17:45 ` eric dot weddington at atmel dot com
2009-11-02  0:54 ` hutchinsonandy at gcc dot gnu dot org
2010-09-20  3:03 ` eric dot weddington at atmel dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).