Bug in 2008Q3 release

Meloun Michal meloun at miracle.cz
Mon Nov 3 09:58:49 UTC 2008


 Hello everybody!
Unfortunately, I have problem with 2008Q3 release.
GCC miscompile this small test case.

//-----------------------------------------------------------------
//m68k-elf-gcc -mcpu=5470 -save-temps -da -c test.c -o test.o
int Test2(char*);

static void Test3(void)
{
  char tmp2[2] = "0";
}

void Test4(void)
{
  Test2("0");
}
//------------------------------------------------------------------

The file is compiled to:
#NO_APP
	.file	"test.c"
	.section	.rodata
.LC0:
	.string	"0"
	
	.text
	.align	2
	.type	Test3, @function
Test3:
	link.w %fp,#-4
	lea .LC0,%a0    ; <<-- !!!! Note: a0 contain ptr to "0" here
	move.w (%a0),-2(%fp)
	unlk %fp
	rts
	.size	Test3, .-Test3
	
	.align	2
	.globl	Test4
	.type	Test4, @function
Test4:
	link.w %fp,#0
	move.l %a0,-(%sp)  ; <<-- !!!! a0 is used uninitialized here
	jsr Test2
	addq.l #4,%sp
	unlk %fp
	rts
	.size	Test4, .-Test4
	.ident	"GCC: (GNU) 4.3.2"


And relevant part of RTL:
(please note missing reference to string constatnt "0" in first insn.

;; Function Test4 (Test4)


;; Generating RTL for tree basic block 2

;; Test2 (&"0"[0])
(insn 5 4 6 test.c:11 (set (mem/f/i:SI (pre_dec:SI (reg/f:SI 15 %sp)) [0 S4 A16])
        (reg:SI 8 %a0)) -1 (nil))     <<-- !!!! Why a0 ???? 

(call_insn 6 5 7 test.c:11 (set (reg:SI 0 %d0)
        (call (mem:QI (symbol_ref:SI ("Test2") [flags 0x41] <function_decl 0x7fdcf260 Test2>) [0 S1 A8])
            (const_int 4 [0x4]))) -1 (nil)
    (nil))

(insn 7 6 0 test.c:11 (set (reg/f:SI 15 %sp)
        (plus:SI (reg/f:SI 15 %sp)
            (const_int 4 [0x4]))) -1 (nil))



But, if i change one of strings "0" to something else, then 
first insn have reference to string and code is compiled OK.
RTL:
;; Test2 (&"1"[0])
(insn 5 4 6 test.c:11 (set (mem/f/i:SI (pre_dec:SI (reg/f:SI 15 %sp)) [0 S4 A16])
        (symbol_ref/f:SI ("*.LC1") [flags 0x2] <string_cst 0x7fde1a60>)) -1 (nil))

code:
Test4:
	link.w %fp,#0
	pea .LC1
	jsr Test2
	addq.l #4,%sp
	unlk %fp
	rts

For me, its looks like compiler forget reinitialize (clear)
registers content (assignment) between functions and uses a0 
assigned in function Test3. Unfortunately, I m not gcc expert 
and fixing this problem is out of my knowledge. 
Can anybody help me, please?
 
Btw, vanilla gcc 4.3.2 have exactly same problem (and some other - 
in long long expansions).

Many thanks

 Michal Meloun
 
 



More information about the coldfire-gnu-discuss mailing list