diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -1624,10 +1624,9 @@ DebugLoc::replaceInlinedAtSubprogram(DL, *NewSP, Ctx, Cache)); // Loop info metadata may contain line locations. Fix them up. - auto updateLoopInfoLoc = [&Ctx, NewSP](Metadata *MD) -> Metadata * { + auto updateLoopInfoLoc = [&Ctx, &Cache, NewSP](Metadata *MD) -> Metadata * { if (auto *Loc = dyn_cast_or_null(MD)) - return DILocation::get(Ctx, Loc->getLine(), Loc->getColumn(), NewSP, - nullptr); + return DebugLoc::replaceInlinedAtSubprogram(Loc, *NewSP, Ctx, Cache); return MD; }; updateLoopMetadataDebugLocations(I, updateLoopInfoLoc); diff --git a/llvm/test/Transforms/HotColdSplit/update-split-loop-metadata.ll b/llvm/test/Transforms/HotColdSplit/update-split-loop-metadata.ll --- a/llvm/test/Transforms/HotColdSplit/update-split-loop-metadata.ll +++ b/llvm/test/Transforms/HotColdSplit/update-split-loop-metadata.ll @@ -11,8 +11,10 @@ ; The scope for these debug locations should be @basic.cold.1, not @basic. ; CHECK: [[SCOPE:![0-9]+]] = distinct !DISubprogram(name: "basic.cold.1" -; CHECK: [[LOOP_MD]] = distinct !{[[LOOP_MD]], [[LINE:![0-9]+]], [[LINE]]} +; CHECK: [[LOOP_MD]] = distinct !{[[LOOP_MD]], [[LINE:![0-9]+]], [[LINE2:![0-9]+]]} ; CHECK: [[LINE]] = !DILocation(line: 1, column: 1, scope: [[SCOPE]]) +; CHECK: [[LINE2]] = !DILocation(line: 2, column: 2, scope: [[LEX_SCOPE:![0-9]+]]) +; CHECK: [[LEX_SCOPE]] = !DILexicalBlock(scope: [[SCOPE]], file: !{{[0-9]+}}, line: 3, column: 3) define void @basic(ptr %p, i32 %k) !dbg !6 { entry: @@ -55,4 +57,6 @@ !7 = !DISubroutineType(types: !2) !8 = !{} !9 = !DILocation(line: 1, column: 1, scope: !6) -!10 = distinct !{!10, !9, !9} +!10 = distinct !{!10, !9, !11} +!11 = !DILocation(line: 2, column: 2, scope: !12) +!12 = !DILexicalBlock(scope: !6, file: !1, line: 3, column: 3)