r174206 - Fix exception handling line table problems introduced by r173593

David Blaikie dblaikie at gmail.com
Fri Feb 1 11:09:50 PST 2013


Author: dblaikie
Date: Fri Feb  1 13:09:49 2013
New Revision: 174206

URL: http://llvm.org/viewvc/llvm-project?rev=174206&view=rev
Log:
Fix exception handling line table problems introduced by r173593

r173593 made us a little too eager to associate all code at the end of a
function with the user-written 'return' line. This caused problems with
breakpoints as they'd be set in exception handling code preceeding the
actual non-exception return handling code, leading to the breakpoint never
being hit in non-exceptional execution.

This change restores the pre-r173593 exception handling line information where
the cleanup code is associated with the '}' not the return line.

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=174206&r1=174205&r2=174206&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Feb  1 13:09:49 2013
@@ -2205,7 +2205,9 @@ void CGDebugInfo::EmitLocation(CGBuilder
   if (CurLoc == PrevLoc ||
       SM.getExpansionLoc(CurLoc) == SM.getExpansionLoc(PrevLoc))
     // New Builder may not be in sync with CGDebugInfo.
-    if (!Builder.getCurrentDebugLocation().isUnknown())
+    if (!Builder.getCurrentDebugLocation().isUnknown() &&
+        Builder.getCurrentDebugLocation().getScope(CGM.getLLVMContext()) ==
+          LexicalBlockStack.back())
       return;
   
   // Update last state.

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=174206&r1=174205&r2=174206&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Feb  1 13:09:49 2013
@@ -117,7 +117,7 @@ bool CodeGenFunction::hasAggregateLLVMTy
   llvm_unreachable("unknown type kind!");
 }
 
-bool CodeGenFunction::EmitReturnBlock() {
+void CodeGenFunction::EmitReturnBlock() {
   // For cleanliness, we try to avoid emitting the return block for
   // simple cases.
   llvm::BasicBlock *CurBB = Builder.GetInsertBlock();
@@ -132,7 +132,7 @@ bool CodeGenFunction::EmitReturnBlock() 
       delete ReturnBlock.getBlock();
     } else
       EmitBlock(ReturnBlock.getBlock());
-    return false;
+    return;
   }
 
   // Otherwise, if the return block is the target of a single direct
@@ -144,11 +144,13 @@ bool CodeGenFunction::EmitReturnBlock() 
     if (BI && BI->isUnconditional() &&
         BI->getSuccessor(0) == ReturnBlock.getBlock()) {
       // Reset insertion point, including debug location, and delete the branch.
+      // this is really subtle & only works because the next change in location
+      // will hit the caching in CGDebugInfo::EmitLocation & not override this
       Builder.SetCurrentDebugLocation(BI->getDebugLoc());
       Builder.SetInsertPoint(BI->getParent());
       BI->eraseFromParent();
       delete ReturnBlock.getBlock();
-      return true;
+      return;
     }
   }
 
@@ -157,7 +159,6 @@ bool CodeGenFunction::EmitReturnBlock() 
   // region.end for now.
 
   EmitBlock(ReturnBlock.getBlock());
-  return false;
 }
 
 static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB) {
@@ -171,6 +172,9 @@ void CodeGenFunction::FinishFunction(Sou
   assert(BreakContinueStack.empty() &&
          "mismatched push/pop in break/continue stack!");
 
+  if (CGDebugInfo *DI = getDebugInfo())
+    DI->EmitLocation(Builder, EndLoc);
+
   // Pop any cleanups that might have been associated with the
   // parameters.  Do this in whatever block we're currently in; it's
   // important to do this before we enter the return block or return
@@ -179,14 +183,13 @@ void CodeGenFunction::FinishFunction(Sou
     PopCleanupBlocks(PrologueCleanupDepth);
 
   // Emit function epilog (to return).
-  bool MoveEndLoc = EmitReturnBlock();
+  EmitReturnBlock();
 
   if (ShouldInstrumentFunction())
     EmitFunctionInstrumentation("__cyg_profile_func_exit");
 
   // Emit debug descriptor for function end.
   if (CGDebugInfo *DI = getDebugInfo()) {
-    if (!MoveEndLoc) DI->setLocation(EndLoc);
     DI->EmitFunctionEnd(Builder);
   }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=174206&r1=174205&r2=174206&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Feb  1 13:09:49 2013
@@ -1413,7 +1413,7 @@ public:
 
   /// EmitReturnBlock - Emit the unified return block, trying to avoid its
   /// emission when possible.
-  bool EmitReturnBlock();
+  void EmitReturnBlock();
 
   /// FinishFunction - Complete IR generation of the current function. It is
   /// legal to call this function even if there is no current insertion point.

Modified: cfe/trunk/test/CodeGenCXX/debug-info-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-class.cpp?rev=174206&r1=174205&r2=174206&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-class.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-class.cpp Fri Feb  1 13:09:49 2013
@@ -1,21 +1,20 @@
 // RUN: %clang  -emit-llvm -g -S %s -o - | FileCheck %s
 struct foo;
-void func(foo *f) { // CHECK: DW_TAG_structure_type
+void func(foo *f) {
 }
 class bar;
-void func(bar *f) { // CHECK: DW_TAG_class_type
+void func(bar *f) {
 }
 union baz;
-void func(baz *f) { // CHECK: DW_TAG_union_type
+void func(baz *f) {
 }
-class B { // CHECK: DW_TAG_class_type
+class B {
 public:
   virtual ~B();
-// CHECK: metadata !"_vptr$B", {{.*}}, i32 64, metadata !{{.*}}} ; [ DW_TAG_member ]
 };
-struct A { // CHECK: DW_TAG_structure_type
+struct A {
   int one;
-  static const int HdrSize = 52; // CHECK: HdrSize
+  static const int HdrSize = 52;
   int two;
   A() {
     int x = 1;
@@ -23,7 +22,22 @@ struct A { // CHECK: DW_TAG_structure_ty
 };
 
 
-int main() {
-  A a;
+int main(int argc, char **argv) {
   B b;
+  if (argc) {
+    A a;
+  }
+  return 0;
 }
+
+// CHECK: unwind label %terminate.lpad, !dbg ![[EXCEPTLOC:.*]]
+// CHECK: store i32 0, i32* %retval, !dbg ![[RETLOC:.*]]
+// CHECK: DW_TAG_structure_type ] [foo]
+// CHECK: DW_TAG_class_type ] [bar]
+// CHECK: DW_TAG_union_type ] [baz]
+// CHECK: DW_TAG_structure_type ] [A]
+// CHECK: HdrSize
+// CHECK: DW_TAG_class_type ] [B]
+// CHECK: metadata !"_vptr$B", {{.*}}, i32 64, metadata !{{.*}}} ; [ DW_TAG_member ]
+// CHECK: ![[EXCEPTLOC]] = metadata !{i32 31,
+// CHECK: ![[RETLOC]] = metadata !{i32 30,





More information about the cfe-commits mailing list