Index: lib/Transforms/Utils/BasicBlockUtils.cpp =================================================================== --- lib/Transforms/Utils/BasicBlockUtils.cpp +++ lib/Transforms/Utils/BasicBlockUtils.cpp @@ -438,7 +438,7 @@ // The new block unconditionally branches to the old block. BranchInst *BI = BranchInst::Create(BB, NewBB); - BI->setDebugLoc(BB->getFirstNonPHI()->getDebugLoc()); + BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc()); // Move the edges from Preds to point to NewBB instead of BB. for (unsigned i = 0, e = Preds.size(); i != e; ++i) { Index: test/Transforms/LoopSimplify/dbg-loc.ll =================================================================== --- test/Transforms/LoopSimplify/dbg-loc.ll +++ test/Transforms/LoopSimplify/dbg-loc.ll @@ -1,44 +1,58 @@ ; Check that LoopSimplify creates debug locations in synthesized basic blocks. ; RUN: opt -loop-simplify %s -S -o - | FileCheck %s -%union.anon = type { i32 } -%"Length" = type <{ %union.anon, i8, i8, i8, i8 }> -declare void @bar(%"Length"*) #3 +%struct._node_t = type { %struct._node_t* } +@root = external local_unnamed_addr global %struct._node_t*, align 8 @catchtypeinfo = external unnamed_addr constant { i8*, i8*, i8* } +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) declare i32 @__gxx_personality_v0(...) declare void @f1() declare void @f2() declare void @f3() ; CHECK-LABEL: @foo -; CHECK: for.body.preheader: -; CHECK-NEXT: br label %for.body, !dbg [[PREHEADER_LOC:![0-9]+]] -; CHECK: for.end.loopexit: -; CHECK-NEXT: br label %for.end, !dbg [[LOOPEXIT_LOC:![0-9]+]] +; CHECK: while.cond.loopexit: +; CHECK-NEXT: br label %while.cond, !dbg [[DBG_LOC1:![0-9]+]] +; CHECK: while.cond2.preheader: +; CHECK-NEXT: br label %while.cond2, !dbg [[DBG_LOC2:![0-9]+]] -define linkonce_odr hidden void @foo(%"Length"* %begin, %"Length"* %end) nounwind ssp uwtable align 2 !dbg !6 { +define i32 @foo() local_unnamed_addr !dbg !6 { entry: - %cmp.4 = icmp eq %"Length"* %begin, %end, !dbg !7 - br i1 %cmp.4, label %for.end, label %for.body, !dbg !8 - -for.body: ; preds = %entry, %length.exit - %begin.sink5 = phi %"Length"* [ %incdec.ptr, %length.exit ], [ %begin, %entry ] - %m_type.i.i.i = getelementptr inbounds %"Length", %"Length"* %begin.sink5, i64 0, i32 2, !dbg !9 - %0 = load i8, i8* %m_type.i.i.i, align 1, !dbg !9 - %cmp.i.i = icmp eq i8 %0, 9, !dbg !7 - br i1 %cmp.i.i, label %if.then.i, label %length.exit, !dbg !8 - -if.then.i: ; preds = %for.body - tail call void @bar(%"Length"* %begin.sink5) #7, !dbg !10 - br label %length.exit, !dbg !10 - -length.exit: ; preds = %for.body, %if.then.i - %incdec.ptr = getelementptr inbounds %"Length", %"Length"* %begin.sink5, i64 1, !dbg !11 - %cmp = icmp eq %"Length"* %incdec.ptr, %end, !dbg !7 - br i1 %cmp, label %for.end, label %for.body, !dbg !8 - -for.end: ; preds = %length.exit, %entry - ret void, !dbg !12 + tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !19, metadata !20), !dbg !21 + %0 = load %struct._node_t*, %struct._node_t** @root, align 8, !dbg !22, !tbaa !23 + %next = getelementptr inbounds %struct._node_t, %struct._node_t* %0, i64 0, i32 0, !dbg !27 + %1 = load %struct._node_t*, %struct._node_t** %next, align 8, !dbg !27, !tbaa !28 + tail call void @llvm.dbg.value(metadata %struct._node_t* %1, i64 0, metadata !18, metadata !20), !dbg !30 + tail call void @llvm.dbg.value(metadata %struct._node_t* %1, i64 0, metadata !11, metadata !20), !dbg !31 + br label %while.cond, !dbg !32 + +while.cond: ; preds = %while.cond2, %entry + %node.0 = phi %struct._node_t* [ %1, %entry ], [ null, %while.cond2 ] + %ret.0 = phi i32 [ 0, %entry ], [ %ret.1, %while.cond2 ] + tail call void @llvm.dbg.value(metadata i32 %ret.0, i64 0, metadata !19, metadata !20), !dbg !21 + tail call void @llvm.dbg.value(metadata %struct._node_t* %node.0, i64 0, metadata !11, metadata !20), !dbg !31 + %cmp = icmp eq %struct._node_t* %node.0, %0, !dbg !33 + br i1 %cmp, label %while.end5, label %while.cond2, !dbg !35 + +while.cond2: ; preds = %while.cond, %while.body3 + %node.1 = phi %struct._node_t* [ %node.0, %while.cond ], [ %2, %while.body3 ] + %ret.1 = phi i32 [ %ret.0, %while.cond ], [ %inc, %while.body3 ] + tail call void @llvm.dbg.value(metadata i32 %ret.1, i64 0, metadata !19, metadata !20), !dbg !21 + tail call void @llvm.dbg.value(metadata %struct._node_t* %node.1, i64 0, metadata !11, metadata !20), !dbg !31 + %tobool = icmp eq %struct._node_t* %node.1, null, !dbg !36 + br i1 %tobool, label %while.cond, label %while.body3, !dbg !36, !llvm.loop !39 + +while.body3: ; preds = %while.cond2 + tail call void @llvm.dbg.value(metadata %struct._node_t* %node.1, i64 0, metadata !18, metadata !20), !dbg !30 + %next4 = getelementptr inbounds %struct._node_t, %struct._node_t* %node.1, i64 0, i32 0, !dbg !41 + %2 = load %struct._node_t*, %struct._node_t** %next4, align 8, !dbg !41, !tbaa !28 + tail call void @llvm.dbg.value(metadata %struct._node_t* %2, i64 0, metadata !11, metadata !20), !dbg !31 + %inc = add nsw i32 %ret.1, 1, !dbg !43 + tail call void @llvm.dbg.value(metadata i32 %inc, i64 0, metadata !19, metadata !20), !dbg !21 + br label %while.cond2, !dbg !44, !llvm.loop !46 + +while.end5: ; preds = %while.cond + ret i32 %ret.0, !dbg !49 } ; CHECK-LABEL: @with_landingpad @@ -49,47 +63,80 @@ define void @with_landingpad() uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { entry: - invoke void @f1() to label %try.cont19 unwind label %catch, !dbg !13 + invoke void @f1() to label %try.cont19 unwind label %catch, !dbg !50 catch: ; preds = %if.else, %entry %0 = landingpad { i8*, i32 } - catch i8* bitcast ({ i8*, i8*, i8* }* @catchtypeinfo to i8*), !dbg !13 - invoke void @f3() to label %if.else unwind label %eh.resume, !dbg !13 + catch i8* bitcast ({ i8*, i8*, i8* }* @catchtypeinfo to i8*), !dbg !50 + invoke void @f3() to label %if.else unwind label %eh.resume, !dbg !50 if.else: ; preds = %catch - invoke void @f2() to label %try.cont19 unwind label %catch, !dbg !13 + invoke void @f2() to label %try.cont19 unwind label %catch, !dbg !50 try.cont19: ; preds = %if.else, %entry - ret void, !dbg !13 + ret void, !dbg !50 eh.resume: ; preds = %catch %1 = landingpad { i8*, i32 } - cleanup catch i8* bitcast ({ i8*, i8*, i8* }* @catchtypeinfo to i8*), !dbg !13 - resume { i8*, i32 } undef, !dbg !13 + cleanup catch i8* bitcast ({ i8*, i8*, i8* }* @catchtypeinfo to i8*), !dbg !50 + resume { i8*, i32 } undef, !dbg !50 } -; CHECK-DAG: [[PREHEADER_LOC]] = !DILocation(line: 73, column: 27, scope: !{{[0-9]+}}) -; CHECK-DAG: [[LOOPEXIT_LOC]] = !DILocation(line: 75, column: 9, scope: !{{[0-9]+}}) +; CHECK-DAG: [[DBG_LOC1]] = !DILocation(line: 12, column: 15, scope: !{{[0-9]+}}) +; CHECK-DAG: [[DBG_LOC2]] = !DILocation(line: 13, column: 5, scope: !{{[0-9]+}}) ; CHECK-DAG: [[LPAD_PREHEADER_LOC]] = !DILocation(line: 85, column: 1, scope: !{{[0-9]+}}) -!llvm.module.flags = !{!0, !1, !2} -!llvm.dbg.cu = !{!14} -!0 = !{i32 2, !"Dwarf Version", i32 4} -!1 = !{i32 2, !"Debug Info Version", i32 3} -!2 = !{i32 1, !"PIC Level", i32 2} - -!3 = !{} -!4 = !DISubroutineType(types: !3) -!5 = !DIFile(filename: "Vector.h", directory: "/tmp") -!6 = distinct !DISubprogram(name: "destruct", scope: !5, file: !5, line: 71, type: !4, isLocal: false, isDefinition: true, scopeLine: 72, flags: DIFlagPrototyped, isOptimized: false, unit: !14, variables: !3) -!7 = !DILocation(line: 73, column: 38, scope: !6) -!8 = !DILocation(line: 73, column: 13, scope: !6) -!9 = !DILocation(line: 73, column: 27, scope: !6) -!10 = !DILocation(line: 74, column: 17, scope: !6) -!11 = !DILocation(line: 73, column: 46, scope: !6) -!12 = !DILocation(line: 75, column: 9, scope: !6) -!13 = !DILocation(line: 85, column: 1, scope: !6) -!14 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang", - file: !5, - isOptimized: true, flags: "-O2", - splitDebugFilename: "abc.debug", emissionKind: 2) +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug) +!1 = !DIFile(filename: "foo.c", directory: "b/") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{} +!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 7, type: !7, isLocal: false, isDefinition: true, scopeLine: 7, isOptimized: true, unit: !0, variables: !10) +!7 = !DISubroutineType(types: !8) +!8 = !{!9} +!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!10 = !{!11, !18, !19} +!11 = !DILocalVariable(name: "node", scope: !6, file: !1, line: 8, type: !12) +!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64) +!13 = !DIDerivedType(tag: DW_TAG_typedef, name: "node_t", file: !1, line: 3, baseType: !14) +!14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "_node_t", file: !1, line: 1, size: 64, elements: !15) +!15 = !{!16} +!16 = !DIDerivedType(tag: DW_TAG_member, name: "next", scope: !14, file: !1, line: 2, baseType: !17, size: 64) +!17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64) +!18 = !DILocalVariable(name: "tmp", scope: !6, file: !1, line: 8, type: !12) +!19 = !DILocalVariable(name: "ret", scope: !6, file: !1, line: 9, type: !9) +!20 = !DIExpression() +!21 = !DILocation(line: 9, column: 7, scope: !6) +!22 = !DILocation(line: 11, column: 16, scope: !6) +!23 = !{!24, !24, i64 0} +!24 = !{!"any pointer", !25, i64 0} +!25 = !{!"omnipotent char", !26, i64 0} +!26 = !{!"Simple C/C++ TBAA"} +!27 = !DILocation(line: 11, column: 22, scope: !6) +!28 = !{!29, !24, i64 0} +!29 = !{!"_node_t", !24, i64 0} +!30 = !DILocation(line: 8, column: 18, scope: !6) +!31 = !DILocation(line: 8, column: 11, scope: !6) +!32 = !DILocation(line: 12, column: 3, scope: !6) +!33 = !DILocation(line: 12, column: 15, scope: !34) +!34 = !DILexicalBlockFile(scope: !6, file: !1, discriminator: 1) +!35 = !DILocation(line: 12, column: 3, scope: !34) +!36 = !DILocation(line: 13, column: 5, scope: !37) +!37 = !DILexicalBlockFile(scope: !38, file: !1, discriminator: 1) +!38 = distinct !DILexicalBlock(scope: !6, file: !1, line: 12, column: 24) +!39 = distinct !{!39, !32, !40} +!40 = !DILocation(line: 18, column: 3, scope: !6) +!41 = !DILocation(line: 15, column: 20, scope: !42) +!42 = distinct !DILexicalBlock(scope: !38, file: !1, line: 13, column: 18) +!43 = !DILocation(line: 16, column: 10, scope: !42) +!44 = !DILocation(line: 13, column: 5, scope: !45) +!45 = !DILexicalBlockFile(scope: !38, file: !1, discriminator: 2) +!46 = distinct !{!46, !47, !48} +!47 = !DILocation(line: 13, column: 5, scope: !38) +!48 = !DILocation(line: 17, column: 5, scope: !38) +!49 = !DILocation(line: 20, column: 3, scope: !6) +!50 = !DILocation(line: 85, column: 1, scope: !6)