gramanas updated this revision to Diff 150357.
gramanas added a comment.

Make more elaborate comment.


Repository:
  rC Clang

https://reviews.llvm.org/D47097

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGen/debug-info-preserve-scope.c


Index: test/CodeGen/debug-info-preserve-scope.c
===================================================================
--- /dev/null
+++ test/CodeGen/debug-info-preserve-scope.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -O1 -debug-info-kind=limited -emit-llvm -mllvm \
+// RUN: -opt-bisect-limit=2 -o - %s 2> /dev/null | FileCheck %s \
+// RUN: --check-prefix PHI
+
+extern int map[];
+// PHI-LABEL: define void @test1
+void test1(int a, int n) {
+  for (int i = 0; i < n; ++i)
+    a = map[a];
+}
+
+// PHI: for.cond:
+// PHI-NEXT: {{.*}} = phi i32 {{.*}} !dbg ![[test1DbgLoc:[0-9]+]]
+
+// PHI: ![[test1DbgLoc]] = !DILocation(line: 0
+
+
+static int i;
+// CHECK-LABEL: define void @test2
+void test2(int b) {
+  i = b;
+}
+
+// CHECK: store i32 {{.*}} !dbg ![[test2DbgLoc:[0-9]+]]
+
+// CHECK: ![[test2DbgLoc]] = !DILocation(line: 0
+
Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1946,6 +1946,10 @@
     }
   }
 
+  // Set artificial debug location to preserve the scope. This is later
+  // used by mem2reg to assign DL at the phi's it generates.
+  auto DL = ApplyDebugLocation::CreateArtificial(*this);
+
   Address DeclPtr = Address::invalid();
   bool DoStore = false;
   bool IsScalar = hasScalarEvaluationKind(Ty);


Index: test/CodeGen/debug-info-preserve-scope.c
===================================================================
--- /dev/null
+++ test/CodeGen/debug-info-preserve-scope.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -O1 -debug-info-kind=limited -emit-llvm -mllvm \
+// RUN: -opt-bisect-limit=2 -o - %s 2> /dev/null | FileCheck %s \
+// RUN: --check-prefix PHI
+
+extern int map[];
+// PHI-LABEL: define void @test1
+void test1(int a, int n) {
+  for (int i = 0; i < n; ++i)
+    a = map[a];
+}
+
+// PHI: for.cond:
+// PHI-NEXT: {{.*}} = phi i32 {{.*}} !dbg ![[test1DbgLoc:[0-9]+]]
+
+// PHI: ![[test1DbgLoc]] = !DILocation(line: 0
+
+
+static int i;
+// CHECK-LABEL: define void @test2
+void test2(int b) {
+  i = b;
+}
+
+// CHECK: store i32 {{.*}} !dbg ![[test2DbgLoc:[0-9]+]]
+
+// CHECK: ![[test2DbgLoc]] = !DILocation(line: 0
+
Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1946,6 +1946,10 @@
     }
   }
 
+  // Set artificial debug location to preserve the scope. This is later
+  // used by mem2reg to assign DL at the phi's it generates.
+  auto DL = ApplyDebugLocation::CreateArtificial(*this);
+
   Address DeclPtr = Address::invalid();
   bool DoStore = false;
   bool IsScalar = hasScalarEvaluationKind(Ty);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to