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]

Re: optimization/2847: GCC 2.96 with -O2 incorrectly compile if(var==0)break; else printf("test\n"); inside a while


Hi,

> Synopsis: GCC 2.96 with -O2 incorrectly compile if(var==0) break; else printf("test\n"); inside a while
>
> State-Changed-From-To: open->closed
> State-Changed-By: rodrigc
> State-Changed-When: Mon Aug 13 16:03:16 2001
> State-Changed-Why:
>     Works with: gcc version 3.0.1 20010813
>
>     Please contact Mandrake with issues regarding the
>     compiler supplied with Mandrake Linux.
>
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2847&database=gcc

I am sorry but it doesn't seem to work either with gcc version 3.0.1
20010814. I believe the correct result should be:

[gbeauchesne@thalys vrac]$ ./a.out
iNbr = 1
Wonderful

(don't miss the first printf() when entering the loop)

Funny enough, the behavior between "2.96" and 3.0.1 differs a bit:

[gbeauchesne@thalys vrac]$ gcc-2.96 -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/2.96/specs
gcc version 2.96 20000731 (Mandrake Linux 8.1 2.96-0.61mdk)

[gbeauchesne@thalys vrac]$ gcc-2.96 -O2 ./while.c && ./a.out
iNbr = 1

[gbeauchesne@thalys vrac]$ gcc-3.0.1 -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.0.1/specs
gcc version 3.0.1 20010814 (Mandrake Linux 8.1 3.0.1-0.3mdk)

[gbeauchesne@thalys vrac]$ gcc-3.0.1 -O2 ./while.c && ./a.out
Wonderful

And finally,

[gbeauchesne@thalys vrac]$ gcc-3.0.1 -O2 -fno-strength-reduce ./while.c &&
./a.out
iNbr = 1
Wonderful

Please find enclosed a slightly modified version of the test program. Here
are the results for gcc-3.0.1:

[gbeauchesne@thalys vrac]$ CC="gcc-3.0.1" sh ./wonderful.c
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.0.1/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --enable-long-long --enable-cstdio=stdio
--enable-clocale=generic --enable-languages=c,c++,f77,objc,java
--program-suffix=-3.0.1 --enable-objc-gc --host=i586-mandrake-linux-gnu
Thread model: posix
gcc version 3.0.1 20010814 (Mandrake Linux 8.1 3.0.1-0.3mdk)
CC: gcc-3.0.1; CFLAGS: -O1
>> PASS
CC: gcc-3.0.1; CFLAGS: -O1 -fstrength-reduce
>> FAIL
CC: gcc-3.0.1; CFLAGS: -O2
>> FAIL
CC: gcc-3.0.1; CFLAGS: -O2 -fno-strength-reduce
>> PASS

IMHO, this is a regression from 2.95.X.

You may want to check the following page for other results:
<https://qa.mandrakesoft.com/cgi-bin/show_bug.cgi?id=4221>

Bye,
Gwenole.
#if 0
${CC:=gcc} -v; cat wonderful.c | sed -n '/^\/\/ *\(.*\) *#.*/s//\1/p' | ( while read options; do echo "CC: $CC; CFLAGS: $options"; ${CC} -o wonderful ${options} wonderful.c && ./wonderful; ( [ $? -eq 0 ] && echo ">> PASS" ) || echo ">> FAIL"; rm -f ./wonderful; done ) 2> /dev/null
exit 0
#endif

// -O1				# PASS
// -O1 -fstrength-reduce	# FAIL
// -O2				# FAIL
// -O2 -fno-strength-reduce	# PASS

static int count = 0;

static void inc(void)
{
  count++;
}

int main(int argc, char *argv)
{
  int iNbr = 1;
  int test = 0;
  while(test == 0) {
	inc();
	if (iNbr == 0)
	  break;
	else {
	  inc();
	  iNbr--;
	}
	test = 1;
  }
  if (count != 2)
	abort();
  return 0;
}

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