From b9b5b2ce07cfddd64e7e2cd06353cc9f4a566ede Mon Sep 17 00:00:00 2001
From: Adrian Prantl <aprantl@apple.com>
Date: Tue, 7 Jan 2014 22:05:45 +0000
Subject: [PATCH] Revert "Debug info: Implement a cleaner version of r198461.
 For symmetry with"

This reverts commit 198699 so we can get a cleaner patch.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198713 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/CodeGen/CGDebugInfo.cpp                  | 5 +++--
 lib/CodeGen/CGDebugInfo.h                    | 6 +++++-
 lib/CodeGen/CGObjC.cpp                       | 3 +--
 lib/CodeGen/CGStmt.cpp                       | 2 +-
 lib/CodeGen/CodeGenFunction.cpp              | 7 ++++---
 lib/CodeGen/CodeGenFunction.h                | 2 +-
 test/CodeGenObjC/arc-linetable-autorelease.m | 9 +++++----
 test/CodeGenObjC/arc-linetable.m             | 3 ++-
 8 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index 2977ed22230..3138d82fb8b 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -2537,7 +2537,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType,
 /// information in the source file. If the location is invalid, the
 /// previous location will be reused.
 void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc,
-                               bool ForceColumnInfo) {
+                               bool ForceColumnInfo,
+                               llvm::MDNode *ForceScope) {
   // Update our current location
   setLocation(Loc);
 
@@ -2556,7 +2557,7 @@ void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc,
   // Update last state.
   PrevLoc = CurLoc;
 
-  llvm::MDNode *Scope = LexicalBlockStack.back();
+  llvm::MDNode *Scope = ForceScope ? ForceScope : &*LexicalBlockStack.back();
   Builder.SetCurrentDebugLocation(llvm::DebugLoc::get
                                   (getLineNumber(CurLoc),
                                    getColumnNumber(CurLoc, ForceColumnInfo),
diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h
index b38b9c338c9..ac31bdf3f58 100644
--- a/lib/CodeGen/CGDebugInfo.h
+++ b/lib/CodeGen/CGDebugInfo.h
@@ -211,13 +211,17 @@ public:
   /// getLocation - Return the current source location.
   SourceLocation getLocation() const { return CurLoc; }
 
+  /// getScope() - Return the current scope.
+  llvm::MDNode *getScope() const { return LexicalBlockStack.back(); }
+
   /// EmitLocation - Emit metadata to indicate a change in line/column
   /// information in the source file.
   /// \param ForceColumnInfo  Assume DebugColumnInfo option is true.
   /// \param ForceScope       Force the location to be in a specific lexical
   ///                         scope rather than the top of LexicalBlockStack.
   void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc,
-                    bool ForceColumnInfo = false);
+                    bool ForceColumnInfo = false,
+                    llvm::MDNode *ForceScope = 0);
 
   /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
   /// start of a new function.
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index aa990143ac2..058ce5686a3 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -506,8 +506,7 @@ static llvm::Value *emitARCRetainLoadOfScalar(CodeGenFunction &CGF,
 /// its pointer, name, and types registered in the class struture.
 void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) {
   StartObjCMethod(OMD, OMD->getClassInterface(), OMD->getLocStart());
-  assert(isa<CompoundStmt>(OMD->getBody()));
-  EmitCompoundStmtWithoutScope(*cast<CompoundStmt>(OMD->getBody()));
+  EmitStmt(OMD->getBody());
   FinishFunction(OMD->getBodyRBrace());
 }
 
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index b18ff09015a..50882c8536b 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -37,7 +37,7 @@ void CodeGenFunction::EmitStopPoint(const Stmt *S) {
     Loc = S->getLocStart();
     DI->EmitLocation(Builder, Loc);
 
-    LastStopPoint = Loc;
+    LastStopPoint = std::make_pair(Loc, DI->getScope());
   }
 }
 
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index 04c60f61f88..fb668e4a168 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -209,9 +209,10 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
   // all will be fine.
   if (CGDebugInfo *DI = getDebugInfo()) {
     if (OnlySimpleReturnStmts)
-      DI->EmitLocation(Builder, LastStopPoint, false);
+      DI->EmitLocation(Builder, LastStopPoint.first,
+                       false, LastStopPoint.second);
     else
-      DI->EmitLocation(Builder, EndLoc, false);
+      DI->EmitLocation(Builder, EndLoc, false, LastStopPoint.second);
   }
 
   // Pop any cleanups that might have been associated with the
