Hi dblaikie,

When generating the IR for branch-on-boolean the branch instruction gets a 
debug location that is inherited from the condition’s context. It may get the 
same location as the instructions that precede the condition. This can lead to 
poor stepping behavior when the condition spans multiple lines, e.g.

If (a
     &&
     b)
…
;

In gdb we step back to the if from b’s line before continuing on.

The patch proposes to attach the condition’s debug location to the branch 
instruction.

http://reviews.llvm.org/D8822

Files:
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGenCXX/debug-info-line.cpp

Index: lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1179,8 +1179,8 @@
   {
     ApplyDebugLocation DL(*this, Cond);
     CondV = EvaluateExprAsBool(Cond);
+    Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights);
   }
-  Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights);
 }
 
 /// ErrorUnsupported - Print out an error that codegen doesn't support the
Index: test/CodeGenCXX/debug-info-line.cpp
===================================================================
--- test/CodeGenCXX/debug-info-line.cpp
+++ test/CodeGenCXX/debug-info-line.cpp
@@ -216,7 +216,7 @@
 // CHECK-LABEL: define
 void f18(int a, int b) {
 // CHECK: icmp {{.*}}, !dbg [[DBG_F18_1:![0-9]*]]
-// CHECK: br {{.*}}, !dbg [[DBG_F18_2:![0-9]*]]
+// CHECK: br {{.*}}, !dbg [[DBG_F18_1]]
 #line 2000
   if (a  //
       && //
@@ -227,7 +227,7 @@
 // CHECK-LABEL: define
 void f19(int a, int b) {
 // CHECK: icmp {{.*}}, !dbg [[DBG_F19_1:![0-9]*]]
-// CHECK: br {{.*}}, !dbg [[DBG_F19_2:![0-9]*]]
+// CHECK: br {{.*}}, !dbg [[DBG_F19_1]]
 #line 2100
   if (a  //
       || //
@@ -316,9 +316,7 @@
 // CHECK: [[DBG_F16]] = !MDLocation(line: 1800,
 // CHECK: [[DBG_F17]] = !MDLocation(line: 1900,
 // CHECK: [[DBG_F18_1]] = !MDLocation(line: 2000,
-// CHECK: [[DBG_F18_2]] = !MDLocation(line: 2001,
 // CHECK: [[DBG_F19_1]] = !MDLocation(line: 2100,
-// CHECK: [[DBG_F19_2]] = !MDLocation(line: 2101,
 // CHECK: [[DBG_F20_1]] = !MDLocation(line: 2200,
 // CHECK: [[DBG_F23]] = !MDLocation(line: 2500,
 // CHECK: [[DBG_F24]] = !MDLocation(line: 2600,

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1179,8 +1179,8 @@
   {
     ApplyDebugLocation DL(*this, Cond);
     CondV = EvaluateExprAsBool(Cond);
+    Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights);
   }
-  Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights);
 }
 
 /// ErrorUnsupported - Print out an error that codegen doesn't support the
Index: test/CodeGenCXX/debug-info-line.cpp
===================================================================
--- test/CodeGenCXX/debug-info-line.cpp
+++ test/CodeGenCXX/debug-info-line.cpp
@@ -216,7 +216,7 @@
 // CHECK-LABEL: define
 void f18(int a, int b) {
 // CHECK: icmp {{.*}}, !dbg [[DBG_F18_1:![0-9]*]]
-// CHECK: br {{.*}}, !dbg [[DBG_F18_2:![0-9]*]]
+// CHECK: br {{.*}}, !dbg [[DBG_F18_1]]
 #line 2000
   if (a  //
       && //
@@ -227,7 +227,7 @@
 // CHECK-LABEL: define
 void f19(int a, int b) {
 // CHECK: icmp {{.*}}, !dbg [[DBG_F19_1:![0-9]*]]
-// CHECK: br {{.*}}, !dbg [[DBG_F19_2:![0-9]*]]
+// CHECK: br {{.*}}, !dbg [[DBG_F19_1]]
 #line 2100
   if (a  //
       || //
@@ -316,9 +316,7 @@
 // CHECK: [[DBG_F16]] = !MDLocation(line: 1800,
 // CHECK: [[DBG_F17]] = !MDLocation(line: 1900,
 // CHECK: [[DBG_F18_1]] = !MDLocation(line: 2000,
-// CHECK: [[DBG_F18_2]] = !MDLocation(line: 2001,
 // CHECK: [[DBG_F19_1]] = !MDLocation(line: 2100,
-// CHECK: [[DBG_F19_2]] = !MDLocation(line: 2101,
 // CHECK: [[DBG_F20_1]] = !MDLocation(line: 2200,
 // CHECK: [[DBG_F23]] = !MDLocation(line: 2500,
 // CHECK: [[DBG_F24]] = !MDLocation(line: 2600,
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to