Author: amccarth
Date: Tue Aug 16 17:11:18 2016
New Revision: 278861

URL: http://llvm.org/viewvc/llvm-project?rev=278861&view=rev
Log:
Emit debug info for dynamic classes if they are imported from a DLL.

With -debug-info-kind=limited, we omit debug info for dynamic classes that live 
in other TUs. This reduces duplicate type information. When statically linked, 
the type information comes together. But if your binary has a class derived 
from a base in a DLL, the base class info is not available to the debugger.

The decision is made in shouldOmitDefinition (CGDebugInfo.cpp). Per a 
suggestion from rnk, I've tweaked the decision so that we do include 
definitions for classes marked as DLL imports. This should be a relatively 
small number of classes, so we don't pay a large price for duplication of the 
type info, yet it should cover most cases on Windows.

Essentially this makes debug info for DLLs independent, but we still assume 
that all TUs within the same DLL will be consistently built with (or without) 
debug info and the debugger will be able to search across the debug info within 
that scope to resolve any declarations into definitions, etc.

Added:
    cfe/trunk/test/CodeGenCXX/debug-info-dllimport-base-class.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=278861&r1=278860&r2=278861&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Aug 16 17:11:18 2016
@@ -1685,7 +1685,12 @@ static bool shouldOmitDefinition(codegen
   if (!CXXDecl)
     return false;
 
-  if (CXXDecl->hasDefinition() && CXXDecl->isDynamicClass())
+  // Only emit complete debug info for a dynamic class when its vtable is
+  // emitted.  However, Microsoft debuggers don't resolve type information
+  // across DLL boundaries, so skip this optimization if the class is marked
+  // dllimport.
+  if (CXXDecl->hasDefinition() && CXXDecl->isDynamicClass() &&
+      !CXXDecl->hasAttr<DLLImportAttr>())
     return true;
 
   TemplateSpecializationKind Spec = TSK_Undeclared;

Added: cfe/trunk/test/CodeGenCXX/debug-info-dllimport-base-class.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-dllimport-base-class.cpp?rev=278861&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-dllimport-base-class.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/debug-info-dllimport-base-class.cpp Tue Aug 16 
17:11:18 2016
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple i386-pc-windows -emit-llvm -gcodeview 
-debug-info-kind=limited -fms-compatibility %s -x c++ -o - | FileCheck %s
+
+// Ensure we emit debug info for the full definition of base classes that will
+// be imported from a DLL.  Otherwise, the debugger wouldn't be able to show 
the
+// members.
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ImportedBase",
+// CHECK-NOT:              DIFlagFwdDecl
+// CHECK-SAME:             ){{$}}
+
+struct __declspec(dllimport) ImportedBase {
+  ImportedBase();
+  virtual void Foo();
+};
+
+struct DerivedFromImported : public ImportedBase {};
+
+int main() {
+  DerivedFromImported d;
+}


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to