Author: rnk
Date: Fri Sep  9 11:27:04 2016
New Revision: 281053

URL: http://llvm.org/viewvc/llvm-project?rev=281053&view=rev
Log:
[codeview] Extend the heuristic for detecting classes imported from DLLs

If a dynamic class contains a dllimport method, then assume the class
may not be constructed in this DLL, and therefore the vtable will live
in a different PDB.

This heuristic is still incomplete, and will miss things like abstract
base classes that are only constructed on one side of the DLL interface.
That said, this heuristic does detect some cases that are currently
problematic, and may be useful to other projects that don't use many
DLLs.

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=281053&r1=281052&r2=281053&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Sep  9 11:27:04 2016
@@ -1707,6 +1707,16 @@ static bool isDefinedInClangModule(const
   return true;
 }
 
+/// Return true if the class or any of its methods are marked dllimport.
+static bool isClassOrMethodDLLImport(const CXXRecordDecl *RD) {
+  if (RD->hasAttr<DLLImportAttr>())
+    return true;
+  for (const CXXMethodDecl *MD : RD->methods())
+    if (MD->hasAttr<DLLImportAttr>())
+      return true;
+  return false;
+}
+
 static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
                                  bool DebugTypeExtRefs, const RecordDecl *RD,
                                  const LangOptions &LangOpts) {
@@ -1729,10 +1739,12 @@ static bool shouldOmitDefinition(codegen
 
   // 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.
+  // across DLL boundaries, so skip this optimization if the class or any of 
its
+  // methods are marked dllimport. This isn't a complete solution, since 
objects
+  // without any dllimport methods can be used in one DLL and constructed in
+  // another, but it is the current behavior of LimitedDebugInfo.
   if (CXXDecl->hasDefinition() && CXXDecl->isDynamicClass() &&
-      !CXXDecl->hasAttr<DLLImportAttr>())
+      !isClassOrMethodDLLImport(CXXDecl))
     return true;
 
   TemplateSpecializationKind Spec = TSK_Undeclared;

Modified: 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=281053&r1=281052&r2=281053&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-dllimport-base-class.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-dllimport-base-class.cpp Fri Sep  9 
11:27:04 2016
@@ -4,10 +4,23 @@
 // be imported from a DLL.  Otherwise, the debugger wouldn't be able to show 
the
 // members.
 
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "OutOfLineCtor",
+// CHECK-SAME:             DIFlagFwdDecl
+// CHECK-SAME:             ){{$}}
+
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ImportedBase",
 // CHECK-NOT:              DIFlagFwdDecl
 // CHECK-SAME:             ){{$}}
 
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ImportedMethod",
+// CHECK-NOT:              DIFlagFwdDecl
+// CHECK-SAME:             ){{$}}
+
+struct OutOfLineCtor {
+  OutOfLineCtor();
+  virtual void Foo();
+};
+
 struct __declspec(dllimport) ImportedBase {
   ImportedBase();
   virtual void Foo();
@@ -15,6 +28,14 @@ struct __declspec(dllimport) ImportedBas
 
 struct DerivedFromImported : public ImportedBase {};
 
+struct ImportedMethod {
+  ImportedMethod();
+  virtual void Foo();
+  static void __declspec(dllimport) create();
+};
+
 int main() {
+  OutOfLineCtor o;
   DerivedFromImported d;
+  ImportedMethod m;
 }


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

Reply via email to