r225845 - DebugInfo: Correct the location of EH cleanup for blocks

David Blaikie dblaikie at gmail.com
Tue Jan 13 15:06:28 PST 2015


Author: dblaikie
Date: Tue Jan 13 17:06:27 2015
New Revision: 225845

URL: http://llvm.org/viewvc/llvm-project?rev=225845&view=rev
Log:
DebugInfo: Correct the location of EH cleanup for blocks

This was previously piggybacking on whatever happened to be the last
location set on CGDebugInfo/DIBuilder, which was wrong (it was often the
current location, such as the 'fn()' call site, not the end of the
block). With my improvements to set/unset the location in a scoped
manner (r225000) this went from a bad quality situation, to a crash.
Fixing this goes part-way to unblocking the recommit of r225000.

It's likely that any call to CodeGenFunction::StartFunction without the
CurEHLocation set represents a similar bug or risk of a bug. Perhaps
there are some callers that know they won't generate EH cleanups, but
I'm not sure.

I considered a generic catch-fix in StartFunction (just fallback to the
GlobalDecl's location) but that seemed like it'd mask bugs where the EH
location shouldn't be the same as the decl's location (& indeed by not
using that stop-gap I found this bug). We'll see how long I can hold out
on the generic catch-all. I might eventually be able to add an assertion
in.

Added:
    cfe/trunk/test/CodeGenObjCXX/debug-info-line.mm
Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=225845&r1=225844&r2=225845&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Tue Jan 13 17:06:27 2015
@@ -1107,6 +1107,8 @@ CodeGenFunction::GenerateBlockFunction(G
   const BlockDecl *blockDecl = blockInfo.getBlockDecl();
 
   CurGD = GD;
+
+  CurEHLocation = blockInfo.getBlockExpr()->getLocEnd();
   
   BlockInfo = &blockInfo;
 

Added: cfe/trunk/test/CodeGenObjCXX/debug-info-line.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/debug-info-line.mm?rev=225845&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/debug-info-line.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/debug-info-line.mm Tue Jan 13 17:06:27 2015
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -gline-tables-only -fblocks -emit-llvm %s -o - | FileCheck %s
+
+void fn();
+
+struct foo {
+  ~foo();
+};
+
+void func() {
+  ^{
+    foo f;
+    fn();
+    // CHECK: cleanup, !dbg [[LINE:![0-9]*]]
+    // CHECK: [[LINE]] = !{i32 [[@LINE+1]], 
+  }();
+}





More information about the cfe-commits mailing list