[cfe-commits] r173593 - PR14566: Debug Info: avoid top level lexical blocks in functions

David Blaikie dblaikie at gmail.com
Sat Jan 26 14:16:26 PST 2013


Author: dblaikie
Date: Sat Jan 26 16:16:26 2013
New Revision: 173593

URL: http://llvm.org/viewvc/llvm-project?rev=173593&view=rev
Log:
PR14566: Debug Info: avoid top level lexical blocks in functions

One of the gotchas (see changes to CodeGenFunction) was due to the fix in
r139416 (for PR10829). This only worked previously because the top level
lexical block would set the location to the end of the function, the debug
location would be updated (as per r139416), the location would be set to
the end of the function again (but that would no-op, since it was the same
as the previous location), then the return instruction would be emitted using
the debug location.

Once the top level lexical block was no longer emitted, the end-of-function
location change was causing the debug loc to be updated, regressing that bug.

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/test/CodeGen/2010-02-16-DbgScopes.c
    cfe/trunk/test/CodeGen/2010-03-5-LexicalScope.c
    cfe/trunk/test/CodeGen/debug-info-line.c
    cfe/trunk/test/CodeGen/debug-info-scope.c
    cfe/trunk/test/CodeGenObjC/catch-lexical-block.m

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=173593&r1=173592&r2=173593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Sat Jan 26 16:16:26 2013
@@ -79,7 +79,7 @@ void CGDebugInfo::setLocation(SourceLoca
     llvm::MDNode *N = D;
     LexicalBlockStack.pop_back();
     LexicalBlockStack.push_back(N);
-  } else if (Scope.isLexicalBlock()) {
+  } else if (Scope.isLexicalBlock() || Scope.isSubprogram()) {
     llvm::DIDescriptor D
       = DBuilder.createLexicalBlockFile(Scope, getOrCreateFile(CurLoc));
     llvm::MDNode *N = D;

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=173593&r1=173592&r2=173593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sat Jan 26 16:16:26 2013
@@ -198,6 +198,12 @@ RValue CodeGenFunction::EmitCompoundStmt
   // Keep track of the current cleanup stack depth, including debug scopes.
   LexicalScope Scope(*this, S.getSourceRange());
 
+  return EmitCompoundStmtWithoutScope(S, GetLast, AggSlot);
+}
+
+RValue CodeGenFunction::EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast,
+                                         AggValueSlot AggSlot) {
+
   for (CompoundStmt::const_body_iterator I = S.body_begin(),
        E = S.body_end()-GetLast; I != E; ++I)
     EmitStmt(*I);

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=173593&r1=173592&r2=173593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sat Jan 26 16:16:26 2013
@@ -117,7 +117,7 @@ bool CodeGenFunction::hasAggregateLLVMTy
   llvm_unreachable("unknown type kind!");
 }
 
-void CodeGenFunction::EmitReturnBlock() {
+bool CodeGenFunction::EmitReturnBlock() {
   // For cleanliness, we try to avoid emitting the return block for
   // simple cases.
   llvm::BasicBlock *CurBB = Builder.GetInsertBlock();
@@ -132,7 +132,7 @@ void CodeGenFunction::EmitReturnBlock() 
       delete ReturnBlock.getBlock();
     } else
       EmitBlock(ReturnBlock.getBlock());
-    return;
+    return false;
   }
 
   // Otherwise, if the return block is the target of a single direct
@@ -148,7 +148,7 @@ void CodeGenFunction::EmitReturnBlock() 
       Builder.SetInsertPoint(BI->getParent());
       BI->eraseFromParent();
       delete ReturnBlock.getBlock();
-      return;
+      return true;
     }
   }
 
@@ -157,6 +157,7 @@ void CodeGenFunction::EmitReturnBlock() 
   // region.end for now.
 
   EmitBlock(ReturnBlock.getBlock());
