[Bug c/39635] New: integer wrong code bug on AVR

regehr at cs dot utah dot edu gcc-bugzilla@gcc.gnu.org
Sat Apr 4 05:42:00 GMT 2009


See below.  This bug was found using Avrora bug is reproducible in AVR studio. 

The problem exists in HEAD but not apparently in the 4.3 series.

The generated code looks to be wrong at -O2 and -Os.

regehr@john-home:~$ avr-gcc -v
Using built-in specs.
Target: avr
Configured with: ../configure --prefix=/home/regehr/avrgcc440/install
--target=avr --enable-languages=c,c++ --disable-nls --disable-libssp :
(reconfigured) ../configure --prefix=/home/regehr/avrgcc440/install
--target=avr --enable-languages=c,c++ --disable-nls --disable-libssp :
(reconfigured) ../configure --prefix=/home/regehr/avrgcc440/install
--target=avr --enable-languages=c,c++ --disable-nls --disable-libssp
Thread model: single
gcc version 4.5.0 20090403 (experimental) (GCC) 
regehr@john-home:~$ avr-gcc -O1 -mmcu=atmega128 small.c -o small.elf 
regehr@john-home:~$ java avrora.Main -colors=false -monitors=break small.elf
Avrora [Beta 1.7.107] - (c) 2003-2007 UCLA Compilers Group

Loading small.elf...[OK: 0.060 seconds]
=={ Simulation events }=======================================================
Node          Time   Event
------------------------------------------------------------------------------
   0           178  break instruction @ 0x0130, r30:r31 = 0x0001
==============================================================================
Simulated time: 179 cycles
Time for simulation: 0.061 seconds
Total throughput: 0.0029344263 mhz
regehr@john-home:~$ avr-gcc -O2 -mmcu=atmega128 small.c -o small.elf 
regehr@john-home:~$ java avrora.Main -colors=false -monitors=break small.elf
Avrora [Beta 1.7.107] - (c) 2003-2007 UCLA Compilers Group

Loading small.elf...[OK: 0.057 seconds]
=={ Simulation events }=======================================================
Node          Time   Event
------------------------------------------------------------------------------
   0           166  break instruction @ 0x0122, r30:r31 = 0x0C00
==============================================================================
Simulated time: 167 cycles
Time for simulation: 0.061 seconds
Total throughput: 0.002737705 mhz
regehr@john-home:~$ cat small.c
#include <stdint.h>
#include <limits.h>

#define safe_mod_macro_uint8_t_u_u(ui1,ui2) \
        ((((uint8_t)(ui2)) == ((uint8_t)0)) \
                        ? ((uint8_t)(ui1)) \
                        : (((uint8_t)(ui1)) % ((uint8_t)(ui2))))

static uint8_t
safe_mod_func_uint8_t_u_u (uint8_t _ui1, uint8_t _ui2)
{
  return safe_mod_macro_uint8_t_u_u(_ui1,_ui2);
}

#define safe_lshift_macro_uint16_t_u_u(left,right) \
         (((((unsigned int)(right)) >= sizeof(uint16_t)*CHAR_BIT) \
                         || (((uint16_t)(left)) > ((UINT16_MAX) >> ((unsigned
int)(right))))) \
                        ? ((uint16_t)(left)) \
                        : (((uint16_t)(left)) << ((unsigned int)(right))))

static uint16_t
safe_lshift_func_uint16_t_u_u(uint16_t _left, unsigned int _right)
{
  return safe_lshift_macro_uint16_t_u_u(_left,_right);
}

int8_t func_7 (uint8_t p_8);
int8_t func_7 (uint8_t p_8)
{
  if (safe_mod_func_uint8_t_u_u (0xC, safe_lshift_func_uint16_t_u_u (p_8,
p_8)))
    {
      return 0;
    }
  return 1;
}

static inline void platform_main_end(int8_t crc);
static inline void platform_main_end(int8_t crc)
{
  asm volatile("cli" "\n\t"
               "mov r30, %A0" "\n\t"
               "mov r31, %B0" "\n\t"
               "break"
               :
               : "r" (crc)
               : "memory"
               );
}

int main (void)
{
  platform_main_end (func_7(1));
  return 0;
}


-- 
           Summary: integer wrong code bug on AVR
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: regehr at cs dot utah dot edu
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: avr


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



More information about the Gcc-bugs mailing list