diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h --- a/llvm/include/llvm/IR/DIBuilder.h +++ b/llvm/include/llvm/IR/DIBuilder.h @@ -53,7 +53,7 @@ /// Track the RetainTypes, since they can be updated later on. SmallVector AllRetainTypes; SmallVector AllSubprograms; - SmallVector AllGVs; + SmallVector Globals; SmallVector ImportedModules; /// Map Macro parent (which can be DIMacroFile or nullptr) to a list of /// Metadata all of type DIMacroNode. @@ -64,8 +64,8 @@ SmallVector UnresolvedNodes; bool AllowUnresolvedNodes; - /// Each subprogram's preserved local variables, labels, imported entities, - /// and types. + /// Each subprogram's preserved local and static local variables, labels, + /// imported entities, and types. /// /// Do not use a std::vector. Some versions of libc++ apparently copy /// instead of move on grow operations, and TrackingMDRef is expensive to diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -1656,7 +1656,7 @@ unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit, DITemplateParameterArray TemplateParams, DISubprogram *Declaration, - DINodeArray RetainedNodes, DITypeArray ThrownTypes, + MDNodeArray RetainedNodes, DITypeArray ThrownTypes, DINodeArray Annotations, StringRef TargetFuncName, StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, Scope, getCanonicalMDString(Context, Name), @@ -1695,7 +1695,7 @@ DIType *ContainingType, unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit, DITemplateParameterArray TemplateParams = nullptr, - DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr, + DISubprogram *Declaration = nullptr, MDNodeArray RetainedNodes = nullptr, DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr, StringRef TargetFuncName = ""), (Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType, @@ -1817,7 +1817,7 @@ DISubprogram *getDeclaration() const { return cast_or_null(getRawDeclaration()); } - DINodeArray getRetainedNodes() const { + MDNodeArray getRetainedNodes() const { return cast_or_null(getRawRetainedNodes()); } DITypeArray getThrownTypes() const { @@ -1856,7 +1856,7 @@ void replaceRawLinkageName(MDString *LinkageName) { replaceOperandWith(3, LinkageName); } - void replaceRetainedNodes(DINodeArray N) { + void replaceRetainedNodes(MDNodeArray N) { replaceOperandWith(7, N.get()); } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1416,6 +1416,8 @@ DenseSet Processed; for (auto *GVE : CUNode->getGlobalVariables()) { DIGlobalVariable *GV = GVE->getVariable(); + assert(!isa_and_nonnull(GV->getScope()) && + "Unexpected function-local entity in 'globals' CU field."); if (Processed.insert(GV).second) CU->getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(GVMap[GV])); } @@ -1433,7 +1435,11 @@ CU->getOrCreateImportedEntityDIE(IE); else if (auto *Ty = dyn_cast(D)) CU->getOrCreateTypeDIE(Ty); - else + else if (auto *GVE = dyn_cast(D)) { + DIGlobalVariable *GV = GVE->getVariable(); + if (Processed.insert(GV).second) + CU->getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(GVMap[GV])); + } else llvm_unreachable("Unexpected local retained node!"); } @@ -1532,6 +1538,8 @@ S = IE->getScope(); else if (const auto *T = dyn_cast(N)) S = T->getScope(); + else if (const auto *GVE = dyn_cast(N)) + S = GVE->getVariable()->getScope(); else llvm_unreachable("Unexpected retained node!"); @@ -1984,16 +1992,17 @@ } // Collect info for retained nodes. - for (const DINode *DN : SP->getRetainedNodes()) { - const auto *LS = getRetainedNodeScope(DN); - if (isa(DN) || isa(DN)) { + for (const MDNode *N : SP->getRetainedNodes()) { + const auto *LS = getRetainedNodeScope(N); + if (isa(N) || isa(N)) { + const auto *DN = cast(N); if (!Processed.insert(InlinedEntity(DN, nullptr)).second) continue; LexicalScope *LexS = LScopes.findLexicalScope(LS); if (LexS) createConcreteEntity(TheCU, *LexS, DN, nullptr); } else { - LocalDeclsPerLS[LS].insert(DN); + LocalDeclsPerLS[LS].insert(N); } } } @@ -2313,12 +2322,13 @@ #endif for (LexicalScope *AScope : LScopes.getAbstractScopesList()) { const auto *SP = cast(AScope->getScopeNode()); - for (const DINode *DN : SP->getRetainedNodes()) { - const auto *LS = getRetainedNodeScope(DN); + for (const MDNode *N : SP->getRetainedNodes()) { + const auto *LS = getRetainedNodeScope(N); // Ensure LexicalScope is created for the scope of this node. auto *LexS = LScopes.getOrCreateAbstractScope(LS); assert(LexS && "Expected the LexicalScope to be created."); - if (isa(DN) || isa(DN)) { + if (isa(N) || isa(N)) { + const auto *DN = cast(N); // Collect info for variables/labels that were optimized out. if (!Processed.insert(InlinedEntity(DN, nullptr)).second || TheCU.getExistingAbstractEntity(DN)) @@ -2326,7 +2336,7 @@ TheCU.createAbstractEntity(DN, LexS); } else { // Remember the node if this is a local declarations. - LocalDeclsPerLS[LS].insert(DN); + LocalDeclsPerLS[LS].insert(N); } assert( LScopes.getAbstractScopesList().size() == NumAbstractSubprograms && diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -33,7 +33,7 @@ if (const auto &RTs = CUNode->getRetainedTypes()) AllRetainTypes.assign(RTs.begin(), RTs.end()); if (const auto &GVs = CUNode->getGlobalVariables()) - AllGVs.assign(GVs.begin(), GVs.end()); + Globals.assign(GVs.begin(), GVs.end()); if (const auto &IMs = CUNode->getImportedEntities()) ImportedModules.assign(IMs.begin(), IMs.end()); if (const auto &MNs = CUNode->getMacros()) @@ -90,8 +90,8 @@ if (auto *SP = dyn_cast(N)) finalizeSubprogram(SP); - if (!AllGVs.empty()) - CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs)); + if (!Globals.empty()) + CUNode->replaceGlobalVariables(MDTuple::get(VMContext, Globals)); if (!ImportedModules.empty()) CUNode->replaceImportedEntities(MDTuple::get( @@ -750,7 +750,10 @@ if (!Expr) Expr = createExpression(); auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr); - AllGVs.push_back(N); + if (isa_and_nonnull(Context)) + getSubprogramNodesTrackingVector(Context).emplace_back(N); + else + Globals.push_back(N); return N; } diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1382,9 +1382,10 @@ CheckDI(Node, "invalid retained nodes list", &N, RawNode); for (Metadata *Op : Node->operands()) { CheckDI(Op && (isa(Op) || isa(Op) || - isa(Op) || isa(Op)), + isa(Op) || isa(Op) || + isa(Op)), "invalid retained nodes, expected DILocalVariable, DILabel, " - "DIImportedEntity or DIType", + "DIImportedEntity, DIType or DIGlobalVariableExpression", &N, Node, Op); } } diff --git a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp --- a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp +++ b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp @@ -237,7 +237,7 @@ if (SP && SP->isDefinition()) { for (DIType *Ty: SP->getType()->getTypeArray()) CheckAnonRecordType(nullptr, Ty); - for (const DINode *DN : SP->getRetainedNodes()) { + for (const MDNode *DN : SP->getRetainedNodes()) { if (const auto *DV = dyn_cast(DN)) CheckAnonRecordType(nullptr, DV->getType()); } diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp --- a/llvm/lib/Target/BPF/BTFDebug.cpp +++ b/llvm/lib/Target/BPF/BTFDebug.cpp @@ -604,7 +604,7 @@ uint32_t FuncId = addType(std::move(FuncTypeEntry)); // Process argument annotations. - for (const DINode *DN : SP->getRetainedNodes()) { + for (const MDNode *DN : SP->getRetainedNodes()) { if (const auto *DV = dyn_cast(DN)) { uint32_t Arg = DV->getArg(); if (Arg) @@ -1198,7 +1198,7 @@ // Use RetainedNodes so we can collect all argument names // even if the argument is not used. std::unordered_map FuncArgNames; - for (const DINode *DN : SP->getRetainedNodes()) { + for (const MDNode *DN : SP->getRetainedNodes()) { if (const auto *DV = dyn_cast(DN)) { // Collect function arguments for subprogram func type. uint32_t Arg = DV->getArg(); diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -1055,6 +1055,7 @@ /*Decl=*/nullptr, /*TemplateParams=*/nullptr, /*AlignInBits=*/0, Annotations); CounterPtr->addDebugInfo(DICounter); + DB.finalizeSubprogram(SP); DB.finalize(); } else { std::string Msg = ("Missing debug info for function " + Fn->getName() + diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp --- a/llvm/lib/Transforms/Utils/Debugify.cpp +++ b/llvm/lib/Transforms/Utils/Debugify.cpp @@ -322,7 +322,7 @@ DebugInfoBeforePass.DIFunctions.insert({&F, SP}); if (SP) { LLVM_DEBUG(dbgs() << " Collecting subprogram: " << *SP << '\n'); - for (const DINode *DN : SP->getRetainedNodes()) { + for (const MDNode *DN : SP->getRetainedNodes()) { if (const auto *DV = dyn_cast(DN)) { DebugInfoBeforePass.DIVariables[DV] = 0; } @@ -565,7 +565,7 @@ if (SP) { LLVM_DEBUG(dbgs() << " Collecting subprogram: " << *SP << '\n'); - for (const DINode *DN : SP->getRetainedNodes()) { + for (const MDNode *DN : SP->getRetainedNodes()) { if (const auto *DV = dyn_cast(DN)) { DebugInfoAfterPass.DIVariables[DV] = 0; } diff --git a/llvm/test/CodeGen/AArch64/arm64-2011-03-17-AsmPrinterCrash.ll b/llvm/test/CodeGen/AArch64/arm64-2011-03-17-AsmPrinterCrash.ll --- a/llvm/test/CodeGen/AArch64/arm64-2011-03-17-AsmPrinterCrash.ll +++ b/llvm/test/CodeGen/AArch64/arm64-2011-03-17-AsmPrinterCrash.ll @@ -28,12 +28,12 @@ !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!9, !10} -!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !2) +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug) !1 = !DIFile(filename: "print.i", directory: "/Volumes/Ebi/echeng/radars/r9146594") !2 = !{!3} !3 = !DIGlobalVariableExpression(var: !4, expr: !DIExpression()) !4 = !DIGlobalVariable(name: "vsplive", scope: !5, file: !1, line: 617, type: !8, isLocal: true, isDefinition: true) -!5 = distinct !DISubprogram(name: "drt_vsprintf", scope: !1, file: !1, line: 616, type: !6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0) +!5 = distinct !DISubprogram(name: "drt_vsprintf", scope: !1, file: !1, line: 616, type: !6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2) !6 = !DISubroutineType(types: !7) !7 = !{!8} !8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) diff --git a/llvm/test/CodeGen/BPF/BTF/static-var-inited-sec.ll b/llvm/test/CodeGen/BPF/BTF/static-var-inited-sec.ll --- a/llvm/test/CodeGen/BPF/BTF/static-var-inited-sec.ll +++ b/llvm/test/CodeGen/BPF/BTF/static-var-inited-sec.ll @@ -101,14 +101,14 @@ !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !14, isLocal: true, isDefinition: true) -!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !29) !3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) !8 = !{} -!9 = !{!0, !10} +!9 = !{!10} !10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) !11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) !12 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !13) @@ -128,3 +128,4 @@ !26 = !{!"short", !22, i64 0} !27 = !DILocation(line: 4, column: 12, scope: !2) !28 = !DILocation(line: 4, column: 3, scope: !2) +!29 = !{!0} diff --git a/llvm/test/CodeGen/BPF/BTF/static-var-inited.ll b/llvm/test/CodeGen/BPF/BTF/static-var-inited.ll --- a/llvm/test/CodeGen/BPF/BTF/static-var-inited.ll +++ b/llvm/test/CodeGen/BPF/BTF/static-var-inited.ll @@ -101,14 +101,14 @@ !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !14, isLocal: true, isDefinition: true) -!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !29) !3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) !8 = !{} -!9 = !{!0, !10} +!9 = !{!10} !10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) !11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) !12 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !13) @@ -128,3 +128,4 @@ !26 = !{!"short", !22, i64 0} !27 = !DILocation(line: 4, column: 12, scope: !2) !28 = !DILocation(line: 4, column: 3, scope: !2) +!29 = !{!0} diff --git a/llvm/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll b/llvm/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll --- a/llvm/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll +++ b/llvm/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll @@ -107,14 +107,14 @@ !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !15, isLocal: true, isDefinition: true) -!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !31) !3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) !8 = !{} -!9 = !{!0, !10} +!9 = !{!10} !10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) !11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) !12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !13) @@ -136,3 +136,4 @@ !28 = !{!"short", !24, i64 0} !29 = !DILocation(line: 4, column: 12, scope: !2) !30 = !DILocation(line: 4, column: 3, scope: !2) +!31 = !{!0} diff --git a/llvm/test/CodeGen/BPF/BTF/static-var-readonly.ll b/llvm/test/CodeGen/BPF/BTF/static-var-readonly.ll --- a/llvm/test/CodeGen/BPF/BTF/static-var-readonly.ll +++ b/llvm/test/CodeGen/BPF/BTF/static-var-readonly.ll @@ -107,14 +107,14 @@ !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !15, isLocal: true, isDefinition: true) -!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !31) !3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) !8 = !{} -!9 = !{!0, !10} +!9 = !{!10} !10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) !11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) !12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !13) @@ -136,3 +136,4 @@ !28 = !{!"short", !24, i64 0} !29 = !DILocation(line: 4, column: 12, scope: !2) !30 = !DILocation(line: 4, column: 3, scope: !2) +!31 = !{!0} diff --git a/llvm/test/CodeGen/BPF/BTF/static-var-sec.ll b/llvm/test/CodeGen/BPF/BTF/static-var-sec.ll --- a/llvm/test/CodeGen/BPF/BTF/static-var-sec.ll +++ b/llvm/test/CodeGen/BPF/BTF/static-var-sec.ll @@ -101,14 +101,14 @@ !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !14, isLocal: true, isDefinition: true) -!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !29) !3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) !8 = !{} -!9 = !{!0, !10} +!9 = !{!10} !10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) !11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) !12 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !13) @@ -128,3 +128,4 @@ !26 = !{!"short", !22, i64 0} !27 = !DILocation(line: 4, column: 12, scope: !2) !28 = !DILocation(line: 4, column: 3, scope: !2) +!29 = !{!0} diff --git a/llvm/test/CodeGen/BPF/BTF/static-var.ll b/llvm/test/CodeGen/BPF/BTF/static-var.ll --- a/llvm/test/CodeGen/BPF/BTF/static-var.ll +++ b/llvm/test/CodeGen/BPF/BTF/static-var.ll @@ -101,14 +101,14 @@ !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !14, isLocal: true, isDefinition: true) -!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !29) !3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) !8 = !{} -!9 = !{!0, !10} +!9 = !{!10} !10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) !11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) !12 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !13) @@ -128,3 +128,4 @@ !26 = !{!"short", !22, i64 0} !27 = !DILocation(line: 4, column: 12, scope: !2) !28 = !DILocation(line: 4, column: 3, scope: !2) +!29 = !{!0} diff --git a/llvm/test/CodeGen/BPF/dwarfdump.ll b/llvm/test/CodeGen/BPF/dwarfdump.ll --- a/llvm/test/CodeGen/BPF/dwarfdump.ll +++ b/llvm/test/CodeGen/BPF/dwarfdump.ll @@ -37,10 +37,9 @@ !4 = !DISubroutineType(types: !5) !5 = !{!6, !6, !6} !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) -!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 4.0.0 (trunk 287518) (llvm/trunk 287520)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9) +!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 4.0.0 (trunk 287518) (llvm/trunk 287520)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8) !8 = !{} -!9 = !{!0} -!10 = !{!11, !12} +!10 = !{!0, !11, !12} !11 = !DILocalVariable(name: "myvar_a", arg: 1, scope: !2, file: !3, line: 1, type: !6) !12 = !DILocalVariable(name: "myvar_b", arg: 2, scope: !2, file: !3, line: 1, type: !6) !13 = !{i32 2, !"Dwarf Version", i32 4} diff --git a/llvm/test/CodeGen/PowerPC/pr24546.ll b/llvm/test/CodeGen/PowerPC/pr24546.ll --- a/llvm/test/CodeGen/PowerPC/pr24546.ll +++ b/llvm/test/CodeGen/PowerPC/pr24546.ll @@ -56,7 +56,7 @@ !llvm.module.flags = !{!29, !30} !llvm.ident = !{!31} -!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, globals: !23) +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3) !1 = !DIFile(filename: "testcase.i", directory: "/tmp/glibc.build") !2 = !{} !3 = !{!4} @@ -76,9 +76,8 @@ !18 = distinct !DISubprogram(name: "php_intpow10", scope: !1, file: !1, line: 1, type: !19, isLocal: true, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !21) !19 = !DISubroutineType(types: !20) !20 = !{!4, !9} -!21 = !{!22} +!21 = !{!22, !24} !22 = !DILocalVariable(name: "power", arg: 1, scope: !18, file: !1, line: 1, type: !9) -!23 = !{!24} !24 = !DIGlobalVariableExpression(var: !DIGlobalVariable(name: "powers", scope: !18, file: !1, line: 3, type: !25, isLocal: true, isDefinition: true), expr: !DIExpression()) !25 = !DICompositeType(tag: DW_TAG_array_type, baseType: !26, size: 1472, align: 64, elements: !27) !26 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !4) diff --git a/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll b/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll --- a/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll +++ b/llvm/test/CodeGen/X86/dbg-distringtype-uint.ll @@ -74,10 +74,9 @@ !5 = !DISubroutineType(types: !6) !6 = !{!7} !7 = !DIStringType(name: "CHARACTER_0", size: 64) -!8 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, producer: "Intel(R) Fortran 21.0-2745", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !9, globals: !10, splitDebugInlining: false, nameTableKind: None) +!8 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, producer: "Intel(R) Fortran 21.0-2745", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !9, splitDebugInlining: false, nameTableKind: None) !9 = !{} -!10 = !{!0} -!11 = !{!12, !14} +!11 = !{!0, !12, !14} !12 = !DILocalVariable(name: "esym", arg: 1, scope: !2, file: !3, line: 15, type: !13, flags: DIFlagArtificial) !13 = !DIStringType(name: "CHARACTER_1", size: 64) !14 = !DILocalVariable(name: "i", arg: 2, scope: !2, file: !3, line: 15, type: !15) diff --git a/llvm/test/DebugInfo/Generic/2009-11-05-DeadGlobalVariable.ll b/llvm/test/DebugInfo/Generic/2009-11-05-DeadGlobalVariable.ll --- a/llvm/test/DebugInfo/Generic/2009-11-05-DeadGlobalVariable.ll +++ b/llvm/test/DebugInfo/Generic/2009-11-05-DeadGlobalVariable.ll @@ -14,13 +14,13 @@ !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!10} -!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.0 (trunk 139632)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !3) +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.0 (trunk 139632)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2) !1 = !DIFile(filename: "fb.c", directory: "/private/tmp") !2 = !{} !3 = !{!4} !4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) !5 = !DIGlobalVariable(name: "bar", scope: !6, file: !1, line: 2, type: !9, isLocal: true, isDefinition: true) -!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: true, unit: !0) +!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: true, unit: !0, retainedNodes: !3) !7 = !DISubroutineType(types: !8) !8 = !{!9} !9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) diff --git a/llvm/test/DebugInfo/Generic/inlined-static-var.ll b/llvm/test/DebugInfo/Generic/inlined-static-var.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/Generic/inlined-static-var.ll @@ -0,0 +1,94 @@ +; RUN: %llc_dwarf -O0 -filetype=obj < %s | llvm-dwarfdump -debug-info - | FileCheck --implicit-check-not "{{DW_TAG|NULL}}" %s +; REQUIRES: object-emission + +; inline __attribute__((always_inline)) +; int removed() { static int A; return A++; } +; +; __attribute__((always_inline)) +; int not_removed() { static int B; return B++; } +; +; int foo() { return removed() + not_removed(); } + +; Ensure that global variables belong to the correct subprograms even if those +; subprograms are inlined. + +; CHECK: DW_TAG_compile_unit +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_abstract_origin {{.*}} "_Z11not_removedv" +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("removed") +; CHECK: DW_TAG_variable +; CHECK: DW_AT_name ("A") +; CHECK: NULL +; CHECK: DW_TAG_base_type +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("not_removed") +; CHECK: DW_TAG_variable +; CHECK: DW_AT_name ("B") +; CHECK: NULL +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("foo") +; CHECK: DW_TAG_inlined_subroutine +; CHECK: DW_TAG_inlined_subroutine +; CHECK: NULL +; CHECK: NULL + +@_ZZ11not_removedvE1A = internal global i32 0, align 4, !dbg !0 +@_ZZ7removedvE1A = linkonce_odr dso_local global i32 0, align 4, !dbg !10 + +define dso_local i32 @_Z11not_removedv() !dbg !2 { + %1 = load i32, i32* @_ZZ11not_removedvE1A, align 4, !dbg !24 + %2 = add nsw i32 %1, 1, !dbg !24 + store i32 %2, i32* @_ZZ11not_removedvE1A, align 4, !dbg !24 + ret i32 %1, !dbg !25 +} + +define dso_local i32 @_Z3foov() !dbg !26 { + %1 = load i32, i32* @_ZZ7removedvE1A, align 4, !dbg !27 + %2 = add nsw i32 %1, 1, !dbg !27 + store i32 %2, i32* @_ZZ7removedvE1A, align 4, !dbg !27 + %3 = load i32, i32* @_ZZ11not_removedvE1A, align 4, !dbg !29 + %4 = add nsw i32 %3, 1, !dbg !29 + store i32 %4, i32* @_ZZ11not_removedvE1A, align 4, !dbg !29 + %5 = add nsw i32 %1, %3, !dbg !31 + ret i32 %5, !dbg !32 +} + +!llvm.dbg.cu = !{!7} +!llvm.module.flags = !{!14, !15, !16, !17, !18, !19, !20, !21, !22} +!llvm.ident = !{!23} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "B", scope: !2, file: !3, line: 5, type: !6, isLocal: true, isDefinition: true) +!2 = distinct !DISubprogram(name: "not_removed", linkageName: "_Z11not_removedv", scope: !3, file: !3, line: 5, type: !4, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !9) +!3 = !DIFile(filename: "example.cpp", directory: "") +!4 = !DISubroutineType(types: !5) +!5 = !{!6} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !8, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) +!8 = !DIFile(filename: "example.cpp", directory: "") +!9 = !{!0} +!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) +!11 = distinct !DIGlobalVariable(name: "A", scope: !12, file: !3, line: 2, type: !6, isLocal: false, isDefinition: true) +!12 = distinct !DISubprogram(name: "removed", linkageName: "_Z7removedv", scope: !3, file: !3, line: 2, type: !4, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !33) +!13 = !{} +!14 = !{i32 7, !"Dwarf Version", i32 4} +!15 = !{i32 2, !"Debug Info Version", i32 3} +!16 = !{i32 1, !"wchar_size", i32 4} +!17 = !{i32 1, !"branch-target-enforcement", i32 0} +!18 = !{i32 1, !"sign-return-address", i32 0} +!19 = !{i32 1, !"sign-return-address-all", i32 0} +!20 = !{i32 1, !"sign-return-address-with-bkey", i32 0} +!21 = !{i32 7, !"uwtable", i32 1} +!22 = !{i32 7, !"frame-pointer", i32 1} +!23 = !{!"clang version 14.0.0"} +!24 = !DILocation(line: 5, column: 43, scope: !2) +!25 = !DILocation(line: 5, column: 35, scope: !2) +!26 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !3, file: !3, line: 7, type: !4, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !13) +!27 = !DILocation(line: 2, column: 39, scope: !12, inlinedAt: !28) +!28 = distinct !DILocation(line: 7, column: 20, scope: !26) +!29 = !DILocation(line: 5, column: 43, scope: !2, inlinedAt: !30) +!30 = distinct !DILocation(line: 7, column: 32, scope: !26) +!31 = !DILocation(line: 7, column: 30, scope: !26) +!32 = !DILocation(line: 7, column: 13, scope: !26) +!33 = !{!10} diff --git a/llvm/test/DebugInfo/Generic/lexical-block-static-var.ll b/llvm/test/DebugInfo/Generic/lexical-block-static-var.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/Generic/lexical-block-static-var.ll @@ -0,0 +1,146 @@ +; RUN: %llc_dwarf -O0 -filetype=obj < %s | llvm-dwarfdump -debug-info - | FileCheck --implicit-check-not "{{DW_TAG|NULL}}" %s +; REQUIRES: object-emission + +; inline __attribute__((always_inline)) +; int removed() { +; { +; static int A; +; return A++; +; } +; } +; +; __attribute__((always_inline)) +; int not_removed() { +; { +; static int B; +; return B++; +; } +; } +; +; int foo() { +; { +; static int C; +; return ++C + removed() + not_removed(); +; } +; } + +; CHECK: DW_TAG_compile_unit + +; Out-of-line definition of `not_removed()`. +; The empty lexical block is created to match abstract origin. +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_abstract_origin {{.*}} "_Z11not_removedv" +; CHECK: DW_TAG_lexical_block +; CHECK: NULL + +; Abstract definition of `removed()` +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("removed") +; CHECK: DW_AT_inline (DW_INL_inlined) +; CHECK: DW_TAG_lexical_block +; CHECK: DW_TAG_variable +; CHECK: DW_AT_name ("A") +; CHECK: DW_AT_location (DW_OP_addr 0x0) +; CHECK: NULL +; CHECK: NULL +; CHECK: DW_TAG_base_type + +; Abstract definition of `not_removed()` +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("not_removed") +; CHECK: DW_AT_inline (DW_INL_inlined) +; CHECK: DW_TAG_lexical_block +; CHECK: DW_TAG_variable +; CHECK: DW_AT_name ("B") +; CHECK: DW_AT_location (DW_OP_addr 0x0) +; CHECK: NULL +; CHECK: NULL + +; Definition of foo(). +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("foo") +; CHECK: DW_TAG_lexical_block +; CHECK: DW_TAG_inlined_subroutine +; CHECK: DW_TAG_lexical_block +; CHECK: NULL +; CHECK: DW_TAG_inlined_subroutine +; CHECK: DW_TAG_lexical_block +; CHECK: NULL +; CHECK: DW_TAG_variable +; CHECK: DW_AT_name ("C") +; CHECK: DW_AT_location (DW_OP_addr 0x0) +; CHECK: NULL +; CHECK: NULL +; CHECK: NULL + +target triple = "x86_64-unknown-linux-gnu" + +@_ZZ11not_removedvE1B = internal global i32 0, align 4, !dbg !0 +@_ZZ3foovE1C = internal global i32 0, align 4, !dbg !10 +@_ZZ7removedvE1A = linkonce_odr dso_local global i32 0, align 4, !dbg !15 + +define dso_local i32 @_Z11not_removedv() !dbg !4 { +entry: + %0 = load i32, i32* @_ZZ11not_removedvE1B, align 4, !dbg !25 + %inc = add nsw i32 %0, 1, !dbg !25 + store i32 %inc, i32* @_ZZ11not_removedvE1B, align 4, !dbg !25 + ret i32 %0, !dbg !26 +} + +define dso_local i32 @_Z3foov() !dbg !13 { +entry: + %0 = load i32, i32* @_ZZ3foovE1C, align 4, !dbg !27 + %inc = add nsw i32 %0, 1, !dbg !27 + store i32 %inc, i32* @_ZZ3foovE1C, align 4, !dbg !27 + %1 = load i32, i32* @_ZZ7removedvE1A, align 4, !dbg !28 + %inc.i3 = add nsw i32 %1, 1, !dbg !28 + store i32 %inc.i3, i32* @_ZZ7removedvE1A, align 4, !dbg !28 + %add = add nsw i32 %inc, %1, !dbg !30 + %2 = load i32, i32* @_ZZ11not_removedvE1B, align 4, !dbg !31 + %inc.i = add nsw i32 %2, 1, !dbg !31 + store i32 %inc.i, i32* @_ZZ11not_removedvE1B, align 4, !dbg !31 + %add2 = add nsw i32 %add, %2, !dbg !33 + ret i32 %add2, !dbg !34 +} + +!llvm.dbg.cu = !{!8} +!llvm.module.flags = !{!19, !20, !21, !22, !23} +!llvm.ident = !{!24} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "B", scope: !2, file: !3, line: 13, type: !7, isLocal: true, isDefinition: true) +!2 = distinct !DILexicalBlock(scope: !4, file: !3, line: 12, column: 3) +!3 = !DIFile(filename: "test_static.cpp", directory: "/") +!4 = distinct !DISubprogram(name: "not_removed", linkageName: "_Z11not_removedv", scope: !3, file: !3, line: 11, type: !5, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !8, retainedNodes: !35) +!5 = !DISubroutineType(types: !6) +!6 = !{!7} +!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!8 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) +!9 = !{!15} +!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) +!11 = distinct !DIGlobalVariable(name: "C", scope: !12, file: !3, line: 20, type: !7, isLocal: true, isDefinition: true) +!12 = distinct !DILexicalBlock(scope: !13, file: !3, line: 19, column: 3) +!13 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !3, file: !3, line: 18, type: !5, scopeLine: 18, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !8, retainedNodes: !36) +!14 = !{} +!15 = !DIGlobalVariableExpression(var: !16, expr: !DIExpression()) +!16 = distinct !DIGlobalVariable(name: "A", scope: !17, file: !3, line: 5, type: !7, isLocal: false, isDefinition: true) +!17 = distinct !DILexicalBlock(scope: !18, file: !3, line: 4, column: 3) +!18 = distinct !DISubprogram(name: "removed", linkageName: "_Z7removedv", scope: !3, file: !3, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !8, retainedNodes: !9) +!19 = !{i32 7, !"Dwarf Version", i32 4} +!20 = !{i32 2, !"Debug Info Version", i32 3} +!21 = !{i32 1, !"wchar_size", i32 4} +!22 = !{i32 7, !"uwtable", i32 1} +!23 = !{i32 7, !"frame-pointer", i32 2} +!24 = !{!"clang version 14.0.0"} +!25 = !DILocation(line: 14, column: 13, scope: !2) +!26 = !DILocation(line: 14, column: 5, scope: !2) +!27 = !DILocation(line: 21, column: 12, scope: !12) +!28 = !DILocation(line: 6, column: 13, scope: !17, inlinedAt: !29) +!29 = distinct !DILocation(line: 21, column: 18, scope: !12) +!30 = !DILocation(line: 21, column: 16, scope: !12) +!31 = !DILocation(line: 14, column: 13, scope: !2, inlinedAt: !32) +!32 = distinct !DILocation(line: 21, column: 30, scope: !12) +!33 = !DILocation(line: 21, column: 28, scope: !12) +!34 = !DILocation(line: 21, column: 5, scope: !12) +!35 = !{!0} +!36 = !{!10} diff --git a/llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll b/llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll --- a/llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll +++ b/llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll @@ -38,7 +38,7 @@ define void @invalid_retained_nodes_list() !dbg !10 { ret void } !10 = distinct !DISubprogram(retainedNodes: !0) -; CHECK: invalid retained nodes, expected DILocalVariable, DILabel, DIImportedEntity or DIType +; CHECK: invalid retained nodes, expected DILocalVariable, DILabel, DIImportedEntity, DIType or DIGlobalVariableExpression define void @invalid_retained_nodes_expected() !dbg !11 { ret void } !11 = distinct !DISubprogram(retainedNodes: !{!0}) diff --git a/llvm/test/DebugInfo/X86/DW_AT_specification.ll b/llvm/test/DebugInfo/X86/DW_AT_specification.ll --- a/llvm/test/DebugInfo/X86/DW_AT_specification.ll +++ b/llvm/test/DebugInfo/X86/DW_AT_specification.ll @@ -23,13 +23,13 @@ !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 5, type: !14, isLocal: true, isDefinition: true) -!2 = distinct !DISubprogram(name: "bar", linkageName: "_ZN3foo3barEv", scope: null, file: !3, line: 4, type: !4, isLocal: false, isDefinition: true, scopeLine: 4, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !8, declaration: !11) +!2 = distinct !DISubprogram(name: "bar", linkageName: "_ZN3foo3barEv", scope: null, file: !3, line: 4, type: !4, isLocal: false, isDefinition: true, scopeLine: 4, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !8, declaration: !11, retainedNodes: !10) !3 = !DIFile(filename: "nsNativeAppSupportBase.ii", directory: "/Users/espindola/mozilla-central/obj-x86_64-apple-darwin11.2.0/toolkit/library") !4 = !DISubroutineType(types: !5) !5 = !{null, !6} !6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, align: 64, flags: DIFlagArtificial) !7 = !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !3, line: 1, flags: DIFlagFwdDecl) -!8 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.0 ()", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !9, retainedTypes: !9, globals: !10, imports: !9) +!8 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.0 ()", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !9, retainedTypes: !9, imports: !9) !9 = !{} !10 = !{!0} !11 = !DISubprogram(name: "bar", linkageName: "_ZN3foo3barEv", scope: !12, file: !3, line: 2, type: !4, isLocal: false, isDefinition: false, scopeLine: 2, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false) diff --git a/llvm/test/DebugInfo/X86/dimodule-external-fortran.ll b/llvm/test/DebugInfo/X86/dimodule-external-fortran.ll --- a/llvm/test/DebugInfo/X86/dimodule-external-fortran.ll +++ b/llvm/test/DebugInfo/X86/dimodule-external-fortran.ll @@ -73,13 +73,12 @@ !3 = !DIFile(filename: "em.f90", directory: "tests") !4 = !DISubroutineType(types: !5) !5 = !{null} -!6 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, producer: "Intel(R) Fortran 21.0-2165", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, globals: !8, splitDebugInlining: false, nameTableKind: None) +!6 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, producer: "Intel(R) Fortran 21.0-2165", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, splitDebugInlining: false, nameTableKind: None) !7 = !{} -!8 = !{!0} !9 = !{} !10 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !2, entity: !11, file: !3, line: 2) !11 = !DIModule(scope: !2, name: "external_module", isDecl: true) -!12 = !{!10, !13} +!12 = !{!0, !10, !13} !13 = !DILocalVariable(name: "x", scope: !2, file: !3, line: 5, type: !14) !14 = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float) !15 = !{i32 2, !"Debug Info Version", i32 3} diff --git a/llvm/test/DebugInfo/X86/distringtype.ll b/llvm/test/DebugInfo/X86/distringtype.ll --- a/llvm/test/DebugInfo/X86/distringtype.ll +++ b/llvm/test/DebugInfo/X86/distringtype.ll @@ -145,11 +145,11 @@ !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = distinct !DIGlobalVariable(name: "deferred", linkageName: "assumedlength_$DEFERRED", scope: !2, file: !3, line: 2, type: !9, isLocal: true, isDefinition: true) -!2 = distinct !DISubprogram(name: "assumedlength", linkageName: "MAIN__", scope: !3, file: !3, line: 1, type: !4, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !7) +!2 = distinct !DISubprogram(name: "assumedlength", linkageName: "MAIN__", scope: !3, file: !3, line: 1, type: !4, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !8) !3 = !DIFile(filename: "distring.f90", directory: "/iusers/cchen15/examples/tests") !4 = !DISubroutineType(types: !5) !5 = !{null} -!6 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, producer: "Intel(R) Fortran 21.0-2142", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, globals: !8, splitDebugInlining: false, nameTableKind: None) +!6 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, producer: "Intel(R) Fortran 21.0-2142", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, splitDebugInlining: false, nameTableKind: None) !7 = !{} !8 = !{!0} !9 = !DIStringType(name: ".str.DEFERRED", stringLengthExpression: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 8), stringLocationExpression: !DIExpression(DW_OP_push_object_address, DW_OP_deref)) diff --git a/llvm/test/DebugInfo/X86/gnu-public-names.ll b/llvm/test/DebugInfo/X86/gnu-public-names.ll --- a/llvm/test/DebugInfo/X86/gnu-public-names.ll +++ b/llvm/test/DebugInfo/X86/gnu-public-names.ll @@ -329,7 +329,7 @@ !14 = !{!15} !15 = !DIEnumerator(name: "named_enum_class_enumerator", value: 0) !16 = !{!13} -!17 = !{!0, !18, !29, !32, !37, !44, !47, !50} +!17 = !{!0, !18, !29, !32, !44, !47, !50} !18 = !DIGlobalVariableExpression(var: !19, expr: !DIExpression()) !19 = distinct !DIGlobalVariable(name: "global_variable", scope: !2, file: !3, line: 13, type: !20, isLocal: false, isDefinition: true) !20 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "C", file: !3, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !21, identifier: "_ZTS1C") @@ -351,7 +351,7 @@ !36 = !DIDerivedType(tag: DW_TAG_member, name: "A", scope: !34, file: !3, line: 22, baseType: !13, size: 32) !37 = !DIGlobalVariableExpression(var: !38, expr: !DIExpression()) !38 = distinct !DIGlobalVariable(name: "z", scope: !39, file: !3, line: 33, type: !13, isLocal: true, isDefinition: true) -!39 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !3, file: !3, line: 32, type: !40, scopeLine: 32, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !43) +!39 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !3, file: !3, line: 32, type: !40, scopeLine: 32, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !91) !40 = !DISubroutineType(types: !41) !41 = !{!42} !42 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64) @@ -403,3 +403,4 @@ !88 = !DILocation(line: 59, column: 68, scope: !78) !89 = !DILocation(line: 60, column: 32, scope: !78) !90 = !DILocation(line: 59, column: 3, scope: !78) +!91 = !{!37} diff --git a/llvm/test/DebugInfo/X86/namelist1.ll b/llvm/test/DebugInfo/X86/namelist1.ll --- a/llvm/test/DebugInfo/X86/namelist1.ll +++ b/llvm/test/DebugInfo/X86/namelist1.ll @@ -47,9 +47,9 @@ !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression(DW_OP_plus_uconst, 120)) !1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 3, type: !9, isLocal: true, isDefinition: true) -!2 = distinct !DISubprogram(name: "main", scope: !4, file: !3, line: 1, type: !7, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, unit: !4) +!2 = distinct !DISubprogram(name: "main", scope: !4, file: !3, line: 1, type: !7, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, unit: !4, retainedNodes: !6) !3 = !DIFile(filename: "namelist.f90", directory: "/dir") -!4 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: false, flags: "'+flang -g namelist.f90 -S -emit-llvm'", runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5, nameTableKind: None) +!4 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: false, flags: "'+flang -g namelist.f90 -S -emit-llvm'", runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, imports: !5, nameTableKind: None) !5 = !{} !6 = !{!0} !7 = !DISubroutineType(cc: DW_CC_program, types: !8) diff --git a/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll b/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll --- a/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll +++ b/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll @@ -20,7 +20,7 @@ define void @_Z3foov() !dbg !12 { call void @llvm.instrprof.increment(ptr @__profn_foo, i64 12345678, i32 2, i32 0) - ret void + ret void, !dbg !17 } declare void @llvm.instrprof.increment(ptr, i64, i32, i32) @@ -46,6 +46,7 @@ !14 = !DISubroutineType(types: !15) !15 = !{null} !16 = !{} +!17 = !DILocation(line: 1, scope: !12) ; CHECK-DWARF: DW_TAG_compile_unit ; CHECK-DWARF: DW_TAG_subprogram diff --git a/llvm/unittests/Transforms/Utils/CloningTest.cpp b/llvm/unittests/Transforms/Utils/CloningTest.cpp --- a/llvm/unittests/Transforms/Utils/CloningTest.cpp +++ b/llvm/unittests/Transforms/Utils/CloningTest.cpp @@ -1027,6 +1027,15 @@ EXPECT_EQ(SP->getName(), "f"); EXPECT_EQ(SP->getFile()->getFilename(), "filename.c"); EXPECT_EQ(SP->getLine(), (unsigned)4); + + // Check static locals. + MDNodeArray LocalDeclsArray = SP->getRetainedNodes(); + EXPECT_EQ(LocalDeclsArray.size(), 2U); + for (auto *Node : LocalDeclsArray) { + auto *GVExpr = cast(Node); + DIGlobalVariable *GV = GVExpr->getVariable(); + EXPECT_EQ(GV->getScope(), SP); + } } TEST_F(CloneModule, FunctionDeclarationMetadata) { @@ -1084,14 +1093,6 @@ DISubprogram *SP = NewM->getFunction("f")->getSubprogram(); EXPECT_TRUE(SP != nullptr); EXPECT_EQ(SP->getUnit(), CU); - - // Check globals listed in CU have the correct scope - DIGlobalVariableExpressionArray GlobalArray = CU->getGlobalVariables(); - EXPECT_EQ(GlobalArray.size(), 2U); - for (DIGlobalVariableExpression *GVExpr : GlobalArray) { - DIGlobalVariable *GV = GVExpr->getVariable(); - EXPECT_EQ(GV->getScope(), SP); - } } TEST_F(CloneModule, Comdat) {