<p dir="ltr">There's not enough information in the commit message, the comments, or the test cases to know what's broken or fixed here. Why is forcing the block the correct solution here? What is it working around?</p>

<p dir="ltr">--eric</p>
<div class="gmail_quote">On Jan 3, 2014 3:41 PM, "Adrian Prantl" <<a href="mailto:aprantl@apple.com">aprantl@apple.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: adrian<br>
Date: Fri Jan  3 17:34:30 2014<br>
New Revision: 198461<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=198461&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=198461&view=rev</a><br>
Log:<br>
Debug info: Ensure that the last stop point in a function is still within<br>
the lexical block formed by the compound statement that is the function<br>
body.<br>
<br>
rdar://problem/15010825<br>
<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
    cfe/trunk/lib/CodeGen/CGDebugInfo.h<br>
    cfe/trunk/lib/CodeGen/CGStmt.cpp<br>
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
    cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
    cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp<br>
    cfe/trunk/test/CodeGenObjC/arc-linetable.m<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=198461&r1=198460&r2=198461&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=198461&r1=198460&r2=198461&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Jan  3 17:34:30 2014<br>
@@ -2537,7 +2537,8 @@ void CGDebugInfo::EmitFunctionStart(Glob<br>
 /// information in the source file. If the location is invalid, the<br>
 /// previous location will be reused.<br>
 void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc,<br>
-                               bool ForceColumnInfo) {<br>
+                               bool ForceColumnInfo,<br>
+                               llvm::MDNode *ForceScope) {<br>
   // Update our current location<br>
   setLocation(Loc);<br>
<br>
@@ -2556,7 +2557,7 @@ void CGDebugInfo::EmitLocation(CGBuilder<br>
   // Update last state.<br>
   PrevLoc = CurLoc;<br>
<br>
-  llvm::MDNode *Scope = LexicalBlockStack.back();<br>
+  llvm::MDNode *Scope = ForceScope ? ForceScope : &*LexicalBlockStack.back();<br>
   Builder.SetCurrentDebugLocation(llvm::DebugLoc::get<br>
                                   (getLineNumber(CurLoc),<br>
                                    getColumnNumber(CurLoc, ForceColumnInfo),<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=198461&r1=198460&r2=198461&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=198461&r1=198460&r2=198461&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Fri Jan  3 17:34:30 2014<br>
@@ -211,11 +211,17 @@ public:<br>
   /// getLocation - Return the current source location.<br>
   SourceLocation getLocation() const { return CurLoc; }<br>
<br>
+  /// getScope() - Return the current scope.<br>
+  llvm::MDNode *getScope() const { return LexicalBlockStack.back(); }<br>
+<br>
   /// EmitLocation - Emit metadata to indicate a change in line/column<br>
   /// information in the source file.<br>
   /// \param ForceColumnInfo  Assume DebugColumnInfo option is true.<br>
+  /// \param ForceScope       Force the location to be in a specific lexical<br>
+  ///                         scope rather than the top of LexicalBlockStack.<br>
   void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc,<br>
-                    bool ForceColumnInfo = false);<br>
+                    bool ForceColumnInfo = false,<br>
+                    llvm::MDNode *ForceScope = 0);<br>
<br>
   /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate<br>
   /// start of a new function.<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=198461&r1=198460&r2=198461&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=198461&r1=198460&r2=198461&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Fri Jan  3 17:34:30 2014<br>
@@ -37,7 +37,7 @@ void CodeGenFunction::EmitStopPoint(cons<br>
     Loc = S->getLocStart();<br>
     DI->EmitLocation(Builder, Loc);<br>
<br>
-    LastStopPoint = Loc;<br>
+    LastStopPoint = std::make_pair(Loc, DI->getScope());<br>
   }<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=198461&r1=198460&r2=198461&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=198461&r1=198460&r2=198461&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Jan  3 17:34:30 2014<br>
@@ -207,9 +207,10 @@ void CodeGenFunction::FinishFunction(Sou<br>
   // all will be fine.<br>
   if (CGDebugInfo *DI = getDebugInfo()) {<br>
     if (OnlySimpleReturnStmts)<br>
-      DI->EmitLocation(Builder, LastStopPoint);<br>
+      DI->EmitLocation(Builder, LastStopPoint.first,<br>
+                       false, LastStopPoint.second);<br>
     else<br>
-      DI->EmitLocation(Builder, EndLoc);<br>
+      DI->EmitLocation(Builder, EndLoc, false, LastStopPoint.second);<br>
   }<br>
<br>
   // Pop any cleanups that might have been associated with the<br>
@@ -226,7 +227,7 @@ void CodeGenFunction::FinishFunction(Sou<br>
<br>
     if (CGDebugInfo *DI = getDebugInfo())<br>
       if (OnlySimpleReturnStmts)<br>
-        DI->EmitLocation(Builder, EndLoc);<br>
+        DI->EmitLocation(Builder, EndLoc, false, LastStopPoint.second);<br>
   }<br>
<br>
   // Emit function epilog (to return).<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=198461&r1=198460&r2=198461&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=198461&r1=198460&r2=198461&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Jan  3 17:34:30 2014<br>
@@ -859,7 +859,7 @@ private:<br>
   unsigned NumSimpleReturnExprs;<br>
<br>
   /// The last regular (non-return) debug location (breakpoint) in the function.<br>
-  SourceLocation LastStopPoint;<br>
+  std::pair<SourceLocation, llvm::MDNode*> LastStopPoint;<br>
<br>
 public:<br>
   /// A scope within which we are constructing the fields of an object which<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp?rev=198461&r1=198460&r2=198461&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp?rev=198461&r1=198460&r2=198461&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp Fri Jan  3 17:34:30 2014<br>
@@ -46,12 +46,14 @@ void bar()<br>
 void baz()<br>
 {<br>
   if (!foo())<br>
-    // CHECK: {{.*}} = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null}<br>
+    // CHECK: ![[SCOPE1:.*]] = metadata !{{{.*}}, i32 [[@LINE-1]], {{.*}}} ; [ DW_TAG_lexical_block ]<br>
+    // CHECK: {{.*}} = metadata !{i32 [[@LINE+1]], i32 0, metadata ![[SCOPE1]], null}<br>
     return;<br>
<br>
   if (foo()) {<br>
     // no cleanup<br>
-    // CHECK: {{.*}} = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null}<br>
+    // CHECK: {{.*}} = metadata !{i32 [[@LINE+2]], i32 0, metadata ![[SCOPE2:.*]], null}<br>
+    // CHECK: ![[SCOPE2]] = metadata !{{{.*}}, i32 [[@LINE-3]], {{.*}}} ; [ DW_TAG_lexical_block ]<br>
     return;<br>
   }<br>
   // CHECK: ![[RETBAZ]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null}<br>
<br>
Modified: cfe/trunk/test/CodeGenObjC/arc-linetable.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-linetable.m?rev=198461&r1=198460&r2=198461&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-linetable.m?rev=198461&r1=198460&r2=198461&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/CodeGenObjC/arc-linetable.m (original)<br>
+++ cfe/trunk/test/CodeGenObjC/arc-linetable.m Fri Jan  3 17:34:30 2014<br>
@@ -47,8 +47,11 @@<br>
<br>
 @implementation AppDelegate : NSObject<br>
<br>
+// CHECK: ![[TESTNOSIDEEFFECT:.*]] = {{.*}}[ DW_TAG_subprogram ] [line [[@LINE+1]]] [local] [def] [-[AppDelegate testNoSideEffect:]]<br>
 - (int)testNoSideEffect:(NSString *)foo {<br>
-  // CHECK: ![[ARC1]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null}<br>
+  // CHECK: ![[COMPOUND_STMT:.*]] = metadata !{i32 786443, metadata !{{.*}}, metadata ![[TESTNOSIDEEFFECT]], i32 [[@LINE-1]], i32 0, i32 0} ; [ DW_TAG_lexical_block ]<br>
+  int x = 1;<br>
+  // CHECK: ![[ARC1]] = metadata !{i32 [[@LINE+1]], i32 0, metadata ![[COMPOUND_STMT]], null}<br>
   return 1; // Return expression<br>
   // CHECK: ![[RET1]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null}<br>
 }           // Cleanup + Ret<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>