llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.17k stars 11.63k forks source link

[DebugInfo] Missing debug info for abstract classes with constexpr constructors with -flimited-debug-info #28622

Open rnk opened 8 years ago

rnk commented 8 years ago
Bugzilla Link 28248
Version unspecified
OS Windows NT
CC @dwblaikie

Extended Description

While working on https://llvm.org/bugs/show_bug.cgi?id=28150, I noticed that this C++ doesn't generate any debug info describing class 'A' in C++11:

struct A { virtual void f() = 0; }; struct B : A { virtual void f() {} }; B b;

On Windows, Clang defaults to C++11, so we don't get this debug info. I think the C++11 aspect has to do with A's default constructor being constexpr. Adding a user-defined ctor to A ensures that the debug info is emitted.

dwblaikie commented 8 years ago

Weird that we bother with a ctor in the other cases - though the static initialization is only /required/ in the global case... shrug

But, yes, this is a bug (across platforms, shows up on non-windows as well, when building with C++11). GCC gets this right, though I'm not sure exactly what rules it uses to do so. Perhaps they just rely on the ctor being inlined away, so they start off by generating all the assorted things, and thus emitting the debug info for the type.

Running some experiments. But I guess the most general way to fix this would be to wire the "requires vtable" stuff through the static initialization optimization codepath so it still triggers in a way that's sufficient to generate the debug info even though we never actually emit the ctor, vtable, etc.

rnk commented 8 years ago

I guess this only happens if you initialize B in a global, because then we initialize it statically. If you make a B on the stack or with 'new', then we emit B's ctor, which calls A's ctor, which references A's vtable, and we get class debug info.

Maybe this isn't that high priority then.