r184473 - Debug Info: Attempt to resolve forward declarations if we are not emitting

Adrian Prantl aprantl at apple.com
Thu Jun 20 14:17:25 PDT 2013


Author: adrian
Date: Thu Jun 20 16:17:24 2013
New Revision: 184473

URL: http://llvm.org/viewvc/llvm-project?rev=184473&view=rev
Log:
Debug Info: Attempt to resolve forward declarations if we are not emitting
limited debug info.

This is another small addendum to r184252.

rdar://problem/14101097

Added:
    cfe/trunk/test/CodeGen/debug-info-record2.c
      - copied, changed from r184442, cfe/trunk/test/CodeGen/debug-info-record.c
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/test/CodeGen/debug-info-record.c

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=184473&r1=184472&r2=184473&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Jun 20 16:17:24 2013
@@ -1886,6 +1886,22 @@ llvm::DIType CGDebugInfo::getTypeOrNull(
   return llvm::DIType();
 }
 
+/// ContainsFwdDecl - True if Ty is either a forward declaration or a
+/// derived type of a forward declaration.
+static bool ContainsFwdDecl(llvm::DIType Ty) {
+  // Composite types such as structs inherit from DIDerivedType, so
+  // check this first and do an early exit.
+  if (Ty.isForwardDecl())
+    return true;
+
+  if (Ty.isDerivedType()) {
+    llvm::DIDerivedType DTy(Ty);
+    return ContainsFwdDecl(DTy.getTypeDerivedFrom());
+  }
+
+  return false;
+}
+
 /// getCompletedTypeOrNull - Get the type from the cache or return null if it
 /// doesn't exist.
 llvm::DIType CGDebugInfo::getCompletedTypeOrNull(QualType Ty) {
@@ -1904,8 +1920,17 @@ llvm::DIType CGDebugInfo::getCompletedTy
   }
 
   // Verify that any cached debug info still exists.
-  if (V != 0)
-    return llvm::DIType(cast<llvm::MDNode>(V));
+  if (V != 0) {
+    llvm::DIType CachedType(cast<llvm::MDNode>(V));
+
+    // Unless we are limiting debug info, attempt to resolve any
+    // forward declarations.
+    if (DebugKind > CodeGenOptions::LimitedDebugInfo &&
+        ContainsFwdDecl(CachedType))
+      return llvm::DIType();
+
+    return CachedType;
+  }
 
   return llvm::DIType();
 }

Modified: cfe/trunk/test/CodeGen/debug-info-record.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-record.c?rev=184473&r1=184472&r2=184473&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-record.c (original)
+++ cfe/trunk/test/CodeGen/debug-info-record.c Thu Jun 20 16:17:24 2013
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-unk-unk -fno-limit-debug-info -o - -emit-llvm -g %s | FileCheck %s
-// Check that we emit debug info for a struct even if it is typedef'd before using.
+// Check that we emit debug info for a struct even if it is typedef'd.
 // rdar://problem/14101097
 //
 // FIXME: This should work with -flimit-debug-info, too.

Copied: cfe/trunk/test/CodeGen/debug-info-record2.c (from r184442, cfe/trunk/test/CodeGen/debug-info-record.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-record2.c?p2=cfe/trunk/test/CodeGen/debug-info-record2.c&p1=cfe/trunk/test/CodeGen/debug-info-record.c&r1=184442&r2=184473&rev=184473&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-record.c (original)
+++ cfe/trunk/test/CodeGen/debug-info-record2.c Thu Jun 20 16:17:24 2013
@@ -8,11 +8,12 @@
 // CHECK-NOT: [ DW_TAG_structure_type ] [elusive_s] {{.*}} [fwd]
 // CHECK: [ DW_TAG_member ] [foo]
 // CHECK: [ DW_TAG_member ] [bar]
+typedef struct elusive_s* elusive_t;
+elusive_t first_use = (void*)0;
 struct elusive_s {
   int foo;
   float bar;
 };
-typedef struct elusive_s* elusive_t;
 
 int baz(void* x) {
   elusive_t s = x;





More information about the cfe-commits mailing list