diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1197,6 +1197,8 @@ QualType DstType, SourceLocation Loc, ScalarConversionOpts Opts) { + ApplyDebugLocation DL(CGF, Loc); + // All conversions involving fixed point types should be handled by the // EmitFixedPoint family functions. This is done to prevent bloating up this // function more, and although fixed point numbers are represented by @@ -4187,6 +4189,7 @@ // setting up the PHI node in the Cont Block for this. llvm::PHINode *PN = llvm::PHINode::Create(llvm::Type::getInt1Ty(VMContext), 2, "", ContBlock); + PN->setDebugLoc(Builder.getCurrentDebugLocation()); for (llvm::pred_iterator PI = pred_begin(ContBlock), PE = pred_end(ContBlock); PI != PE; ++PI) PN->addIncoming(llvm::ConstantInt::getFalse(VMContext), *PI); @@ -4209,12 +4212,6 @@ // Insert an entry into the phi node for the edge with the value of RHSCond. PN->addIncoming(RHSCond, RHSBlock); - // Artificial location to preserve the scope information - { - auto NL = ApplyDebugLocation::CreateArtificial(CGF); - PN->setDebugLoc(Builder.getCurrentDebugLocation()); - } - // ZExt result to int. return Builder.CreateZExtOrBitCast(PN, ResTy, "land.ext"); } @@ -4274,6 +4271,7 @@ // setting up the PHI node in the Cont Block for this. llvm::PHINode *PN = llvm::PHINode::Create(llvm::Type::getInt1Ty(VMContext), 2, "", ContBlock); + PN->setDebugLoc(Builder.getCurrentDebugLocation()); for (llvm::pred_iterator PI = pred_begin(ContBlock), PE = pred_end(ContBlock); PI != PE; ++PI) PN->addIncoming(llvm::ConstantInt::getTrue(VMContext), *PI); @@ -4290,9 +4288,13 @@ // Reaquire the RHS block, as there may be subblocks inserted. RHSBlock = Builder.GetInsertBlock(); - // Emit an unconditional branch from this block to ContBlock. Insert an entry - // into the phi node for the edge with the value of RHSCond. - CGF.EmitBlock(ContBlock); + // Emit an unconditional branch from this block to ContBlock. + { + // There is no need to emit line number for unconditional branch. + auto NL = ApplyDebugLocation::CreateEmpty(CGF); + CGF.EmitBlock(ContBlock); + } + // Insert an entry into the phi node for the edge with the value of RHSCond. PN->addIncoming(RHSCond, RHSBlock); // ZExt result to int. diff --git a/clang/test/CodeGen/debug-info-inline-for.c b/clang/test/CodeGen/debug-info-inline-for.c deleted file mode 100644 --- a/clang/test/CodeGen/debug-info-inline-for.c +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s -// Check that clang emits Debug location in the phi instruction - -int func(int n) { - int a; - for(a = 10; a>0 && n++; a--); - return n; -} - -// CHECK: land.end: -// CHECK-NEXT: {{.*}} = phi i1 {{.*}} !dbg ![[DbgLoc:[0-9]+]] - -// CHECK: ![[DbgLoc]] = !DILocation(line: 0 diff --git a/clang/test/CodeGen/debug-info-land-lor.c b/clang/test/CodeGen/debug-info-land-lor.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/debug-info-land-lor.c @@ -0,0 +1,36 @@ +// Check that clang emits reasonable debug info for && and ||. +// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s +int f1(int a, int b) { + return a && b; // line 4 +} +int f2(int a, int b) { + return a || b; // line 7 +} + +// Each load/icmp pair should have the location of the operand. +// Each conditional branch/phi pair should have the location of the operator. + +// CHECK-LABEL: @f1 +// CHECK: load {{.*}} %a.addr, {{.*}} !dbg ![[F1A:[0-9]+]] +// CHECK-NEXT: icmp {{.*}} !dbg ![[F1A]] +// CHECK-NEXT: br {{.*}} !dbg ![[F1AND:[0-9]+]] +// CHECK: land.rhs: +// CHECK-NEXT: load {{.*}} %b.addr, {{.*}} !dbg ![[F1B:[0-9]+]] +// CHECK-NEXT: icmp {{.*}} !dbg ![[F1B]] +// CHECK: phi {{.*}} !dbg ![[F1AND]] + +// CHECK-LABEL: @f2 +// CHECK: load {{.*}} %a.addr, {{.*}} !dbg ![[F2A:[0-9]+]] +// CHECK-NEXT: icmp {{.*}} !dbg ![[F2A]] +// CHECK-NEXT: br {{.*}} !dbg ![[F2OR:[0-9]+]] +// CHECK: lor.rhs: +// CHECK-NEXT: load {{.*}} %b.addr, {{.*}} !dbg ![[F2B:[0-9]+]] +// CHECK-NEXT: icmp {{.*}} !dbg ![[F2B]] +// CHECK: phi {{.*}} !dbg ![[F2OR]] + +// CHECK-DAG: ![[F1A]] = !DILocation(line: 4, column: 10, +// CHECK-DAG: ![[F1B]] = !DILocation(line: 4, column: 15, +// CHECK-DAG: ![[F1AND]] = !DILocation(line: 4, column: 12, +// CHECK-DAG: ![[F2A]] = !DILocation(line: 7, column: 10, +// CHECK-DAG: ![[F2B]] = !DILocation(line: 7, column: 15, +// CHECK-DAG: ![[F2OR]] = !DILocation(line: 7, column: 12,