Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -3427,6 +3427,11 @@ } // 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"); Index: test/CodeGen/debug-info-inline-for.c =================================================================== --- /dev/null +++ test/CodeGen/debug-info-inline-for.c @@ -0,0 +1,13 @@ +// 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