May 21, 2005 -inline calling wrong virtual function! | ||||
|---|---|---|---|---|
| ||||
class BaseFoo
{
protected void stuff()
{
printf("BaseFoo.stuff()\n");
}
}
class DerivedFoo: BaseFoo
{
protected override void stuff()
{
printf("DerivedFoo.stuff()\n");
}
package final void baseStuff()
{
super.stuff();
}
}
int main()
{
DerivedFoo f;
f = new DerivedFoo;
f.stuff(); // Should print "DerivedFoo.stuff()".
f.baseStuff(); // Should print "BaseFoo.stuff()".
return 0;
}
Command "dmd test" shows this [correct] output:
DerivedFoo.stuff()
BaseFoo.stuff()
Command "dmd -inline test" shows this incorrect output:
DerivedFoo.stuff()
DerivedFoo.stuff()
A workaround is to insert some more code in baseStuff that won't get optimized away, such as
void delegate() foo = &stuff;
so that it won't get inlined.
| ||||
June 01, 2005 Re: -inline calling wrong virtual function! | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Vathix | -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Vathix schrieb am Sat, 21 May 2005 06:59:58 -0400: > class BaseFoo > { > protected void stuff() > { > printf("BaseFoo.stuff()\n"); > } > } > > class DerivedFoo: BaseFoo > { > protected override void stuff() > { > printf("DerivedFoo.stuff()\n"); > } > > package final void baseStuff() > { > super.stuff(); > } > } > > int main() > { > DerivedFoo f; > f = new DerivedFoo; > f.stuff(); // Should print "DerivedFoo.stuff()". > f.baseStuff(); // Should print "BaseFoo.stuff()". > return 0; > } > > > Command "dmd test" shows this [correct] output: > DerivedFoo.stuff() > BaseFoo.stuff() > > Command "dmd -inline test" shows this incorrect output: > DerivedFoo.stuff() > DerivedFoo.stuff() > > > A workaround is to insert some more code in baseStuff that won't get > optimized away, such as > void delegate() foo = &stuff; > so that it won't get inlined. Added to DStress as http://dstress.kuehne.cn/run/i/inline_10_A.d http://dstress.kuehne.cn/run/i/inline_10_B.d http://dstress.kuehne.cn/run/i/inline_10_C.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCnb+F3w+/yD4P9tIRAjoyAKCNCZ2K3TC+ryMz+rmw+OIS5KmpygCdEuFP HJEmjWeXuueLIa4J3jLyrK8= =XzVe -----END PGP SIGNATURE----- | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply