Cross-Compiler Bug-Report: GNU C version 2.95.2 19991024 (release) (sh-coff)

Dietmar Petras dietmar.petras@elsa.de
Mon Jul 17 08:14:00 GMT 2000


Compiler produces incorrect arithmetical code!!!
In the minimum test case below one "add" ASM instruction is missing!!!

I configured the cross-compiler as follows:

../gcc-2.95.2/configure --target=sh-coff --prefix /usr/local/crosscomp --with-gnu-as --with-gnu-ld

(By the way, my host is of type i586-pc-linux-gnu)

The minimum test case:

---double-bad.c------------------------------------------------------------
signed long do_double(signed long sl1) {
  double d;
  signed long sl;

  d = sl1;
  
  sl = (signed long)d + 48751; /* error: no add, result is always 48751 */
  return sl;
}
---------------------------------------------------------------------------

Compile it with:

sh-coff-gcc -v -O3 -m3 -Wall -W double-bad.c -S -o double-bad.s

Output:
Reading specs from /usr/local/crosscomp/lib/gcc-lib/sh-coff/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/local/crosscomp/lib/gcc-lib/sh-coff/2.95.2/cpp -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=95 -D__sh__ -D__sh__ -Acpu(sh) -Amachine(sh) -D__OPTIMIZE__ -Wall -W -D__sh3__ double-bad.c /tmp/ccNIDH2O.i
GNU CPP version 2.95.2 19991024 (release) (Hitachi SH)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/crosscomp/lib/gcc-lib/sh-coff/2.95.2/include
 /usr/local/crosscomp/lib/gcc-lib/sh-coff/2.95.2/../../../../sh-coff/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/local/crosscomp/lib/gcc-lib/sh-coff/2.95.2/../../../../include/g++-3
 /usr/local/crosscomp/lib/gcc-lib/sh-coff/2.95.2/../../../../sh-coff/sys-include
End of omitted list.
 /usr/local/crosscomp/lib/gcc-lib/sh-coff/2.95.2/cc1 /tmp/ccNIDH2O.i -quiet -dumpbase double-bad.c -m3 -O3 -Wall -W -version -o double-bad.s
GNU C version 2.95.2 19991024 (release) (sh-coff) compiled by GNU C version 2.95.2 19991024 (release).

Here the assembler output (I added the comment with the missing instruction
by hand!):
---double-bad.s------------------------------------------------------------
	.file	"double-bad.c"
	.data
gcc2_compiled.:
___gnu_compiled_c:
	.text
	.align 4
	.global	_do_double
_do_double:
	mov.l	r14,@-r15
	mov.l	L3,r1
	sts.l	pr,@-r15
	jsr	@r1
	mov	r15,r14
	mov	r1,r5
	mov.l	L4,r1
	jsr	@r1
	mov	r0,r4
	mov	r0,r1
	mov.l	L5,r0
!!! >>>	add	r1,r0 <<< error this instruction is missing !!!
	mov	r14,r15
	lds.l	@r15+,pr
	rts	
	mov.l	@r15+,r14
L6:
	.align 2
L3:
	.long	___floatsidf
L4:
	.long	___fixdfsi
L5:
	.long	48751
---------------------------------------------------------------------------
That modified C code produces correct ASM code:

---double-bad.c------------------------------------------------------------
signed long do_double(signed long sl1) {
  double d;
  signed long sl;

  d = sl1;
  
  sl = (signed long)d + 48751;
 /* with the following line also the addition from the previous line is executed */
  sl += sl1;
  return sl;
}
---------------------------------------------------------------------------
---double-bad.s------------------------------------------------------------
	.file	"double-ok.c"
	.data
gcc2_compiled.:
___gnu_compiled_c:
	.text
	.align 4
	.global	_do_double
_do_double:
	mov.l	r8,@-r15
	mov.l	L3,r1
	mov.l	r14,@-r15
	mov	r4,r8
	sts.l	pr,@-r15
	jsr	@r1
	mov	r15,r14
	mov	r1,r5
	mov.l	L4,r1
	jsr	@r1
	mov	r0,r4
	mov.l	L5,r1
	add	r1,r0
	add	r8,r0
	mov	r14,r15
	lds.l	@r15+,pr
	mov.l	@r15+,r14
	rts	
	mov.l	@r15+,r8
L6:
	.align 2
L3:
	.long	___floatsidf
L4:
	.long	___fixdfsi
L5:
	.long	48751
---------------------------------------------------------------------------

Kind regards,

     Dietmar

-- 
---------------------------------------------------------------------------
Dr. Dietmar Petras     Senior Expert
ELSA AG                Engineering Consumer Communications
Sonnenweg 11           Phone: +49-(0)241-606-4649
52070 Aachen           Fax:   +49-(0)241-606-4699
Germany                EMail: Dietmar.Petras@ELSA.de
---------------------------------------------------------------------------


More information about the Gcc-bugs mailing list