www.digitalmars.com         C & C++   DMDScript  

D.gnu - Question about pragma mangle

I just ran the test suite with an x86/ARM cross-compiler and it looks
like we have no cross-compiler specific problems!

There's one interesting failing test case: in runnable/mangle.d:

//UTF-8 chars
__gshared pragma(mangle, "test_=D1=8D=D0=BB=D1=8C=D1=84=D0=B8=D0=B9=D1=81=
=D0=BA=D0=B8=D0=B5_=D0=BF=D0=B8=D1=81=D1=8C=D0=BC=D0=B5=D0=BD=D0=B0_9") uby=
te test9_1;
__gshared extern pragma(mangle, "test_=D1=8D=D0=BB=D1=8C=D1=84=D0=B8=D0=B9=
") ubyte

void test9()
	import std.stdio;
    test9_1 =3D 42;
    writefln("test9_1 =3D %s", test9_1);
    writefln("test9_1_e =3D %s", test9_1_e);
    assert(test9_1_e =3D=3D 42);

The assert fails with optimization enabled iff the writelns are
removed. I haven't verified this yet but I guess that gcc reorders the
read/write to the symbol(s) when optimization is enabled.

So: If we have symbols with the same mangled name, do we guarantee
that reordering won't happen? What would be the best way to rewrite
this test case so it doesn't rely on ordering or can't be reordered?

Placing the read/write into extra functions could work, but inlining
could cause problems...
Dec 21 2013