<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Apr 28, 2014 at 6:08 PM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: adrian<br>
Date: Mon Apr 28 20:07:59 2014<br>
New Revision: 207480<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=207480&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=207480&view=rev</a><br>
Log:<br>
Debug info: Improve line table for functions with cleanups an early exit<br>
and no return expr at the end of the function.<br>
The "function has only simple returns" check in FinishFunction tests<br>
whether the number of simple return exprs equals the number of return<br>
exprs, but so far a fallthrough at the end of a function was not counted<br>
as a return, which would result in cleanup code being associated with the<br>
wrong source line.<br>
<br>
rdar://problem/16733984.<br>
<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
    cfe/trunk/test/CodeGenObjC/arc-linetable.m<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=207480&r1=207479&r2=207480&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=207480&r1=207479&r2=207480&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Apr 28 20:07:59 2014<br>
@@ -498,6 +498,22 @@ void CodeGenFunction::EmitOpenCLKernelMe<br>
   OpenCLKernelMetadata->addOperand(kernelMDNode);<br>
 }<br>
<br>
+/// Determine whether the function F ends with a return stmt.<br>
+static bool endsWithReturn(const Decl* F) {<br>
+  const Stmt *Body = nullptr;<br>
+  if (auto *FD = dyn_cast_or_null<FunctionDecl>(F))<br>
+    Body = FD->getBody();<br>
+  else if (auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(F))<br>
+    Body = OMD->getBody();<br>
+<br>
+  if (auto *CS = dyn_cast_or_null<CompoundStmt>(Body)) {<br>
+    auto LastStmt = CS->body_rbegin();<br>
+    if (LastStmt != CS->body_rend())<br>
+      return isa<ReturnStmt>(*LastStmt);<br>
+  }<br>
+  return false;<br>
+}<br>
+<br>
 void CodeGenFunction::StartFunction(GlobalDecl GD,<br>
                                     QualType RetTy,<br>
                                     llvm::Function *Fn,<br>
@@ -593,6 +609,10 @@ void CodeGenFunction::StartFunction(Glob<br>
   if (RetTy->isVoidType()) {<br>
     // Void type; nothing to return.<br>
     ReturnValue = 0;<br>
+<br>
+    // Count the implicit return.<br>
+    if (!endsWithReturn(D))<br>
+      ++NumReturnExprs;<br>
   } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect &&<br>
              !hasScalarEvaluationKind(CurFnInfo->getReturnType())) {<br>
     // Indirect aggregate return; emit returned value directly into sret slot.<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=207480&r1=207479&r2=207480&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-linetable.m?rev=207480&r1=207479&r2=207480&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/CodeGenObjC/arc-linetable.m (original)<br>
+++ cfe/trunk/test/CodeGenObjC/arc-linetable.m Mon Apr 28 20:07:59 2014<br>
@@ -32,6 +32,15 @@<br>
 // CHECK: @objc_msgSend{{.*}} !dbg ![[MSG7:[0-9]+]]<br>
 // CHECK: ret {{.*}} !dbg ![[RET7:[0-9]+]]<br>
<br>
+// CHECK: define {{.*}}testCleanupVoid<br>
+// CHECK: icmp ne {{.*}}!dbg ![[SKIP1:[0-9]+]]<br>
+// CHECK-NEXT: br {{.*}}, label %[[CLEANUP:.*]], label<br>
+// CHECK: [[CLEANUP]]:<br></blockquote><div><br></div><div>This will fail on any non-Asserts clang (where we don't emit label names in the IR). Please fix or revert!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+// CHECK-NEXT: !dbg ![[RET8:[0-9]+]]<br>
+// CHECK: @objc_storeStrong{{.*}}, !dbg ![[ARC8:[0-9]+]]<br>
+// CHECK: ret {{.*}} !dbg ![[RET8]]<br>
+<br>
+typedef signed char BOOL;<br>
<br>
 @interface NSObject<br>
 + (id)alloc;<br>
@@ -93,6 +102,22 @@<br>
   return 1;<br>
 }<br>
<br>
+- (void)testCleanupVoid:(BOOL)skip withDelegate: (AppDelegate *) delegate {<br>
+  static BOOL skip_all;<br>
+  // CHECK: ![[SKIP1]] = metadata !{i32 [[@LINE+1]], i32 0,<br>
+  if (!skip_all) {<br>
+    if (!skip) {<br>
+      return;<br>
+    }<br>
+    NSString *s = @"bar";<br>
+    if (!skip) {<br>
+      [delegate testVoid :s];<br>
+    }<br>
+  }<br>
+  // CHECK: ![[RET8]] = metadata !{i32 [[@LINE+2]], i32 0,<br>
+  // CHECK: ![[ARC8]] = metadata !{i32 [[@LINE+1]], i32 0,<br>
+}<br>
+<br>
<br>
 @end<br>
<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><br></div></div>