www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Incorrect code generation -O2 gdc

reply Johan Granberg <lijat.meREM OVEgmail.com> writes:
The following code generates an assert error when compiling with gdc and 
-O2 on my iBook G3 800mhz OS X 10.4.7

gdc (GCC) 4.0.1 (gdc 0.19, using dmd 0.162)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

It looks like something goes wrong when copying structs (or I'm 
incorrect in believing structs is just binary copied)

<code>
struct SigeCallback
{
	union
	{
		void delegate(uint) del;
		void function(uint) dfp;
	}
	static SigeCallback opCall(void function(uint) c,uint i)
	{
		SigeCallback a;
		a.dfp=c;
		return a;
	}
}
SigeCallback f;
static this()
{
	f=SigeCallback(&sigeFpNull,0);//this line causes an assert error
	//f.dfp=&sigeFpNull;//this line works ok
}
void sigeFpNull(uint i){}
void main()
{
	sigeFpNull(0);
	assert(f.dfp);f.dfp(0);//line 26
}
/* output from running this
$ ./test
Error: AssertError Failure test.d(26)
*/
</code>
Sep 14 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Johan Granberg schrieb am 2006-09-14:
 The following code generates an assert error when compiling with gdc and 
 -O2 on my iBook G3 800mhz OS X 10.4.7

 gdc (GCC) 4.0.1 (gdc 0.19, using dmd 0.162)
 Copyright (C) 2005 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 It looks like something goes wrong when copying structs (or I'm 
 incorrect in believing structs is just binary copied)

<code>
 struct SigeCallback
 {
 	union
 	{
 		void delegate(uint) del;
 		void function(uint) dfp;
 	}
 	static SigeCallback opCall(void function(uint) c,uint i)
 	{
 		SigeCallback a;
 		a.dfp=c;
 		return a;
 	}
 }
 SigeCallback f;
 static this()
 {
 	f=SigeCallback(&sigeFpNull,0);//this line causes an assert error
 	//f.dfp=&sigeFpNull;//this line works ok
 }
 void sigeFpNull(uint i){}
 void main()
 {
 	sigeFpNull(0);
 	assert(f.dfp);f.dfp(0);//line 26
 }
 /* output from running this
 $ ./test
 Error: AssertError Failure test.d(26)
 */
</code>
Added to DStress as http://dstress.kuehne.cn/run/o/odd_bug_09_A.d http://dstress.kuehne.cn/run/o/odd_bug_09_B.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFCVPeLK5blCcjpWoRAkZNAJ9u9KuG37L3O53M184/EXeNBd6ZCACgpzDE ZmrKofQvQyFVNcx/IzhvXy4= =nxYa -----END PGP SIGNATURE-----
Sep 14 2006