------------------------------ __gshared pragma(mangle, "test_эльфийские_письмена_9") int test9_1; __gshared extern pragma(mangle, "test_эльфийские_письмена_9") int test9_1_e; void main() { test9_1 = 42; assert(test9_1_e == 42); } ------------------------------ Compile with '-O2' Problem: GCC references test9_1 via section anchors, test9_1_e is always done via a linker relocation to test_эльфийские_письмена_9. The backend then doesn't realize that test9_1 and test9_1_e are actually the same variable and switches the order of the assignment and the assert. The same as a C example: ----------------------------- int test9_1 asm ("test_эльфийские_письмена_9"); extern int test9_1_e asm ("test_эльфийские_письмена_9"); int main() { test9_1 = 42; return test9_1_e == 42; } ----------------------------- Works as expected.
Problem #2: D main () { int D.2453; struct D.2452; int test_______________________________________9.0; int test_______________________________________9.0_1; int _2; } The DECL_NAME should really be the language name, not the DECL_ASSEMBLER_NAME.
(In reply to comment #1) > Problem #2: > > D main () > { > int D.2453; > struct D.2452; > int test_______________________________________9.0; > int test_______________________________________9.0_1; > int _2; > } > > > The DECL_NAME should really be the language name, not the DECL_ASSEMBLER_NAME. https://github.com/D-Programming-GDC/GDC/commit/79ebb4c0012485528cbf900b8bc8280423a872ff Now puts out: D main () { int D.2453; struct D.2452; int test.test9_1_e.0; int test.test9_1_e.0_1; int _2; /* ... */ } When fixing this, I found that d_comdat_group was calling DECL_ASSEMBLER_NAME before one had been set for var decls, oops. That is not good if the DECL_NAME has unfriendly symbols in it (eg: "quotes"). https://github.com/D-Programming-GDC/GDC/commit/64b4aa77a5d1e7254f783f9b835df216d85a3f0b However, the code logic in -fdump-tree-optimized-asmname is still not right: { <bb 2>: test_эльфийские_письмена_9 = 42; test.test9_1_e.0_1 = test_эльфийские_письмена_9; if (test.test9_1_e.0_1 == 42) } So finally: https://github.com/D-Programming-GDC/GDC/commit/942298f595e95cc60d75fa111645498420f6aa2e { <bb 2>: *test_эльфийские_письмена_9 = 42; test.test9_1_e.0_1 = *test_эльфийские_письмена_9; if (test.test9_1_e.0_1 == 42) } Fixed!
Great! I don't doubt those changes were necessary but I managed to reproduce the issue in C in the meantime so I guess you haven't actually tested these changes on ARM? I'm building a new compiler with your changes right now and I'll check if it really completely fixes the problem. I'll have to apologize on the GCC bugtracker then though cause I just filed a bug report about this some minutes ago.... Here's the C test case: ----------------------------------------------------- int test9_1 asm ("test_эльфийские_письмена_9") = 0; extern int test9_1_e asm ("test_эльфийские_письмена_9"); int main() { test9_1 = 42; return test9_1_e == 42; } ----------------------------------------------------- (note how test9_1 must be initialized for the bug to show up)
Unfortunately I can still reproduce this. Here's the URL to the GCC bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60214 We could close this as RESOLVED/NOTOURBUG but as people will probably see a failing test case because of this it's probably better to keep it open so it's easier to find this report.
Test case fixed in dmd and backported: https://github.com/D-Programming-GDC/GDC/commit/36d078bec94f43c0974057b09f1ca3cff909a2f2