Subject: toolchain/24938: gcc/powerpc codegen bug?
To: None <gnats-bugs@gnats.netbsd.org>
From: Juergen Hannken-Illjes <hannken@eis.cs.tu-bs.de>
List: netbsd-bugs
Date: 03/27/2004 17:21:21
>Number:         24938
>Category:       toolchain
>Synopsis:       gcc/powerpc codegen bug?
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 27 16:22:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Juergen Hannken-Illjes
>Release:        NetBSD 1.6ZL
>Organization:
	net
	
>Environment:
	
	
System: NetBSD exp451 1.6ZL NetBSD 1.6ZL (LOCAL.evbppc) #0: Fri Mar 26 08:19:36 MET 2004  root@watcher:/build/dist/obj/evbppc/sys/arch/evbppc/compile/LOCAL.evbppc evbppc
Architecture: powerpc
Machine: evbppc
>Description:
	The (new) awk does not work right on evbppc/powerpc. Everything is well
	if src/dist/nawk/lib.c::is_number() is compiled without optimization.

	The problem exists in awk from a cross-build. Building it native (with
	the cross-compiled gcc) works.

	The cross-build gcc identifies as:

	Reading specs from /build/dist/obj/evbppc/tooldir.NetBSD-1.6ZK-i386/lib/gcc-lib/powerpc--netbsd/3.3.3/specs
	Configured with: /build/dist/src/tools/gcc/../../gnu/dist/gcc/configure --target=powerpc--netbsd --disable-nls --enable-long-long --disable-multilib --enable-threads --program-transform-name=s,^,powerpc--netbsd-, --enable-languages=c c++ objc f77 --prefix=/build/dist/obj/evbppc/tooldir.NetBSD-1.6ZK-i386
	Thread model: posix
	gcc version 3.3.3 (NetBSD nb1 20040301)

	The cross-built native gcc identifies as:

	Using built-in specs.
	Configured with: /home/nick/work/netbsd/src/tools/gcc/../../gnu/dist/gcc/configure --enable-long-long --disable-multilib --enable-threads --disable-symvers --build=i386-unknown-netbsdelf --host=powerpc--netbsd --target=powerpc--netbsd
	Thread model: posix
	gcc version 3.3.3 (NetBSD nb1 20040301)

	The source file I used is:

	#include <stdio.h>
	#include <string.h>
	#include <ctype.h>
	#include <errno.h>
	#include <stdlib.h>
	#include <stdarg.h>
	#include <math.h>

	int is_number(const char *);
	int is_number(const char *s)
	{
		double r;
		char *ep;
		errno = 0;
		r = strtod(s, &ep);
		if (ep == s || r == HUGE_VAL || errno == ERANGE)
			return 0;
		while (*ep == ' ' || *ep == '\t' || *ep == '\n')
			ep++;
		if (*ep == '\0')
			return 1;
		else
			return 0;
	}

	The assembler output from the cross-build:

	/build/dist/obj/evbppc/tooldir.NetBSD-1.6ZK-i386/bin/powerpc--netbsd-gcc -O2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-sign-compare -Wno-traditional -Wno-uninitialized    -I/build/dist/src/dist/nawk -I. -DHAS_ISBLANK   -nostdinc -isystem /build/dist/dist/evbppc/usr/include -S -c lib.c -o opt.s

	.file	"lib.c"
	.section	".text"
	.align 2
	.globl is_number
	.type	is_number, @function
is_number:
	stwu 1,-48(1)
	mflr 0
	stw 29,36(1)
	mr 29,3
	stw 0,52(1)
	bl __errno
	mr 9,3
	li 0,0
	stw 0,0(9)
	mr 3,29
	addi 4,1,8
	bl strtod
	lwz 0,8(1)
	cmpw 0,0,29
	mfcr 8
	stw 8,12(1)
	beq- 0,.L3
	lis 9,__infinity@ha
	lfd 0,__infinity@l(9)
	fcmpu 7,1,0
	bne- 7,.L13
.L3:
	li 3,0
.L1:
	lwz 0,52(1)
	lwz 29,36(1)
	addi 1,1,48
	mtlr 0
	blr
.L13:
	bl __errno
	lwz 0,0(3)
	cmpwi 7,0,34
	beq- 7,.L3
	lwz 10,8(1)
	lbz 11,0(10)
	xori 0,11,32
	subfic 8,0,0
	adde 0,8,0
	xori 9,11,9
	subfic 8,9,0
	adde 9,8,9
	or 8,0,9
	cmpwi 7,8,0
	beq- 7,.L14
.L12:
	addi 10,10,1
	stw 10,8(1)
	lbz 0,0(10)
	xori 11,0,32
	subfic 9,11,0
	adde 11,9,11
	cmpwi 7,0,10
	xori 9,0,9
	subfic 8,9,0
	adde 9,8,9
	or. 0,11,9
	bne- 0,.L12
	beq+ 7,.L12
.L11:
	lbz 0,0(10)
	subfic 8,0,0
	adde 3,8,0
	b .L1
.L14:
	cmpwi 7,11,10
	bne+ 7,.L11
	b .L12
	.size	is_number, .-is_number
	.ident	"GCC: (GNU) 3.3.3 (NetBSD nb1 20040301)"

	The assembler output from the native-build:

	.file	"lib.c"
	.section	".text"
	.align 2
	.globl is_number
	.type	is_number, @function
is_number:
	stwu 1,-32(1)
	mflr 0
	stw 29,20(1)
	mr 29,3
	stw 0,36(1)
	bl __errno
	mr 9,3
	li 0,0
	stw 0,0(9)
	mr 3,29
	addi 4,1,8
	bl strtod
	lwz 0,8(1)
	cmpw 0,0,29
	beq- 0,.L3
	lis 9,__infinity@ha
	lfd 0,__infinity@l(9)
	fcmpu 0,1,0
	bne- 0,.L13
.L3:
	li 3,0
.L1:
	lwz 0,36(1)
	lwz 29,20(1)
	addi 1,1,32
	mtlr 0
	blr
.L13:
	bl __errno
	lwz 0,0(3)
	cmpwi 0,0,34
	beq- 0,.L3
	lwz 10,8(1)
	lbz 11,0(10)
	xori 0,11,32
	subfic 8,0,0
	adde 0,8,0
	xori 9,11,9
	subfic 8,9,0
	adde 9,8,9
	or. 8,0,9
	beq- 0,.L14
.L12:
	addi 10,10,1
	stw 10,8(1)
	lbz 11,0(10)
	xori 0,11,32
	subfic 9,0,0
	adde 0,9,0
	xori 9,11,9
	subfic 8,9,0
	adde 9,8,9
	or. 8,0,9
	bne- 0,.L12
	cmpwi 0,11,10
	beq+ 0,.L12
.L11:
	lbz 0,0(10)
	subfic 9,0,0
	adde 3,9,0
	b .L1
.L14:
	cmpwi 0,11,10
	bne+ 0,.L11
	b .L12
	.size	is_number, .-is_number
	.ident	"GCC: (GNU) 3.3.3 (NetBSD nb1 20040301)"
	
>How-To-Repeat:
	
>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted: