Debug information for type is lost with LTO at -O0
| Bugzilla Link | 28149 |
| Version | trunk |
| OS | Windows NT |
| CC | @dwblaikie,@jmorse,@pogo59 |
Extended Description
// After r267296 the following simple example fails to retain debug // information for the type 'MyStruct' in the final executable when // built with LTO. Building with -O2 behaves as expected.
// To build (on native Linux): // clang -std=c++11 -O0 -g -flto -c test.cpp // clang -flto -o test test.o
// 'llvm-dwarfdump test' shows no information for 'MyStruct'
attribute((noinline)) void use(int, int) { }
struct MyStruct { int w; int x; int y; int z;
int foo();
int bar();
};
int MyStruct::foo() { return 3; }
int main() { MyStruct str{1, 2, 3, 4}; use(str.x, str.y); return 0; }
Chances are the bug is that the variable gets lost - once it's optimized away, it's intentional/not surprising that the type goes away too.
In theory, at any optimization level, we should be emitting a list of variables attached to the subprogram and even those totally optimized away should be emitted - I'd suggest you look around that variable list handling to see where it's getting fouled up.
In what other ways does the DWARF differ?
Does MyStruct::foo still exist, or did it get optimized away? I imagine that's probably the thing that was holding on to MyStruct (I'm guessing the 'str' variable got optimized away? Though slightly surprised if we didn't preserve it even without any location)
The only thing that is left is the subprogram DIE for "main".
And 'str' got optimized away, but even when the 'use' gets changed to a 'printf' :
int main() { MyStruct str{1, 2, 3, 4}; printf("%d %d %p\n", str.x, str.y, (void *)&str); return 0; }
the same thing happens. And still, with -O2 everything for MyStruct is emitted.
In what other ways does the DWARF differ?
Does MyStruct::foo still exist, or did it get optimized away? I imagine that's probably the thing that was holding on to MyStruct (I'm guessing the 'str' variable got optimized away? Though slightly surprised if we didn't preserve it even without any location)
An old internal bug report lead me to this issue. @wolfy1961 and I discussed offline that this is caused by the fact variables are only added to retainedNodes lists in optimized builds, and overall that is fine, and it's not really an issue for LTO+O0 to have some weird edge cases.
Closing this with @wolfy1961's blessing.