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]

This is probably an egcs 2.91.66 introduced compiler optimization bug,


	Hi,

   I am afraid that I did spot an obscure compiler optimization error
   within the RH6.1 released egcs 1.1.2-24 compiler.  Please have a
   look at the below small re-pro.  Removing the long type casts before
   the defined CHK_ or declaring the rdata with unsigned long seems a
   work-around.  All seems to narrow down to the sign bit set in CHK_B
   and the use of signed vars in combination with the -O optimizer flag.

   My thoughts on it are that the below code construction is valid,
   please let me know when I am wrong.  

   The problem only shows when compiling for an optimized model, as then
   effectively the if (test) is reduced to an always one condition
   and no expression assembly is generated.  I.e. -O.  See the attached
   minimum C-code repro below my signature.

Thanks,
-- Wim ten Have. 		AUDIX: 245 2981
Phone: (+31) 346 582981, Fax: Euro (+31) 346 552884, Room (+31) 346 558415


/*
**	Repro to demonstrate a RH6.1 compiler optimization defect
**		gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
**
**	All worked fine with previous versions released like
**		gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)
**
**	So before testing the below, check your installed compiler
**	version first!
**
**		% rpm -q egcs
**		egcs-1.1.2-24
**
**	Save the below and compile with
**
**		% cc filename.c
**		% a.out
**		GOOD NEWS
**
**		% cc -O filename.c
**		filename.c: In function `main':
**	?!=>	filename.c:37: warning: comparison is always one
**		% a.out
**		BAD NEWS
**
**	All works as expected using 'unsigned long' over 'long' for
**	rdata.	Or when removing the type cast on CHK_A or CHK_B
**
**	Wim ten Have, <wtenhave@sybase.com>
**	Thu Jan  6 12:07:57 CET 2000
*/

#define CHK_A	(long)0x40000000
#define	CHK_B	(long)0x80000000

main ()
{
	long	rdata = CHK_B;

	if ((rdata & CHK_A) ||
		!(rdata & CHK_B))
	{
		printf ("BAD NEWS\n");
	} else
	{
		printf ("GOOD NEWS\n");
	}
}









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