The icc 7.0 for linux seems to break code using function templates when compiled with optimization enabled. The following command line arguments are used for compiling:
-x c++ -Xa -align -Zp16 -w1 -c -D__null=0 -O3 -mp1 -rcd -tpp6 -axM -ip
The offending code is a bit too long to post it here completely, but the following code snipped may give an impression:
typedef unsigned short UWORD;
class Foo {
/* snip */
typedef UWORD (Foo::*MicroCode)(UWORD operand);
template
UWORD Cat(UWORD operand)
{
return (this->*step2)((this->*step1)(operand));
}
UWORD ImmediateUnit(UWORD)
{
return Ram->ReadByte(GlobalPC++);
}
template
UWORD OrToStatusUnit(UWORD)
{
return GlobalP |= mask;
}
template
UWORD LoadPCUnit(UWORD)
{
return GlobalPC + displacement;
}
UWORD PushUnit(UWORD operand)
{
Stack[UBYTE(GlobalS--)] = operand;
return operand;
}
/* snip */
void BuildInstructions(void);
void AddStep(MicroCode step);
};
Then, in the .cpp file, I take pointers to templated member functions:
void Foo::BuildInstructions(void)
{
/* snip */
AddStep(&CPU::Cat<&CPU::OrToStatusUnit,&CPU::PushU
nit>);
/* snip */
}
The code compiles file, but the resulting program is corrupt and executes the wrong functions,i.e. template arguments are resolved incorrectly. The code runs fine if compiled with GNU GCC 3.2.1, and it also runs fine if compiled without the optimizer. The same bug applies to the icc 6.0 compiler.
For a complete (but lengthy) source code, please contact me at thor@math.tu-berlin.de. Please post comments to this mail as well.
Best regards,
Thomas Richter
Optimizer breaks function templates
Пожалуйста, обратитесь к странице Уведомление об оптимизации для более подробной информации относительно производительности и оптимизации в программных продуктах компании Intel.


