Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Debug information for type is lost with LTO at -O0 #28149

Open Quuxplusone opened 8 years ago

Quuxplusone commented 8 years ago
Bugzilla Link PR28149
Status NEW
Importance P normal
Reported by Wolfgang Pieb (Wolfgang_Pieb@playstation.sony.com)
Reported on 2016-06-15 17:12:35 -0700
Last modified on 2019-06-06 03:34:32 -0700
Version trunk
Hardware PC Windows NT
CC dblaikie@gmail.com, jeremy.morse.llvm@gmail.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
// 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;
}
Quuxplusone commented 8 years ago

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)

Quuxplusone commented 8 years ago
(In reply to comment #1)
> 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.
Quuxplusone commented 8 years ago

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.