Unexpected behavior of dmd -H switch

Sergey Gromov snake.scaly at gmail.com
Sat Aug 23 16:19:52 PDT 2008


I'm getting strange results when using -H switch with DMD 2.018.  
Consider an example:

---- begin test.d
uint foo(uint x) { return x & 0xE000_0000; }
---- end test.d

Nothing complex.  Now, compile it using "dmd -c -H test.d".  The 
resulting .di is:

---- begin test.di
// D import file generated from 'test.d'
uint foo(uint x)
{
return x & -536870912u;
}
---- end test.di

Things start getting funny.  A negative unsigned literal?  OK I'm going 
to test if this compiles.  The test file is:

---- begin test2.d
import test;
import std.stdio;
void main() { writeln(foo(0xb000_0000)); }
---- end test2.d

Compile it using "dmd test2.d" and get "Error 42: Symbol Undefined 
_D4test3fooFkZk".  But the .di contains the full function body.  Isn't 
it for inlining?  Well, the "dmd test2.d test.o" compiles fine and 
executable gives the correct answer.  So the compiler is OK with a 
negative unsigned literal...

I expect that:
1. the constant should be 3758096384u
2. there should be no need in test.obj, or there should be no body for 
foo()

Could anybody clarify this?

-- 
SnakE


More information about the Digitalmars-d-learn mailing list