This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/36494] New: Char arrays gets corrupted in avr programs.


I've seen this bug in 4.1.2, 4.2.0, 4.2.1, 4.2.2, 4.3.0 and 4.3.1 (and at least
with the version 4.1.2 and 4.3.0 of the avr-gcc-c++-compiler). What happens is
that when a char array gets a value assigned through a quoted string, the data
gets corrupted (or lost) in the compilation, but if it's initialized with an
array of numbers it gets the correct value. I've created a small example:

#include <avr/io.h>

int main ()
{
  char a[] = ":";
  char b[] = { 0x3a, 0 };
  int result = 0;

  if (a[0] == 0x3a) result |= 1;
  if (b[0] == 0x3a) result |= 2;

  DDRC = 0x0f;
  PORTC = result;

  return 0;
}

The expected result is of course 3 (which I get if I compile a slightly
modified program for i386) but what I get is 2. In my world that's not quite
accepted, I hope you all concur. The include file and the macros for DDRC and
PORTC doesn't matter, I've verified with dummy values that they're ok.

[martin@chip ~]$ avr-gcc -v
Using built-in specs.
Target: avr
Configured with: ../gcc-4.3.1/configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --target=avr --enable-languages=c,c++ --disable-nls
--disable-libssp --with-system-zlib --enable-version-specific-runtime-libs
Thread model: single
gcc version 4.3.1 (GCC) 
[martin@chip ~]$ uname -a
Linux chip.chaos 2.6.24.7-92.fc8 #1 SMP Wed May 7 16:50:09 EDT 2008 i686 athlon
i386 GNU/Linux

Flags used while compiling are -mmcu=atmega48 -Wall. Optimization doesn't seem
to make any difference. The .i-file looks like this:

# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"
# 1 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/io.h" 1 3
# 87 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/sfr_defs.h" 1 3
# 126 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/sfr_defs.h" 3
# 1 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/inttypes.h" 1 3
# 37 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/inttypes.h" 3
# 1 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/stdint.h" 1 3
# 121 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/stdint.h" 3
typedef int int8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef int int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
typedef int int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));

typedef int int64_t __attribute__((__mode__(__DI__)));
typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
# 142 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/stdint.h" 3
typedef int16_t intptr_t;




typedef uint16_t uintptr_t;
# 159 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/stdint.h" 3
typedef int8_t int_least8_t;




typedef uint8_t uint_least8_t;




typedef int16_t int_least16_t;




typedef uint16_t uint_least16_t;




typedef int32_t int_least32_t;




typedef uint32_t uint_least32_t;







typedef int64_t int_least64_t;






typedef uint64_t uint_least64_t;
# 213 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/stdint.h" 3
typedef int8_t int_fast8_t;




typedef uint8_t uint_fast8_t;




typedef int16_t int_fast16_t;




typedef uint16_t uint_fast16_t;




typedef uint64_t uint_least64_t;
# 213 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/stdint.h" 3
typedef int8_t int_fast8_t;




typedef uint8_t uint_fast8_t;




typedef int16_t int_fast16_t;




typedef uint16_t uint_fast16_t;




typedef int32_t int_fast32_t;




typedef uint32_t uint_fast32_t;







typedef int64_t int_fast64_t;






typedef uint64_t uint_fast64_t;
# 273 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/stdint.h" 3
typedef int64_t intmax_t;




typedef uint64_t uintmax_t;
# 38 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/inttypes.h" 2 3
# 77 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/inttypes.h" 3
typedef int32_t int_farptr_t;



typedef uint32_t uint_farptr_t;
# 127 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/sfr_defs.h" 2 3
# 88 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/io.h" 2 3
# 290 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/iom48.h" 1 3
# 36 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/iom48.h" 3
# 1 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/iomx8.h" 1 3
# 37 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/iom48.h" 2 3
# 291 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/io.h" 2 3
# 360 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/portpins.h" 1 3
# 361 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/io.h" 2 3
# 370 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/io.h" 3
# 1 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/version.h" 1 3
# 371 "/usr/lib/gcc/avr/4.3.1/../../../../avr/include/avr/io.h" 2 3
# 2 "test.c" 2

int main ()
{
  char a[] = ":";
  char b[] = { 0x3a, 0 };
  int result = 0;

  if (a[0] == 0x3a) result |= 1;
  if (b[0] == 0x3a) result |= 2;

  (*(volatile uint8_t *)((0x07) + 0x20)) = 0x0f;
  (*(volatile uint8_t *)((0x08) + 0x20)) = result;

  return 0;
}

I'll of course try to answer any questions as prompt and detailed as possible.

Regards

/Martin


-- 
           Summary: Char arrays gets corrupted in avr programs.
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: martin at kfib dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]