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

             Bug #: 54476
           Summary: Passing -1 to __builtin_avr_delay_cycles causes cc1
                    memory usage to explode on x86_64 host
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: senthil_kumar.selva...@atmel.com
              Host: Linux x86_64
            Target: AVR
             Build: 4.8.0 20120903


gcc/testsuite/gcc.target/avr/torture/builtins-1.c has

void delay_4 (void)  { __builtin_avr_delay_cycles (-1ul); }

When run on a 64 bit host, the delay cycles call with -1 causes cc1 to consume
huge amounts of memory, eventually timing out or running out of virtual memory.

Looking at the code, avr_expand_delay_cycles converts the operand passed to an
unsigned HOST_WIDE_INT. On a 64 bit machine, -1 becomes 0xFFFFFFFFFFFFFFFF. The
range checks only check for 0xFFFFFFFF and therefore get bypassed. The while
(cycles >= 2) then keeps running, generating loads of nop instructions,
eventually causing memory exhaustion.

The delay cycles builtin is declared to take an unsigned long in
avr_init_builtins. If longs are 32 bit for the AVR target, perhaps only the
lower 4 bytes should be used?

Reply via email to