Hi,
I stumbled upon an internal compiler bug of the msp430-gcc 3.2.3. I
built the compiler using the build-mspgcc script (TinyOS-1.x). This
bug is also present in the msp430-tools RPMs available for download.

A single-line change should fix the bug. Not knowing to whom this
issue might be of interest I post it to this list.


The bug is triggered by the __nesc_hton_uint64 (conversion used for
nx_uint64_t). However, it always occurs whenever a uint8 is
zero-extended to an uint64.

Example:
--
unsigned long long foo(unsigned char *x) {
  return x[0];
}
--
$ msp430-gcc -c gccbug.c
gccbug.c: In function `foo':
gccbug.c:20: internal error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.


Plugging cc1 into the debugger reveals a null pointer access in the
'zeroextendqidi' helper routine of the code generator.
--
Program received signal SIGSEGV, Segmentation fault.
zeroextendqidi (insn=0xb7f214e0, operands=0x8248a20, len=0x0)
   at 
/home/muellren/TinyOS/tinyos-1.x/tools/src/mspgcc/build/gcc-3.2.3/gcc/config/msp430/msp430.c:5421
5421        *len -= 3;
--


The pointer is a NULL value passed to the function from output_154
(isns-output.c):
--
static const char *
   output_154 (operands, insn)
         rtx *operands ATTRIBUTE_UNUSED;
         rtx insn ATTRIBUTE_UNUSED;
    {
     return zeroextendqidi(insn, operands,NULL);
    }
--


Here is a trivial patch:
--- gcc-3.2.3/gcc/config/msp430/msp430.c        2007-08-28
11:07:50.000000000 +0200
+++ gcc-3.2.3patched/gcc/config/msp430/msp430.c 2007-08-28
11:19:17.000000000 +0200
@@ -5414,11 +5414,11 @@
  dummy += 6;
  OUT_INSN (len, "clr\t%B0", operands);
  OUT_INSN (len, "clr\t%C0", operands);
  OUT_INSN (len, "clr\t%D0", operands);

-  if (GET_CODE (operands[0]) == REG)
+  if ((GET_CODE (operands[0]) == REG) && len)
    *len -= 3;

  if (len)
    *len = dummy;

The generated assembly code seems to be ok. The buggy code is present
in the gcc-3.3 directory of the mspgcc.sourceforge.net CVS repository
(note the numbering mismatch, the gcc-3.3 directory is known to work
with 3.2.x). However, the bug is fixed in the gcc-3.4 tree. If one
insists on gcc 3.2.3 one could just apply another patch in the
build-mspgcc script.

regards
René

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to