r187611 - DebugInfo: Don't prefer declarations over definitions in -flimit-debug-info in C

David Blaikie dblaikie at gmail.com
Thu Aug 1 13:57:40 PDT 2013


Author: dblaikie
Date: Thu Aug  1 15:57:40 2013
New Revision: 187611

URL: http://llvm.org/viewvc/llvm-project?rev=187611&view=rev
Log:
DebugInfo: Don't prefer declarations over definitions in -flimit-debug-info in C

Without an ODR, the -flimit-debug-info debug info size optimization of
emitting declarations for fully defined types when only a declaration is
needed by the TU, is incorrect. Emit the full definition whenever it's
available in non-C++.

Added:
    cfe/trunk/test/CodeGen/debug-info-limited.c
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/test/CodeGenCXX/debug-info-limited.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=187611&r1=187610&r2=187611&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Aug  1 15:57:40 2013
@@ -1422,7 +1422,7 @@ llvm::DIType CGDebugInfo::CreateType(con
   // Limited debug info should only remove struct definitions that can
   // safely be replaced by a forward declaration in the source code.
   if (DebugKind <= CodeGenOptions::LimitedDebugInfo && Declaration &&
-      !RD->isCompleteDefinitionRequired()) {
+      !RD->isCompleteDefinitionRequired() && CGM.getLangOpts().CPlusPlus) {
     // FIXME: This implementation is problematic; there are some test
     // cases where we violate the above principle, such as
     // test/CodeGen/debug-info-records.c .
@@ -1951,7 +1951,8 @@ llvm::DIType CGDebugInfo::getCompletedTy
 void CGDebugInfo::completeFwdDecl(const RecordDecl &RD) {
   // In limited debug info we only want to do this if the complete type was
   // required.
-  if (DebugKind <= CodeGenOptions::LimitedDebugInfo)
+  if (DebugKind <= CodeGenOptions::LimitedDebugInfo &&
+      CGM.getLangOpts().CPlusPlus)
     return;
 
   QualType QTy = CGM.getContext().getRecordType(&RD);

Added: cfe/trunk/test/CodeGen/debug-info-limited.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-limited.c?rev=187611&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-limited.c (added)
+++ cfe/trunk/test/CodeGen/debug-info-limited.c Thu Aug  1 15:57:40 2013
@@ -0,0 +1,11 @@
+// RUN: %clang -flimit-debug-info -emit-llvm -g -S %s -o - | FileCheck %s
+
+// Ensure we emit the full definition of 'foo' even though only its declaration
+// is needed, since C has no ODR to ensure that the definition will be the same
+// in whatever TU actually uses/requires the definition of 'foo'.
+// CHECK: ; [ DW_TAG_structure_type ] [foo] {{.*}} [def]
+
+struct foo {
+};
+
+struct foo *f;

Modified: cfe/trunk/test/CodeGenCXX/debug-info-limited.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-limited.cpp?rev=187611&r1=187610&r2=187611&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-limited.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-limited.cpp Thu Aug  1 15:57:40 2013
@@ -1,7 +1,6 @@
-// RUN: %clang  -emit-llvm -g -S %s -o - | FileCheck %s
+// RUN: %clang -flimit-debug-info -emit-llvm -g -S %s -o - | FileCheck %s
 
-// TAG_member is used to encode debug info for 'z' in A.
-// CHECK: TAG_member
+// CHECK: ; [ DW_TAG_class_type ] [A] {{.*}} [def]
 class A {
 public:
   int z;
@@ -13,8 +12,7 @@ A *foo (A* x) {
 }
 
 // Verify that we're not emitting a full definition of B in limit debug mode.
-// RUN: %clang -emit-llvm -g -flimit-debug-info -S %s -o - | FileCheck %s
-// CHECK-NOT: TAG_member
+// CHECK: ; [ DW_TAG_class_type ] [B] {{.*}} [decl]
 
 class B {
 public:





More information about the cfe-commits mailing list