Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Oct 1996 21:05:36 +0200
From:      "Philippe Charnier" <charnier@xp11.frmug.org>
To:        current@FreeBSD.org
Subject:   gcc's bug. please comment
Message-ID:  <199610111905.VAA01615@xp11.frmug.org>

next in thread | raw e-mail | index | archive | help
Hello,

A friend found a bug in gcc-2.7.2.1. The following program fails on
i386 architecture (both FreeBSD and solaris-x86) and works as expected
on sparc (both sunos and solaris2.5.1) and on hp (hp-ux9.07). As I'm
not on the gcc-bug list, please comment before I report the bug. This
afternoon I sent a bug report to Sun but it was before trying on
FreeBSD.

The output should be `1 2' but it is `2 1' on i386 computers.
Here is the code:

----------mypb2.c-----------------
#include <stdio.h>
#include <stdlib.h>

main()
{ FILE *fic;
  int a[2][50], i = 0;

  fic=fopen("mypb2.csv","r");
  fscanf(fic, "%d;%d", &a[1][i++], &a[1][i++]);
  i = 0;
  while (i < 2) printf("%d ", a[1][i++]);
  printf("\n");
  fclose(fic);
}
----------------------------------
---------------mypb2.csv----------
1;2
----------------------------------

For those that do not have a solaris-2.5 box to test on, here is the assembly
output of the compiler.

	.file	"mypb2.c"
	.version	"01.01"
gcc2_compiled.:
.section	.rodata
.LC0:
	.string	"r"
.LC1:
	.string	"mypb2.csv"
.LC2:
	.string	"%d;%d"
.LC3:
	.string	"%d "
.LC4:
	.string	"\n"
.text
	.align 4
.globl main
	.type	 main,@function
main:
	pushl %ebp
	movl %esp,%ebp
	subl $408,%esp
	movl $0,-408(%ebp)
	pushl $.LC0
	pushl $.LC1
	call fopen
	addl $8,%esp
	movl %eax,%eax
	movl %eax,-4(%ebp)
	leal -404(%ebp),%eax
	movl -408(%ebp),%edx
	movl %edx,%ecx
	leal 0(,%ecx,4),%edx
	leal 200(%edx),%ecx
	addl %ecx,%eax
	pushl %eax
	incl -408(%ebp)
	leal -404(%ebp),%eax
	movl -408(%ebp),%edx
	movl %edx,%ecx
	leal 0(,%ecx,4),%edx
	leal 200(%edx),%ecx
	addl %ecx,%eax
	pushl %eax
	incl -408(%ebp)
	pushl $.LC2
	movl -4(%ebp),%eax
	pushl %eax
	call fscanf
	addl $16,%esp
	movl $0,-408(%ebp)
.L2:
	cmpl $1,-408(%ebp)
	jle .L4
	jmp .L3
	.align 4
.L4:
	movl -408(%ebp),%eax
	movl -204(%ebp,%eax,4),%edx
	pushl %edx
	incl -408(%ebp)
	pushl $.LC3
	call printf
	addl $8,%esp
	jmp .L2
	.align 4
.L3:
	pushl $.LC4
	call printf
	addl $4,%esp
	movl -4(%ebp),%eax
	pushl %eax
	call fclose
	addl $4,%esp
.L1:
	leave
	ret
.Lfe1:
	.size	 main,.Lfe1-main
	.ident	"GCC: (GNU) 2.7.2.1"

 
------                                                            ------ 
Philippe Charnier                               charnier@lirmm.fr (smtp)       
                                          charnier@xp11.frmug.org (uucp) 

    ``a PC not running FreeBSD is like a venusian with no tentacles'' 
------------------------------------------------------------------------



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610111905.VAA01615>