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]

2.95.2 argument-passing bug on PowerPC (LinuxPPC)


Dear gcc folks,

I have encountered a bug in the argument-passing of gcc-2.95.2 on the 
PowerPC--in at least one case, when you pass some arguments to a
subroutine, the arguments the subroutine actually receives are garbled.  A
short test program exhibiting the bug is attached below.

Compiler version: gcc 2.95.2
Machine: 1999 Apple PowerBook G3
OS: LinuxPPC 1999 Q3, kernel 2.2.12
Compiler command: gcc bug.c -o bug

The test program, attached below, just calls a subroutine bug() from
main(), printing out the argument list before and during the call.  These
two lists should match, but instead they don't; here is the output:

args: A, B, 1, 2, 3, 4, 2147482552, 5, 2147482560, 6, 7, 2147482568, 8
args: A, B, 1, 2, 3, 4, 2147482552, 5, 2147482560, 6, 7, 8, 8

The second-to-last argument (a pointer) is garbled (8 instead of
2147482568).  (Slight changes to the program cause the last argument to be
garbled instead.  More changes cause no argument to be garbled.)

Since the program is so short, I've also attached the assembly-language
output on my machine.  Thanks for any confirmation, help, patches, or
pointers!

Cordially,
Steven G. Johnson

--------------------------------------------------------------------

extern int printf(const char *, ...);

void bug(char transa, char transb, int m, int n, int k,
	 double a, double *A, int fdA, double *B, int fdB,
	 double b, double *C, int fdC)
{
     printf("args: %c, %c, %d, %d, %d, %g, %ld, %d, %ld, %d, %g, %ld, %d\n",
	    transa, transb, m, n, k, a, (long)A, fdA, (long)B, fdB, b,
	    (long)C, fdC);
}

int main(void)
{
  double A[1], B[1], C[1];

  printf("args: %c, %c, %d, %d, %d, %g, %ld, %d, %ld, %d, %g, %ld, %d\n",
	 'A', 'B', 1, 2, 3, 4.0, (long)A, 5, (long)B, 6, 7.0, (long)C, 8);

  bug('A', 'B', 1, 2, 3, 4.0, A, 5, B, 6, 7.0, C, 8);

  return 0;
}

----------------------------------------------------------------------
Assembly output:

	.file	"bug.c"
gcc2_compiled.:
	.section	".rodata"
	.align 2
.LC0:
	.string	"args: %c, %c, %d, %d, %d, %g, %ld, %d, %ld, %d, %g, %ld, %d\n"
	.section	".text"
	.align 2
	.globl bug
	.type	 bug,@function
bug:
	stwu 1,-80(1)
	mflr 0
	stw 31,76(1)
	stw 0,84(1)
	mr 31,1
	mr 11,3
	mr 0,4
	stw 5,28(31)
	stw 6,32(31)
	stw 7,36(31)
	stfd 1,40(31)
	stw 8,48(31)
	stw 9,52(31)
	stw 10,56(31)
	stfd 2,64(31)
	mr 9,11
	stb 9,24(31)
	stb 0,25(31)
	lbz 9,24(31)
	rlwinm 0,9,0,0xff
	lbz 11,25(31)
	rlwinm 9,11,0,0xff
	lwz 11,56(31)
	stw 11,8(1)
	lwz 11,88(31)
	stw 11,12(1)
	lwz 11,96(31)
	stw 11,16(1)
	lwz 11,100(31)
	stw 11,20(1)
	lis 11,.LC0@ha
	la 3,.LC0@l(11)
	mr 4,0
	mr 5,9
	lwz 6,28(31)
	lwz 7,32(31)
	lwz 8,36(31)
	lfd 1,40(31)
	lwz 9,48(31)
	lwz 10,52(31)
	lfd 2,64(31)
	creqv 6,6,6
	bl printf
.L2:
	lwz 11,0(1)
	lwz 0,4(11)
	mtlr 0
	lwz 31,-4(11)
	mr 1,11
	blr
.Lfe1:
	.size	 bug,.Lfe1-bug
	.section	".rodata"
	.align 3
.LC1:
	.long 0x40100000
	.long 0x0
	.align 3
.LC2:
	.long 0x401c0000
	.long 0x0
	.section	".text"
	.align 2
	.globl main
	.type	 main,@function
main:
	stwu 1,-64(1)
	mflr 0
	stw 31,60(1)
	stw 0,68(1)
	mr 31,1
	addi 0,31,32
	stw 0,8(1)
	li 0,6
	stw 0,12(1)
	addi 0,31,40
	stw 0,16(1)
	li 0,8
	stw 0,20(1)
	lis 9,.LC0@ha
	la 3,.LC0@l(9)
	li 4,65
	li 5,66
	li 6,1
	li 7,2
	li 8,3
	lis 9,.LC1@ha
	la 9,.LC1@l(9)
	lfd 1,0(9)
	addi 9,31,24
	li 10,5
	lis 11,.LC2@ha
	la 11,.LC2@l(11)
	lfd 2,0(11)
	creqv 6,6,6
	bl printf
	addi 0,31,32
	li 9,6
	stw 9,8(1)
	addi 9,31,40
	stw 9,12(1)
	li 9,8
	stw 9,16(1)
	li 3,65
	li 4,66
	li 5,1
	li 6,2
	li 7,3
	lis 9,.LC1@ha
	la 9,.LC1@l(9)
	lfd 1,0(9)
	addi 8,31,24
	li 9,5
	mr 10,0
	lis 11,.LC2@ha
	la 11,.LC2@l(11)
	lfd 2,0(11)
	bl bug
	li 3,0
	b .L3
.L3:
	lwz 11,0(1)
	lwz 0,4(11)
	mtlr 0
	lwz 31,-4(11)
	mr 1,11
	blr
.Lfe2:
	.size	 main,.Lfe2-main
	.ident	"GCC: (GNU) 2.95.2 19991024 (release)"


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