@@ -228,7 +229,7 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
 
     if (CGDebugInfo *DI = getDebugInfo())
       if (OnlySimpleReturnStmts)
-        DI->EmitLocation(Builder, EndLoc, false);
+        DI->EmitLocation(Builder, EndLoc, false, LastStopPoint.second);
   }
 
   // Emit function epilog (to return).
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 37bbcf3f342..c11f2c91729 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -877,7 +877,7 @@ private:
   unsigned NumSimpleReturnExprs;
 
   /// The last regular (non-return) debug location (breakpoint) in the function.
-  SourceLocation LastStopPoint;
+  std::pair<SourceLocation, llvm::MDNode*> LastStopPoint;
 
 public:
   /// A scope within which we are constructing the fields of an object which
diff --git a/test/CodeGenObjC/arc-linetable-autorelease.m b/test/CodeGenObjC/arc-linetable-autorelease.m
index fa109154ce0..be05ec2fcd8 100644
--- a/test/CodeGenObjC/arc-linetable-autorelease.m
+++ b/test/CodeGenObjC/arc-linetable-autorelease.m
@@ -29,11 +29,12 @@ NSRect NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h);
   CGFloat pattern[2];
   // CHECK: define {{.*}}_createBezierPathWithWidth
   // CHECK: load {{.*}} %path, align {{.*}}, !dbg ![[RET:[0-9]+]]
-  // CHECK: call void @objc_storeStrong{{.*}} !dbg ![[ARC:[0-9]+]]
-  // CHECK: call {{.*}} @objc_autoreleaseReturnValue{{.*}} !dbg ![[ARC]]
-  // CHECK: ret {{.*}} !dbg ![[ARC]]
+  // CHECK: call void @objc_storeStrong{{.*}} !dbg ![[ARC1:[0-9]+]]
+  // CHECK: call {{.*}} @objc_autoreleaseReturnValue{{.*}} !dbg ![[ARC2:[0-9]+]]
+  // CHECK: ret {{.*}} !dbg ![[ARC2]]
   // CHECK: ![[RET]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null}
   return path;
-  // CHECK: ![[ARC]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null}
+  // CHECK: ![[ARC1]] = metadata !{i32 [[@LINE+2]], i32 0, metadata !{{.*}}, null}
+  // CHECK: ![[ARC2]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null}
 }
 @end
diff --git a/test/CodeGenObjC/arc-linetable.m b/test/CodeGenObjC/arc-linetable.m
index 7af02edc5b6..34b7d7640fa 100644
--- a/test/CodeGenObjC/arc-linetable.m
+++ b/test/CodeGenObjC/arc-linetable.m
@@ -49,8 +49,9 @@
 
 // CHECK: ![[TESTNOSIDEEFFECT:.*]] = {{.*}}[ DW_TAG_subprogram ] [line [[@LINE+1]]] [local] [def] [-[AppDelegate testNoSideEffect:]]
 - (int)testNoSideEffect:(NSString *)foo {
+  // CHECK: ![[COMPOUND_STMT:.*]] = metadata !{i32 786443, metadata !{{.*}}, metadata ![[TESTNOSIDEEFFECT]], i32 [[@LINE-1]], i32 0, i32 0} ; [ DW_TAG_lexical_block ]
   int x = 1;
-  // CHECK: ![[ARC1]] = metadata !{i32 [[@LINE+1]], i32 0, metadata ![[TESTNOSIDEEFFECT]], null}
+  // CHECK: ![[ARC1]] = metadata !{i32 [[@LINE+1]], i32 0, metadata ![[COMPOUND_STMT]], null}
   return 1; // Return expression
   // CHECK: ![[RET1]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null}
 }           // Cleanup + Ret
-- 
GitLab