+  return false;
 }
 
 static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB) {
@@ -178,14 +179,14 @@ void CodeGenFunction::FinishFunction(Sou
     PopCleanupBlocks(PrologueCleanupDepth);
 
   // Emit function epilog (to return).
-  EmitReturnBlock();
+  bool MoveEndLoc = EmitReturnBlock();
 
   if (ShouldInstrumentFunction())
     EmitFunctionInstrumentation("__cyg_profile_func_exit");
 
   // Emit debug descriptor for function end.
   if (CGDebugInfo *DI = getDebugInfo()) {
-    DI->setLocation(EndLoc);
+    if (!MoveEndLoc) DI->setLocation(EndLoc);
     DI->EmitFunctionEnd(Builder);
   }
 
@@ -486,7 +487,10 @@ void CodeGenFunction::StartFunction(Glob
 void CodeGenFunction::EmitFunctionBody(FunctionArgList &Args) {
   const FunctionDecl *FD = cast<FunctionDecl>(CurGD.getDecl());
   assert(FD->getBody());
-  EmitStmt(FD->getBody());
+  if (const CompoundStmt *S = dyn_cast<CompoundStmt>(FD->getBody()))
+    EmitCompoundStmtWithoutScope(*S);
+  else
+    EmitStmt(FD->getBody());
 }
 
 /// Tries to mark the given function nounwind based on the

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=173593&r1=173592&r2=173593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Jan 26 16:16:26 2013
@@ -1411,7 +1411,7 @@ public:
 
   /// EmitReturnBlock - Emit the unified return block, trying to avoid its
   /// emission when possible.
-  void EmitReturnBlock();
+  bool EmitReturnBlock();
 
   /// FinishFunction - Complete IR generation of the current function. It is
   /// legal to call this function even if there is no current insertion point.
@@ -2013,6 +2013,9 @@ public:
 
   RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
                           AggValueSlot AVS = AggValueSlot::ignored());
+  RValue EmitCompoundStmtWithoutScope(const CompoundStmt &S,
+                                      bool GetLast = false, AggValueSlot AVS =
+                                          AggValueSlot::ignored());
 
   /// EmitLabel - Emit the block for the given label. It is legal to call this
   /// function even if there is no current insertion point.

Modified: cfe/trunk/test/CodeGen/2010-02-16-DbgScopes.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2010-02-16-DbgScopes.c?rev=173593&r1=173592&r2=173593&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/2010-02-16-DbgScopes.c (original)
+++ cfe/trunk/test/CodeGen/2010-02-16-DbgScopes.c Sat Jan 26 16:16:26 2013
@@ -4,7 +4,6 @@
 // CHECK: DW_TAG_lexical_block
 // CHECK: DW_TAG_lexical_block
 // CHECK: DW_TAG_lexical_block
-// CHECK: DW_TAG_lexical_block
 
 extern int bar();
 extern void foobar();

Modified: cfe/trunk/test/CodeGen/2010-03-5-LexicalScope.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2010-03-5-LexicalScope.c?rev=173593&r1=173592&r2=173593&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/2010-03-5-LexicalScope.c (original)
+++ cfe/trunk/test/CodeGen/2010-03-5-LexicalScope.c Sat Jan 26 16:16:26 2013
@@ -1,7 +1,6 @@
 // RUN: %clang_cc1 -emit-llvm -O0 -g %s -o - | FileCheck %s
 // CHECK: DW_TAG_lexical_block
 // CHECK: DW_TAG_lexical_block
-// CHECK: DW_TAG_lexical_block
 int foo(int i) {
 	if (i) {
 		int j = 2;

Modified: cfe/trunk/test/CodeGen/debug-info-line.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-line.c?rev=173593&r1=173592&r2=173593&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-line.c (original)
+++ cfe/trunk/test/CodeGen/debug-info-line.c Sat Jan 26 16:16:26 2013
@@ -1,9 +1,8 @@
 // RUN: %clang -emit-llvm -S -g %s -o - | FileCheck %s
 
 // Radar 8396182
-// There is only one lexical block, but we need a DILexicalBlock and two
-// DILexicalBlockFile to correctly represent file info. This means we have
-// two lexical blocks shown as the latter is also tagged as a lexical block.
+// There are no lexical blocks, but we need two DILexicalBlockFiles to
+// correctly represent file info.
 
 int foo() {
   int i = 1;
@@ -16,7 +15,6 @@ int foo() {
 }
 
 // CHECK: DW_TAG_lexical_block
-// CHECK: DW_TAG_lexical_block
 // CHECK: !"m.h"
 // CHECK: DW_TAG_lexical_block
 // CHECK: !"m.c"

Modified: cfe/trunk/test/CodeGen/debug-info-scope.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-scope.c?rev=173593&r1=173592&r2=173593&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-scope.c (original)
+++ cfe/trunk/test/CodeGen/debug-info-scope.c Sat Jan 26 16:16:26 2013
@@ -4,10 +4,12 @@
 int main() {
 	int j = 0;
 	int k = 0;
-// CHECK: DW_TAG_auto_variable
+// CHECK: DW_TAG_auto_variable ] [i]
 // CHECK-NEXT: DW_TAG_lexical_block
 	for (int i = 0; i < 10; i++)
 		j++;
+// CHECK: DW_TAG_auto_variable ] [i]
+// CHECK-NEXT: DW_TAG_lexical_block
 	for (int i = 0; i < 10; i++)
 		k++;
 	return 0;

Modified: cfe/trunk/test/CodeGenObjC/catch-lexical-block.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/catch-lexical-block.m?rev=173593&r1=173592&r2=173593&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/catch-lexical-block.m (original)
+++ cfe/trunk/test/CodeGenObjC/catch-lexical-block.m Sat Jan 26 16:16:26 2013
@@ -7,10 +7,9 @@ void f0() {
   }
 }
 
-// We should have 4 lexical blocks here at the moment, including one
+// We should have 3 lexical blocks here at the moment, including one
 // for the catch block.
 // CHECK: lexical_block
 // CHECK: lexical_block
-// CHECK: lexical_block
 // CHECK: auto_variable
 // CHECK: lexical_block





More information about the cfe-commits mailing list