Index: docs/SourceLevelDebugging.rst =================================================================== --- docs/SourceLevelDebugging.rst +++ docs/SourceLevelDebugging.rst @@ -406,23 +406,20 @@ !llvm.ident = !{!8} ;; Define the global variable itself - !0 = distinct !DIGlobalVariable(name: "MyGlobal", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true, align: 64) + !0 = !DIGlobalVariableExpression(var: !1) + !1 = distinct !DIGlobalVariable(name: "MyGlobal", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true, align: 64, unit: !2) ;; Define the compile unit. - !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, + !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 4.0.0 (http://llvm.org/git/clang.git ae4deadbea242e8ea517eef662c30443f75bd086) (http://llvm.org/git/llvm.git 818b4c1539df3e51dc7e62c89ead4abfd348827d)", - isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, - enums: !3, globals: !4) + isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug) ;; ;; Define the file ;; - !2 = !DIFile(filename: "/dev/stdin", + !3 = !DIFile(filename: "/dev/stdin", directory: "/Users/dexonsmith/data/llvm/debug-info") - ;; An empty array. - !3 = !{} - ;; The Array of Global Variables !4 = !{!0} @@ -447,6 +444,22 @@ alignment is considered default. This is used when producing DWARF output for DW_AT_alignment value. +Global variables occur in three forms in the debug info metadata: +1. *Variable definitions* are reachable via a !dbg attachment on a global that + points to a DIGlobalVariableExpression which typically points to a distinct + DIGlobalVariable (and an optional DIExpression) with a unit field pointing to + the variable's DICompileUnit. If the compile unit the global variable gets + emitted into doesn't matter (e.g., for linkonce_odr symbols), the + DIGlobalVariable may instead be unique (i.e., not distinct) and not have a + unit field. + +2. *Constant definitions* are reachable via the DICompileUnit's list of globals + which points to a DIGlobalVariableExpression with a DIGlobalVariable without + a unit field and a DIExpression describing a constant value. + +3. *Declarations* are DIGlobalVariables without a unit field that are only + reachable via a DIImportedEntity and have isDefinition set to false. + C/C++ function information -------------------------- Index: include/llvm/IR/DIBuilder.h =================================================================== --- include/llvm/IR/DIBuilder.h +++ include/llvm/IR/DIBuilder.h @@ -495,13 +495,16 @@ /// \param Expr The location of the global relative to the attached /// GlobalVariable. /// \param Decl Reference to the corresponding declaration. - /// \param AlignInBits Variable alignment(or 0 if no alignment attr was - /// specified) + /// \param AlignInBits Variable alignment (or 0 if no alignment attr was + /// specified). + /// \param Shared This will create a unique node that is not + /// associated with a specific \a DICompileUnit and is + /// intended to be used with linkonce_odr globals. DIGlobalVariableExpression *createGlobalVariableExpression( DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DIType *Ty, bool isLocalToUnit, DIExpression *Expr = nullptr, MDNode *Decl = nullptr, - uint32_t AlignInBits = 0); + uint32_t AlignInBits = 0, bool Shared = false); /// Identical to createGlobalVariable /// except that the resulting DbgNode is temporary and meant to be RAUWed. Index: include/llvm/IR/DebugInfoMetadata.h =================================================================== --- include/llvm/IR/DebugInfoMetadata.h +++ include/llvm/IR/DebugInfoMetadata.h @@ -2281,49 +2281,50 @@ IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {} ~DIGlobalVariable() = default; - static DIGlobalVariable *getImpl(LLVMContext &Context, DIScope *Scope, - StringRef Name, StringRef LinkageName, - DIFile *File, unsigned Line, DITypeRef Type, - bool IsLocalToUnit, bool IsDefinition, - DIDerivedType *StaticDataMemberDeclaration, - uint32_t AlignInBits, StorageType Storage, - bool ShouldCreate = true) { + static DIGlobalVariable * + getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name, + StringRef LinkageName, DIFile *File, unsigned Line, DITypeRef Type, + bool IsLocalToUnit, bool IsDefinition, + DIDerivedType *StaticDataMemberDeclaration, uint32_t AlignInBits, + DICompileUnit *Unit, StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, Scope, getCanonicalMDString(Context, Name), getCanonicalMDString(Context, LinkageName), File, Line, Type, IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration, - AlignInBits, Storage, ShouldCreate); + AlignInBits, Unit, Storage, ShouldCreate); } static DIGlobalVariable * getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition, Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits, - StorageType Storage, bool ShouldCreate = true); + Metadata *Unit, StorageType Storage, bool ShouldCreate = true); TempDIGlobalVariable cloneImpl() const { return getTemporary(getContext(), getScope(), getName(), getLinkageName(), getFile(), getLine(), getType(), isLocalToUnit(), isDefinition(), getStaticDataMemberDeclaration(), - getAlignInBits()); + getAlignInBits(), getUnit()); } public: DEFINE_MDNODE_GET(DIGlobalVariable, - (DIScope * Scope, StringRef Name, StringRef LinkageName, + (DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned Line, DITypeRef Type, bool IsLocalToUnit, bool IsDefinition, DIDerivedType *StaticDataMemberDeclaration, - uint32_t AlignInBits), + uint32_t AlignInBits, DICompileUnit *Unit), (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, - IsDefinition, StaticDataMemberDeclaration, AlignInBits)) + IsDefinition, StaticDataMemberDeclaration, AlignInBits, + Unit)) DEFINE_MDNODE_GET(DIGlobalVariable, - (Metadata * Scope, MDString *Name, MDString *LinkageName, + (Metadata *Scope, MDString *Name, MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition, Metadata *StaticDataMemberDeclaration, - uint32_t AlignInBits), + uint32_t AlignInBits, Metadata *Unit), (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, - IsDefinition, StaticDataMemberDeclaration, AlignInBits)) + IsDefinition, StaticDataMemberDeclaration, AlignInBits, + Unit)) TempDIGlobalVariable clone() const { return cloneImpl(); } @@ -2334,9 +2335,13 @@ DIDerivedType *getStaticDataMemberDeclaration() const { return cast_or_null(getRawStaticDataMemberDeclaration()); } + DICompileUnit *getUnit() const { + return cast_or_null(getRawUnit()); + } MDString *getRawLinkageName() const { return getOperandAs(5); } Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(6); } + Metadata *getRawUnit() const { return getOperand(7); } static bool classof(const Metadata *MD) { return MD->getMetadataID() == DIGlobalVariableKind; Index: lib/AsmParser/LLParser.cpp =================================================================== --- lib/AsmParser/LLParser.cpp +++ lib/AsmParser/LLParser.cpp @@ -4241,14 +4241,16 @@ OPTIONAL(isLocal, MDBoolField, ); \ OPTIONAL(isDefinition, MDBoolField, (true)); \ OPTIONAL(declaration, MDField, ); \ - OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); + OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ + OPTIONAL(unit, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS - Result = GET_OR_DISTINCT(DIGlobalVariable, - (Context, scope.Val, name.Val, linkageName.Val, - file.Val, line.Val, type.Val, isLocal.Val, - isDefinition.Val, declaration.Val, align.Val)); + Result = + GET_OR_DISTINCT(DIGlobalVariable, + (Context, scope.Val, name.Val, linkageName.Val, file.Val, + line.Val, type.Val, isLocal.Val, isDefinition.Val, + declaration.Val, align.Val, unit.Val)); return false; } Index: lib/Bitcode/Reader/MetadataLoader.cpp =================================================================== --- lib/Bitcode/Reader/MetadataLoader.cpp +++ lib/Bitcode/Reader/MetadataLoader.cpp @@ -452,6 +452,8 @@ bool StripTBAA = false; bool HasSeenOldLoopTags = false; bool NeedUpgradeToDIGlobalVariableExpression = false; + /// Are there DIGLobalVariables without a unit field that must be upgraded? + bool DIGlobalVariablesWithoutUnits = false; /// True if metadata is being parsed for a module being ThinLTO imported. bool IsImporting = false; @@ -511,9 +513,26 @@ } } + /// Upgrade global variables without units. + void upgradeVariablesWithoutUnits() { + if (!DIGlobalVariablesWithoutUnits) + return; + if (auto *CUs = TheModule.getNamedMetadata("llvm.dbg.cu")) + for (auto *N : CUs->operands()) + if (auto *CU = dyn_cast_or_null(N)) + if (auto *GVEs = + dyn_cast_or_null(CU->getRawGlobalVariables())) + for (auto &N1 : GVEs->operands()) + if (auto *GVE = dyn_cast_or_null(N1)) + if (auto *GV = GVE->getVariable()) + if (GV->isDefinition()) + GV->replaceOperandWith(7, CU); + } + void upgradeDebugInfo() { upgradeCUSubprograms(); upgradeCUVariables(); + upgradeVariablesWithoutUnits(); } public: @@ -1431,19 +1450,31 @@ IsDistinct = Record[0] & 1; unsigned Version = Record[0] >> 1; - if (Version == 1) { + if (Version == 2) { + MetadataList.assignValue( + GET_OR_DISTINCT( + DIGlobalVariable, + (Context, getMDOrNull(Record[1]), getMDString(Record[2]), + getMDString(Record[3]), getMDOrNull(Record[4]), Record[5], + getDITypeRefOrNull(Record[6]), Record[7], Record[8], + getMDOrNull(Record[9]), Record[10], getMDOrNull(Record[11]))), + NextMetadataNo); + NextMetadataNo++; + } else if (Version == 1) { + DIGlobalVariablesWithoutUnits = true; MetadataList.assignValue( GET_OR_DISTINCT(DIGlobalVariable, (Context, getMDOrNull(Record[1]), getMDString(Record[2]), getMDString(Record[3]), getMDOrNull(Record[4]), Record[5], getDITypeRefOrNull(Record[6]), Record[7], Record[8], - getMDOrNull(Record[10]), Record[11])), + nullptr, Record[10], getMDOrNull(Record[11]))), NextMetadataNo); NextMetadataNo++; } else if (Version == 0) { // Upgrade old metadata, which stored a global variable reference or a // ConstantInt here. + DIGlobalVariablesWithoutUnits = true; NeedUpgradeToDIGlobalVariableExpression = true; Metadata *Expr = getMDOrNull(Record[9]); uint32_t AlignInBits = 0; @@ -1470,7 +1501,7 @@ (Context, getMDOrNull(Record[1]), getMDString(Record[2]), getMDString(Record[3]), getMDOrNull(Record[4]), Record[5], getDITypeRefOrNull(Record[6]), Record[7], Record[8], - getMDOrNull(Record[10]), AlignInBits)); + getMDOrNull(Record[10]), AlignInBits, nullptr)); DIGlobalVariableExpression *DGVE = nullptr; if (Attach || Expr) Index: lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitcodeWriter.cpp +++ lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1693,8 +1693,8 @@ void ModuleBitcodeWriter::writeDIGlobalVariable( const DIGlobalVariable *N, SmallVectorImpl &Record, unsigned Abbrev) { - const uint64_t Version = 1 << 1; - Record.push_back((uint64_t)N->isDistinct() | Version); + const uint64_t Version = 2; + Record.push_back((uint64_t)N->isDistinct() | (Version << 1)); Record.push_back(VE.getMetadataOrNullID(N->getScope())); Record.push_back(VE.getMetadataOrNullID(N->getRawName())); Record.push_back(VE.getMetadataOrNullID(N->getRawLinkageName())); @@ -1703,9 +1703,9 @@ Record.push_back(VE.getMetadataOrNullID(N->getType())); Record.push_back(N->isLocalToUnit()); Record.push_back(N->isDefinition()); - Record.push_back(/* expr */ 0); Record.push_back(VE.getMetadataOrNullID(N->getStaticDataMemberDeclaration())); Record.push_back(N->getAlignInBits()); + Record.push_back(VE.getMetadataOrNullID(N->getUnit())); Stream.EmitRecord(bitc::METADATA_GLOBAL_VAR, Record, Abbrev); Record.clear(); Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -486,12 +486,6 @@ } return false; }); - GVEs.erase(std::unique(GVEs.begin(), GVEs.end(), - [](DwarfCompileUnit::GlobalExpr A, - DwarfCompileUnit::GlobalExpr B) { - return A.Expr == B.Expr; - }), - GVEs.end()); return GVEs; } @@ -511,13 +505,37 @@ // Tell MMI whether we have debug info. MMI->setDebugInfoAvailability(NumDebugCUs > 0); SingleCU = NumDebugCUs == 1; - DenseMap> - GVMap; + // Collect DIGlobalVariables reachable via global variable !dbg attachments. + // For each CU we keep a worklist to preserve the globals' relative order. + using GlobalExpr = DwarfCompileUnit::GlobalExpr; + using ExprListType = SmallVector; + using GVMapType = DenseMap>; + using WorklistType = + std::vector>; + DenseMap> UnitGVs; + + // Insert Var into GVMap and add a worklist entry if none exists. + auto insertIntoWorklist = [](GVMapType &GVMap, WorklistType &Worklist, + DIGlobalVariable *Var) -> ExprListType & { + auto EntrySuccess = GVMap.insert({Var, llvm::make_unique()}); + auto Entry = EntrySuccess.first; + ExprListType &Exprs = *Entry->second; + if (EntrySuccess.second) + Worklist.push_back({Var, &Exprs}); + return Exprs; + }; + for (const GlobalVariable &Global : M->globals()) { SmallVector GVs; Global.getDebugInfo(GVs); - for (auto *GVE : GVs) - GVMap[GVE->getVariable()].push_back({&Global, GVE->getExpression()}); + for (auto *GVE : GVs) { + auto *Var = GVE->getVariable(); + auto &GVMapWorklist = UnitGVs[Var->getUnit()]; + GVMapType &GVMap = GVMapWorklist.first; + WorklistType &Worklist = GVMapWorklist.second; + ExprListType &Exprs = insertIntoWorklist(GVMap, Worklist, Var); + Exprs.push_back({&Global, GVE->getExpression()}); + } } for (DICompileUnit *CUNode : M->debug_compile_units()) { @@ -525,14 +543,24 @@ for (auto *IE : CUNode->getImportedEntities()) CU.addImportedEntity(IE); - // Global Variables. - for (auto *GVE : CUNode->getGlobalVariables()) - GVMap[GVE->getVariable()].push_back({nullptr, GVE->getExpression()}); - DenseSet Processed; - for (auto *GVE : CUNode->getGlobalVariables()) { - DIGlobalVariable *GV = GVE->getVariable(); - if (Processed.insert(GV).second) - CU.getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(GVMap[GV])); + // Collect DIGlobalVariables reachable via the DICompileUnit. + auto &GVMapWorklist = UnitGVs[CUNode]; + GVMapType &GVMap = GVMapWorklist.first; + WorklistType &Worklist = GVMapWorklist.second; + for (auto *GVE : CUNode->getGlobalVariables()) { + auto *Var = GVE->getVariable(); + auto *Expr = GVE->getExpression(); + ExprListType &Exprs = insertIntoWorklist(GVMap, Worklist, Var); + if (std::none_of(Exprs.begin(), Exprs.end(), + [&Expr](GlobalExpr &GE) { return GE.Expr == Expr; })) + Exprs.push_back({nullptr, Expr}); + } + + // Emit all DIGlobalVariables belonging to the current CU. + for (auto &GVEntry : Worklist) { + DIGlobalVariable *GV = GVEntry.first; + ExprListType &Exprs = *GVEntry.second; + CU.getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(Exprs)); } for (auto *Ty : CUNode->getEnumTypes()) { Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -1844,6 +1844,7 @@ Printer.printBool("isDefinition", N->isDefinition()); Printer.printMetadata("declaration", N->getRawStaticDataMemberDeclaration()); Printer.printInt("align", N->getAlignInBits()); + Printer.printMetadata("unit", N->getUnit()); Out << ")"; } Index: lib/IR/DIBuilder.cpp =================================================================== --- lib/IR/DIBuilder.cpp +++ lib/IR/DIBuilder.cpp @@ -576,16 +576,24 @@ #endif } +template +static DIGlobalVariable *getGlobalVariable(bool IsDistinct, Ts &&... Args) { + if (IsDistinct) + return DIGlobalVariable::getDistinct(std::forward(Args)...); + return DIGlobalVariable::get(std::forward(Args)...); +} + DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression( DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr, - MDNode *Decl, uint32_t AlignInBits) { + MDNode *Decl, uint32_t AlignInBits, bool Shared) { checkGlobalVariableScope(Context); - auto *GV = DIGlobalVariable::getDistinct( - VMContext, cast_or_null(Context), Name, LinkageName, F, + bool Distinct = !Shared; + auto *GV = getGlobalVariable( + Distinct, VMContext, cast_or_null(Context), Name, LinkageName, F, LineNumber, Ty, isLocalToUnit, true, cast_or_null(Decl), - AlignInBits); + AlignInBits, Distinct ? CUNode : nullptr); auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr); AllGVs.push_back(N); return N; @@ -600,7 +608,7 @@ return DIGlobalVariable::getTemporary( VMContext, cast_or_null(Context), Name, LinkageName, F, LineNumber, Ty, isLocalToUnit, false, - cast_or_null(Decl), AlignInBits) + cast_or_null(Decl), AlignInBits, nullptr) .release(); } Index: lib/IR/DebugInfoMetadata.cpp =================================================================== --- lib/IR/DebugInfoMetadata.cpp +++ lib/IR/DebugInfoMetadata.cpp @@ -538,16 +538,17 @@ MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition, Metadata *StaticDataMemberDeclaration, - uint32_t AlignInBits, StorageType Storage, - bool ShouldCreate) { + uint32_t AlignInBits, Metadata *Unit, + StorageType Storage, bool ShouldCreate) { assert(isCanonical(Name) && "Expected canonical MDString"); assert(isCanonical(LinkageName) && "Expected canonical MDString"); DEFINE_GETIMPL_LOOKUP(DIGlobalVariable, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits)); + StaticDataMemberDeclaration, AlignInBits, Unit)); Metadata *Ops[] = { - Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration}; + Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration, + Unit}; DEFINE_GETIMPL_STORE(DIGlobalVariable, (Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops); Index: lib/IR/LLVMContextImpl.h =================================================================== --- lib/IR/LLVMContextImpl.h +++ lib/IR/LLVMContextImpl.h @@ -783,28 +783,30 @@ MDString *Name; MDString *LinkageName; Metadata *File; - unsigned Line; Metadata *Type; + Metadata *StaticDataMemberDeclaration; + Metadata *Unit; + unsigned Line; bool IsLocalToUnit; bool IsDefinition; - Metadata *StaticDataMemberDeclaration; uint32_t AlignInBits; MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition, - Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits) + Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits, + Metadata *Unit) : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File), - Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit), - IsDefinition(IsDefinition), - StaticDataMemberDeclaration(StaticDataMemberDeclaration), - AlignInBits(AlignInBits) {} + Type(Type), StaticDataMemberDeclaration(StaticDataMemberDeclaration), + Unit(Unit), Line(Line), IsLocalToUnit(IsLocalToUnit), + IsDefinition(IsDefinition), AlignInBits(AlignInBits) {} MDNodeKeyImpl(const DIGlobalVariable *N) : Scope(N->getRawScope()), Name(N->getRawName()), LinkageName(N->getRawLinkageName()), File(N->getRawFile()), - Line(N->getLine()), Type(N->getRawType()), - IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()), + Type(N->getRawType()), StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()), + Unit(N->getRawUnit()), Line(N->getLine()), + IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()), AlignInBits(N->getAlignInBits()) {} bool isKeyOf(const DIGlobalVariable *RHS) const { @@ -815,7 +817,7 @@ IsDefinition == RHS->isDefinition() && StaticDataMemberDeclaration == RHS->getRawStaticDataMemberDeclaration() && - AlignInBits == RHS->getAlignInBits(); + AlignInBits == RHS->getAlignInBits() && Unit == RHS->getRawUnit(); } unsigned getHashValue() const { // We do not use AlignInBits in hashing function here on purpose: Index: lib/IR/Verifier.cpp =================================================================== --- lib/IR/Verifier.cpp +++ lib/IR/Verifier.cpp @@ -658,9 +658,16 @@ SmallVector MDs; GV.getMetadata(LLVMContext::MD_dbg, MDs); for (auto *MD : MDs) { - if (auto *GVE = dyn_cast(MD)) + if (auto *GVE = dyn_cast(MD)) { + AssertDI(GVE->getVariable(), "missing DIGlobalVariable"); + if (auto *GV = GVE->getVariable()) { + if (GV->isDistinct()) + AssertDI(GV->getUnit(), "missing unit field"); + else + AssertDI(!GV->getUnit(), "unique variable with a unit field"); + } visitDIGlobalVariableExpression(*GVE); - else + } else AssertDI(false, "!dbg attachment of global variable must be a " "DIGlobalVariableExpression"); } @@ -671,7 +678,8 @@ } // Walk any aggregate initializers looking for bitcasts between address spaces - visitConstantExprsRecursively(GV.getInitializer()); + if (GV.hasInitializer()) + visitConstantExprsRecursively(GV.getInitializer()); visitGlobalValue(GV); } @@ -1016,8 +1024,10 @@ if (auto *Array = N.getRawGlobalVariables()) { AssertDI(isa(Array), "invalid global variable list", &N, Array); for (Metadata *Op : N.getGlobalVariables()->operands()) { - AssertDI(Op && (isa(Op)), - "invalid global variable ref", &N, Op); + if (auto *GVE = dyn_cast_or_null(Op)) + visitDIGlobalVariableExpression(*GVE); + else + AssertDI(false, "invalid global variable ref", &N, Op); } } if (auto *Array = N.getRawImportedEntities()) { Index: test/Bitcode/DIGlobalVariable-unit.ll =================================================================== --- /dev/null +++ test/Bitcode/DIGlobalVariable-unit.ll @@ -0,0 +1,23 @@ +; RUN: llvm-dis -o - %s.bc | FileCheck %s +@g = common global i32 0, align 4, !dbg !0 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!9, !10, !11} +!llvm.ident = !{!12} + +!0 = !DIGlobalVariableExpression(var: !1) +; CHECK: distinct !DIGlobalVariable(name: "g", {{.*}}, unit: ![[CU:[0-9]+]]) +!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true) +; CHECK: ![[CU]] = distinct !DICompileUnit +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, imports: !5) +!3 = !DIFile(filename: "t.c", directory: "/") +!4 = !{!0} +!5 = !{!6} +!6 = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "h", scope: !2, entity: !7, line: 1) +; CHECK: distinct !DIGlobalVariable(name: "h", {{.*}}, isDefinition: false) +!7 = distinct !DIGlobalVariable(name: "h", scope: !2, file: !3, line: 3, type: !8, isLocal: false, isDefinition: false) +!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!9 = !{i32 2, !"Dwarf Version", i32 4} +!10 = !{i32 2, !"Debug Info Version", i32 3} +!11 = !{i32 1, !"PIC Level", i32 2} +!12 = !{!"clang version 4.0.0 (trunk 290265)"} Index: test/Bitcode/diglobalvariable-3.8.ll =================================================================== --- test/Bitcode/diglobalvariable-3.8.ll +++ test/Bitcode/diglobalvariable-3.8.ll @@ -10,7 +10,7 @@ ; CHECK: !3 = !{!4} !3 = !{!4} ; CHECK: !4 = {{.*}}!DIGlobalVariableExpression(var: !5, expr: !8) -; CHECK: !5 = !DIGlobalVariable(name: "c", scope: !0, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true) +; CHECK: !5 = !DIGlobalVariable(name: "c", scope: !0, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, unit: !0) ; CHECK: !8 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value) !4 = !DIGlobalVariable(name: "c", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, variable: i32 42) !5 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !6) Index: test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll =================================================================== --- test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll +++ test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll @@ -19,6 +19,9 @@ ; CHECK: DW_TAG_variable ; CHECK-NOT: DW_TAG +; CHECK: DW_AT_name {{.*}} "x5" +; CHECK: DW_TAG_variable +; CHECK-NOT: DW_TAG ; CHECK: DW_AT_name {{.*}} "x1" ; CHECK-NOT: {{DW_TAG|NULL}} ; CHECK: DW_AT_location [DW_FORM_exprloc] (<0x5> 03 [[ADDR:.. .. .. ..]] ) @@ -91,17 +94,17 @@ !llvm.module.flags = !{!15} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "x1", scope: !2, file: !2, line: 3, type: !3, isLocal: true, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "x1", scope: !2, file: !2, line: 3, type: !3, isLocal: true, isDefinition: true, unit: !12) !2 = !DIFile(filename: "foo.c", directory: "/tmp/") !3 = !DIBasicType(name: "_Bool", size: 8, align: 8, encoding: DW_ATE_boolean) !4 = !DIGlobalVariableExpression(var: !5) -!5 = !DIGlobalVariable(name: "x2", scope: !2, file: !2, line: 6, type: !3, isLocal: true, isDefinition: true) +!5 = distinct !DIGlobalVariable(name: "x2", scope: !2, file: !2, line: 6, type: !3, isLocal: true, isDefinition: true, unit: !12) !6 = !DIGlobalVariableExpression(var: !7) -!7 = !DIGlobalVariable(name: "x3", scope: !2, file: !2, line: 9, type: !3, isLocal: true, isDefinition: true) +!7 = distinct !DIGlobalVariable(name: "x3", scope: !2, file: !2, line: 9, type: !3, isLocal: true, isDefinition: true, unit: !12) !8 = !DIGlobalVariableExpression(var: !9) -!9 = !DIGlobalVariable(name: "x4", scope: !2, file: !2, line: 12, type: !3, isLocal: true, isDefinition: true) +!9 = distinct !DIGlobalVariable(name: "x4", scope: !2, file: !2, line: 12, type: !3, isLocal: true, isDefinition: true, unit: !12) !10 = !DIGlobalVariableExpression(var: !11) -!11 = !DIGlobalVariable(name: "x5", scope: !2, file: !2, line: 15, type: !3, isLocal: false, isDefinition: true) +!11 = distinct !DIGlobalVariable(name: "x5", scope: !2, file: !2, line: 15, type: !3, isLocal: false, isDefinition: true, unit: !12) !12 = distinct !DICompileUnit(language: DW_LANG_C89, file: !2, producer: "4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2369.8)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !13, retainedTypes: !13, globals: !14, imports: !13) !13 = !{} !14 = !{!0, !4, !6, !8, !10} Index: test/CodeGen/ARM/2011-08-02-MergedGlobalDbg.ll =================================================================== --- test/CodeGen/ARM/2011-08-02-MergedGlobalDbg.ll +++ test/CodeGen/ARM/2011-08-02-MergedGlobalDbg.ll @@ -89,13 +89,13 @@ !llvm.module.flags = !{!9} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "x1", scope: !2, file: !3, line: 4, type: !8, isLocal: true, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "x1", scope: !2, file: !3, line: 4, type: !8, isLocal: true, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !4, globals: !5, imports: !4) !3 = !DIFile(filename: "ss3.c", directory: "/private/tmp") !4 = !{} !5 = !{!0, !6} !6 = !DIGlobalVariableExpression(var: !7) -!7 = !DIGlobalVariable(name: "x2", scope: !2, file: !3, line: 7, type: !8, isLocal: true, isDefinition: true) +!7 = distinct !DIGlobalVariable(name: "x2", scope: !2, file: !3, line: 7, type: !8, isLocal: true, isDefinition: true, unit: !2) !8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !9 = !{i32 1, !"Debug Info Version", i32 3} !10 = distinct !DISubprogram(name: "get1", scope: !3, file: !3, line: 5, type: !11, isLocal: false, isDefinition: true, scopeLine: 5, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !2, variables: !13) Index: test/CodeGen/ARM/no-cfi.ll =================================================================== --- test/CodeGen/ARM/no-cfi.ll +++ test/CodeGen/ARM/no-cfi.ll @@ -12,7 +12,7 @@ !llvm.module.flags = !{!7, !8, !9, !10} !0 = !DIGlobalVariableExpression(var: !1) -!1 = distinct !DIGlobalVariable(name: "f", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "f", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 4.0.0 (trunk 290216)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "test2.c", directory: "/tmp") !4 = !{} Index: test/CodeGen/X86/dwarf-headers.ll =================================================================== --- test/CodeGen/X86/dwarf-headers.ll +++ test/CodeGen/X86/dwarf-headers.ll @@ -95,7 +95,7 @@ !llvm.ident = !{!12} !0 = !DIGlobalVariableExpression(var: !1) -!1 = distinct !DIGlobalVariable(name: "s", scope: !2, file: !3, line: 5, type: !6, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "s", scope: !2, file: !3, line: 5, type: !6, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 5.0.0 (trunk 295942)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "t.cpp", directory: "/home/probinson/projects/scratch") !4 = !{} Index: test/CodeGen/X86/machine-outliner-debuginfo.ll =================================================================== --- test/CodeGen/X86/machine-outliner-debuginfo.ll +++ test/CodeGen/X86/machine-outliner-debuginfo.ll @@ -48,7 +48,7 @@ !llvm.ident = !{!10} !0 = !DIGlobalVariableExpression(var: !1) -!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 2, type: !6, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 2, type: !6, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 5.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "debug-test.c", directory: "dir") !4 = !{} Index: test/DebugInfo/AMDGPU/variable-locations-dwarf-v1.ll =================================================================== --- test/DebugInfo/AMDGPU/variable-locations-dwarf-v1.ll +++ test/DebugInfo/AMDGPU/variable-locations-dwarf-v1.ll @@ -56,13 +56,13 @@ !llvm.ident = !{!12} !0 = !DIGlobalVariableExpression(var: !1) -!1 = distinct !DIGlobalVariable(name: "GlobA", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "GlobA", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 5.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "variable-locations-dwarf-v1.cl", directory: "/some/random/directory") !4 = !{} !5 = !{!0, !6} !6 = !DIGlobalVariableExpression(var: !7) -!7 = distinct !DIGlobalVariable(name: "GlobB", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true) +!7 = distinct !DIGlobalVariable(name: "GlobB", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true, unit: !2) !8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !9 = !{i32 2, i32 0} !10 = !{i32 2, !"Dwarf Version", i32 1} Index: test/DebugInfo/AMDGPU/variable-locations.ll =================================================================== --- test/DebugInfo/AMDGPU/variable-locations.ll +++ test/DebugInfo/AMDGPU/variable-locations.ll @@ -75,13 +75,13 @@ !llvm.ident = !{!12} !0 = !DIGlobalVariableExpression(var: !1) -!1 = distinct !DIGlobalVariable(name: "GlobA", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "GlobA", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 5.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "variable-locations.cl", directory: "/some/random/directory") !4 = !{} !5 = !{!0, !6} !6 = !DIGlobalVariableExpression(var: !7) -!7 = distinct !DIGlobalVariable(name: "GlobB", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true) +!7 = distinct !DIGlobalVariable(name: "GlobB", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true, unit: !2) !8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !9 = !{i32 2, i32 0} !10 = !{i32 2, !"Dwarf Version", i32 2} Index: test/DebugInfo/ARM/tls.ll =================================================================== --- test/DebugInfo/ARM/tls.ll +++ test/DebugInfo/ARM/tls.ll @@ -24,7 +24,7 @@ ; EMU-NOT: .long x(tlsldo) !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "x", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "x", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true, unit: !4) !2 = !DIFile(filename: "tls.c", directory: "/tmp") !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !4 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.5 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5) Index: test/DebugInfo/Generic/accel-table-hash-collisions.ll =================================================================== --- test/DebugInfo/Generic/accel-table-hash-collisions.ll +++ test/DebugInfo/Generic/accel-table-hash-collisions.ll @@ -70,34 +70,34 @@ !llvm.ident = !{!32} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "ForceTopDown", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "ForceTopDown", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 3.7.0 (trunk 231548) (llvm/trunk 231547)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !4, globals: !5, imports: !4) !3 = !DIFile(filename: "hash-collisions.c", directory: "/tmp") !4 = !{} !5 = !{!0, !6, !9, !11, !13, !15, !17, !19, !21, !23, !25, !27} !6 = !DIGlobalVariableExpression(var: !7) -!7 = !DIGlobalVariable(name: "_ZNSt3__116allocator_traitsINS_9allocatorINS_11__tree_nodeINS_12__value_typeIPN4llvm10BasicBlockEPNS4_10RegionNodeEEEPvEEEEE11__constructIS9_JNS_4pairIS6_S8_EEEEEvNS_17integral_constantIbLb1EEERSC_PT_DpOT0_", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true) +!7 = distinct !DIGlobalVariable(name: "_ZNSt3__116allocator_traitsINS_9allocatorINS_11__tree_nodeINS_12__value_typeIPN4llvm10BasicBlockEPNS4_10RegionNodeEEEPvEEEEE11__constructIS9_JNS_4pairIS6_S8_EEEEEvNS_17integral_constantIbLb1EEERSC_PT_DpOT0_", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true, unit: !2) !8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !9 = !DIGlobalVariableExpression(var: !10) -!10 = !DIGlobalVariable(name: "_ZN5clang23DataRecursiveASTVisitorIN12_GLOBAL__N_124UnusedBackingIvarCheckerEE26TraverseCUDAKernelCallExprEPNS_18CUDAKernelCallExprE", scope: !2, file: !3, line: 3, type: !8, isLocal: false, isDefinition: true) +!10 = distinct !DIGlobalVariable(name: "_ZN5clang23DataRecursiveASTVisitorIN12_GLOBAL__N_124UnusedBackingIvarCheckerEE26TraverseCUDAKernelCallExprEPNS_18CUDAKernelCallExprE", scope: !2, file: !3, line: 3, type: !8, isLocal: false, isDefinition: true, unit: !2) !11 = !DIGlobalVariableExpression(var: !12) -!12 = !DIGlobalVariable(name: "_ZN4llvm16DenseMapIteratorIPNS_10MDLocationENS_6detail13DenseSetEmptyENS_10MDNodeInfoIS1_EENS3_12DenseSetPairIS2_EELb0EE23AdvancePastEmptyBucketsEv", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true) +!12 = distinct !DIGlobalVariable(name: "_ZN4llvm16DenseMapIteratorIPNS_10MDLocationENS_6detail13DenseSetEmptyENS_10MDNodeInfoIS1_EENS3_12DenseSetPairIS2_EELb0EE23AdvancePastEmptyBucketsEv", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, unit: !2) !13 = !DIGlobalVariableExpression(var: !14) -!14 = !DIGlobalVariable(name: "_ZNK4llvm12LivePhysRegs5printERNS_11raw_ostreamE", scope: !2, file: !3, line: 5, type: !8, isLocal: false, isDefinition: true) +!14 = distinct !DIGlobalVariable(name: "_ZNK4llvm12LivePhysRegs5printERNS_11raw_ostreamE", scope: !2, file: !3, line: 5, type: !8, isLocal: false, isDefinition: true, unit: !2) !15 = !DIGlobalVariableExpression(var: !16) -!16 = !DIGlobalVariable(name: "_ZN4llvm15ScalarEvolution14getSignedRangeEPKNS_4SCEVE", scope: !2, file: !3, line: 6, type: !8, isLocal: false, isDefinition: true) +!16 = distinct !DIGlobalVariable(name: "_ZN4llvm15ScalarEvolution14getSignedRangeEPKNS_4SCEVE", scope: !2, file: !3, line: 6, type: !8, isLocal: false, isDefinition: true, unit: !2) !17 = !DIGlobalVariableExpression(var: !18) -!18 = !DIGlobalVariable(name: "k1", scope: !2, file: !3, line: 7, type: !8, isLocal: false, isDefinition: true) +!18 = distinct !DIGlobalVariable(name: "k1", scope: !2, file: !3, line: 7, type: !8, isLocal: false, isDefinition: true, unit: !2) !19 = !DIGlobalVariableExpression(var: !20) -!20 = !DIGlobalVariable(name: "is", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true) +!20 = distinct !DIGlobalVariable(name: "is", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true, unit: !2) !21 = !DIGlobalVariableExpression(var: !22) -!22 = !DIGlobalVariable(name: "setStmt", scope: !2, file: !3, line: 9, type: !8, isLocal: false, isDefinition: true) +!22 = distinct !DIGlobalVariable(name: "setStmt", scope: !2, file: !3, line: 9, type: !8, isLocal: false, isDefinition: true, unit: !2) !23 = !DIGlobalVariableExpression(var: !24) -!24 = !DIGlobalVariable(name: "_ZN4llvm5TwineC1Ei", scope: !2, file: !3, line: 10, type: !8, isLocal: false, isDefinition: true) +!24 = distinct !DIGlobalVariable(name: "_ZN4llvm5TwineC1Ei", scope: !2, file: !3, line: 10, type: !8, isLocal: false, isDefinition: true, unit: !2) !25 = !DIGlobalVariableExpression(var: !26) -!26 = !DIGlobalVariable(name: "_ZNK5clang12OverrideAttr5cloneERNS_10ASTContextE", scope: !2, file: !3, line: 11, type: !8, isLocal: false, isDefinition: true) +!26 = distinct !DIGlobalVariable(name: "_ZNK5clang12OverrideAttr5cloneERNS_10ASTContextE", scope: !2, file: !3, line: 11, type: !8, isLocal: false, isDefinition: true, unit: !2) !27 = !DIGlobalVariableExpression(var: !28) -!28 = !DIGlobalVariable(name: "_ZN4llvm22MachineModuleInfoMachOD2Ev", scope: !2, file: !3, line: 12, type: !8, isLocal: false, isDefinition: true) +!28 = distinct !DIGlobalVariable(name: "_ZN4llvm22MachineModuleInfoMachOD2Ev", scope: !2, file: !3, line: 12, type: !8, isLocal: false, isDefinition: true, unit: !2) !29 = !{i32 2, !"Dwarf Version", i32 2} !30 = !{i32 2, !"Debug Info Version", i32 3} !31 = !{i32 1, !"PIC Level", i32 2} Index: test/DebugInfo/MIR/X86/live-debug-values-spill.mir =================================================================== --- test/DebugInfo/MIR/X86/live-debug-values-spill.mir +++ test/DebugInfo/MIR/X86/live-debug-values-spill.mir @@ -203,22 +203,22 @@ !llvm.ident = !{!19} !0 = !DIGlobalVariableExpression(var: !1) - !1 = distinct !DIGlobalVariable(name: "glob0", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true) + !1 = distinct !DIGlobalVariable(name: "glob0", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 5.0.0 (trunk 292962)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "spill1.c", directory: "/home/test") !4 = !{} !5 = !{!0, !6, !9, !11, !13, !15} !6 = !DIGlobalVariableExpression(var: !7) - !7 = distinct !DIGlobalVariable(name: "glob1", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true) + !7 = distinct !DIGlobalVariable(name: "glob1", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, unit: !2) !8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !9 = !DIGlobalVariableExpression(var: !10) - !10 = distinct !DIGlobalVariable(name: "glob2", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true) + !10 = distinct !DIGlobalVariable(name: "glob2", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, unit: !2) !11 = !DIGlobalVariableExpression(var: !12) - !12 = distinct !DIGlobalVariable(name: "glob3", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true) + !12 = distinct !DIGlobalVariable(name: "glob3", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, unit: !2) !13 = !DIGlobalVariableExpression(var: !14) - !14 = distinct !DIGlobalVariable(name: "glob4", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true) + !14 = distinct !DIGlobalVariable(name: "glob4", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, unit: !2) !15 = !DIGlobalVariableExpression(var: !16) - !16 = distinct !DIGlobalVariable(name: "glob5", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true) + !16 = distinct !DIGlobalVariable(name: "glob5", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, unit: !2) !17 = !{i32 2, !"Dwarf Version", i32 4} !18 = !{i32 2, !"Debug Info Version", i32 3} !19 = !{!"clang version 5.0.0 (trunk 292962)"} Index: test/DebugInfo/Mips/tls.ll =================================================================== --- test/DebugInfo/Mips/tls.ll +++ test/DebugInfo/Mips/tls.ll @@ -11,7 +11,7 @@ !llvm.ident = !{!9} !0 = !DIGlobalVariableExpression(var: !1) -!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 4.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "tls.c", directory: "/tmp") !4 = !{} Index: test/DebugInfo/PowerPC/tls-fission.ll =================================================================== --- test/DebugInfo/PowerPC/tls-fission.ll +++ test/DebugInfo/PowerPC/tls-fission.ll @@ -24,7 +24,7 @@ !llvm.module.flags = !{!7, !8} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "tls", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "tls", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true, unit: !4) !2 = !DIFile(filename: "tls.cpp", directory: "/tmp") !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !4 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 3.4 ", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "tls.dwo", emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5) Index: test/DebugInfo/PowerPC/tls.ll =================================================================== --- test/DebugInfo/PowerPC/tls.ll +++ test/DebugInfo/PowerPC/tls.ll @@ -20,7 +20,7 @@ !llvm.module.flags = !{!7, !8} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "tls", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "tls", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true, unit: !4) !2 = !DIFile(filename: "tls.cpp", directory: "/tmp") !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !4 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 3.4 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5) Index: test/DebugInfo/X86/FrameIndexExprs.ll =================================================================== --- test/DebugInfo/X86/FrameIndexExprs.ll +++ test/DebugInfo/X86/FrameIndexExprs.ll @@ -48,13 +48,13 @@ !llvm.module.flags = !{!9, !10, !11} !0 = !DIGlobalVariableExpression(var: !1) -!1 = distinct !DIGlobalVariable(name: "f", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "f", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "PR31381.c", directory: "/") !4 = !{} !5 = !{!0, !6} !6 = !DIGlobalVariableExpression(var: !7) -!7 = distinct !DIGlobalVariable(name: "h", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true) +!7 = distinct !DIGlobalVariable(name: "h", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true, unit: !2) !8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !9 = !{i32 2, !"Dwarf Version", i32 4} !10 = !{i32 2, !"Debug Info Version", i32 3} Index: test/DebugInfo/X86/arange-and-stub.ll =================================================================== --- test/DebugInfo/X86/arange-and-stub.ll +++ test/DebugInfo/X86/arange-and-stub.ll @@ -34,7 +34,7 @@ !llvm.module.flags = !{!15, !16} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "zed", scope: !2, file: !6, line: 6, type: !7, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "zed", scope: !2, file: !6, line: 6, type: !7, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.7.0 (trunk 234308) (llvm/trunk 234310)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !4, globals: !5, imports: !4) !3 = !DIFile(filename: "/Users/espindola/llvm/", directory: "/Users/espindola/llvm/build") !4 = !{} Index: test/DebugInfo/X86/arange.ll =================================================================== --- test/DebugInfo/X86/arange.ll +++ test/DebugInfo/X86/arange.ll @@ -32,7 +32,7 @@ !llvm.ident = !{!14} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "f", scope: null, file: !2, line: 6, type: !3, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "f", scope: null, file: !2, line: 6, type: !3, isLocal: false, isDefinition: true, unit: !9) !2 = !DIFile(filename: "simple.cpp", directory: "/tmp/dbginfo") !3 = !DICompositeType(tag: DW_TAG_structure_type, name: "foo<&i>", file: !2, line: 3, size: 8, align: 8, elements: !4, templateParams: !5, identifier: "_ZTS3fooIXadL_Z1iEEE") !4 = !{} Index: test/DebugInfo/X86/debug-info-static-member.ll =================================================================== --- test/DebugInfo/X86/debug-info-static-member.ll +++ test/DebugInfo/X86/debug-info-static-member.ll @@ -67,7 +67,7 @@ !llvm.module.flags = !{!25} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "a", linkageName: "_ZN1C1aE", scope: null, file: !2, line: 14, type: !3, isLocal: false, isDefinition: true, declaration: !4) +!1 = distinct !DIGlobalVariable(name: "a", linkageName: "_ZN1C1aE", scope: null, file: !2, line: 14, type: !3, isLocal: false, isDefinition: true, declaration: !4, unit: !22) !2 = !DIFile(filename: "/usr/local/google/home/blaikie/Development/llvm/src/tools/clang/test/CodeGenCXX/debug-info-static-member.cpp", directory: "/home/blaikie/local/Development/llvm/build/clang/x86-64/Debug/llvm") !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !4 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !5, file: !2, line: 3, baseType: !3, flags: DIFlagPrivate | DIFlagStaticMember) @@ -85,9 +85,9 @@ !16 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !3) !17 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !5, file: !2, line: 11, baseType: !3, size: 32, align: 32, flags: DIFlagPublic) !18 = !DIGlobalVariableExpression(var: !19) -!19 = !DIGlobalVariable(name: "b", linkageName: "_ZN1C1bE", scope: null, file: !2, line: 15, type: !3, isLocal: false, isDefinition: true, declaration: !10) +!19 = distinct !DIGlobalVariable(name: "b", linkageName: "_ZN1C1bE", scope: null, file: !2, line: 15, type: !3, isLocal: false, isDefinition: true, declaration: !10, unit: !22) !20 = !DIGlobalVariableExpression(var: !21) -!21 = !DIGlobalVariable(name: "c", linkageName: "_ZN1C1cE", scope: null, file: !2, line: 16, type: !3, isLocal: false, isDefinition: true, declaration: !14) +!21 = distinct !DIGlobalVariable(name: "c", linkageName: "_ZN1C1cE", scope: null, file: !2, line: 16, type: !3, isLocal: false, isDefinition: true, declaration: !14, unit: !22) !22 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 3.3 (trunk 171914)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !23, retainedTypes: !23, globals: !24, imports: !23) !23 = !{} !24 = !{!0, !18, !20} Index: test/DebugInfo/X86/dwarf-aranges-no-dwarf-labels.ll =================================================================== --- test/DebugInfo/X86/dwarf-aranges-no-dwarf-labels.ll +++ test/DebugInfo/X86/dwarf-aranges-no-dwarf-labels.ll @@ -61,7 +61,7 @@ !llvm.module.flags = !{!7, !8} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "global", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "global", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true, unit: !4) !2 = !DIFile(filename: "tmp/debug_ranges/a.cc", directory: "/") !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !4 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 3.4 (191881)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5) Index: test/DebugInfo/X86/dwarf-aranges.ll =================================================================== --- test/DebugInfo/X86/dwarf-aranges.ll +++ test/DebugInfo/X86/dwarf-aranges.ll @@ -61,13 +61,13 @@ !llvm.module.flags = !{!11, !12} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "some_data", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "some_data", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true, unit: !8) !2 = !DIFile(filename: "test.c", directory: "/home/kayamon") !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !4 = !DIGlobalVariableExpression(var: !5) -!5 = !DIGlobalVariable(name: "some_other", scope: null, file: !2, line: 3, type: !3, isLocal: false, isDefinition: true) +!5 = distinct !DIGlobalVariable(name: "some_other", scope: null, file: !2, line: 3, type: !3, isLocal: false, isDefinition: true, unit: !8) !6 = !DIGlobalVariableExpression(var: !7) -!7 = !DIGlobalVariable(name: "some_bss", scope: null, file: !2, line: 2, type: !3, isLocal: false, isDefinition: true) +!7 = distinct !DIGlobalVariable(name: "some_bss", scope: null, file: !2, line: 2, type: !3, isLocal: false, isDefinition: true, unit: !8) !8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.4 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !9, retainedTypes: !9, globals: !10, imports: !9) !9 = !{} !10 = !{!0, !4, !6} Index: test/DebugInfo/X86/dwarf-public-names.ll =================================================================== --- test/DebugInfo/X86/dwarf-public-names.ll +++ test/DebugInfo/X86/dwarf-public-names.ll @@ -104,7 +104,7 @@ !llvm.module.flags = !{!22} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "static_member_variable", linkageName: "_ZN1C22static_member_variableE", scope: !2, file: !3, line: 7, type: !6, isLocal: false, isDefinition: true, declaration: !5) +!1 = distinct !DIGlobalVariable(name: "static_member_variable", linkageName: "_ZN1C22static_member_variableE", scope: !2, file: !3, line: 7, type: !6, isLocal: false, isDefinition: true, declaration: !5, unit: !20) !2 = !DICompositeType(tag: DW_TAG_structure_type, name: "C", file: !3, line: 1, size: 8, elements: !4) !3 = !DIFile(filename: "dwarf-public-names.cpp", directory: "/usr2/kparzysz/s.hex/t") !4 = !{!5, !7, !12} @@ -119,9 +119,9 @@ !13 = !DISubroutineType(types: !14) !14 = !{!6} !15 = !DIGlobalVariableExpression(var: !16) -!16 = !DIGlobalVariable(name: "global_variable", scope: null, file: !3, line: 17, type: !2, isLocal: false, isDefinition: true) ; previously: invalid DW_TAG_base_type +!16 = distinct !DIGlobalVariable(name: "global_variable", scope: null, file: !3, line: 17, type: !2, isLocal: false, isDefinition: true, unit: !20) ; previously: invalid DW_TAG_base_type !17 = !DIGlobalVariableExpression(var: !18) -!18 = !DIGlobalVariable(name: "global_namespace_variable", linkageName: "_ZN2ns25global_namespace_variableE", scope: !19, file: !3, line: 27, type: !6, isLocal: false, isDefinition: true) +!18 = distinct !DIGlobalVariable(name: "global_namespace_variable", linkageName: "_ZN2ns25global_namespace_variableE", scope: !19, file: !3, line: 27, type: !6, isLocal: false, isDefinition: true, unit: !20) !19 = !DINamespace(name: "ns", scope: null, file: !3, line: 23) !20 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.3 (http://llvm.org/git/clang.git a09cd8103a6a719cb2628cdf0c91682250a17bd2) (http://llvm.org/git/llvm.git 47d03cec0afca0c01ae42b82916d1d731716cd20)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !11, retainedTypes: !11, globals: !21, imports: !11) ; previously: invalid DW_TAG_base_type !21 = !{!0, !15, !17} Index: test/DebugInfo/X86/fission-cu.ll =================================================================== --- test/DebugInfo/X86/fission-cu.ll +++ test/DebugInfo/X86/fission-cu.ll @@ -11,7 +11,7 @@ !llvm.module.flags = !{!7} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true, unit: !4) !2 = !DIFile(filename: "baz.c", directory: "/usr/local/google/home/echristo/tmp") !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !4 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.3 (trunk 169021) (llvm/trunk 169020)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "baz.dwo", emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5) Index: test/DebugInfo/X86/gnu-public-names-tu.ll =================================================================== --- test/DebugInfo/X86/gnu-public-names-tu.ll +++ test/DebugInfo/X86/gnu-public-names-tu.ll @@ -38,7 +38,7 @@ !llvm.ident = !{!13} !0 = !DIGlobalVariableExpression(var: !1) -!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 5.0.0 (trunk 293904) (llvm/trunk 293908)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "type.cpp", directory: "/tmp/dbginfo") !4 = !{} Index: test/DebugInfo/X86/gnu-public-names.ll =================================================================== --- test/DebugInfo/X86/gnu-public-names.ll +++ test/DebugInfo/X86/gnu-public-names.ll @@ -301,7 +301,7 @@ !llvm.ident = !{!50} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "static_member_variable", linkageName: "_ZN1C22static_member_variableE", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true, declaration: !8) +!1 = distinct !DIGlobalVariable(name: "static_member_variable", linkageName: "_ZN1C22static_member_variableE", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true, declaration: !8, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.7.0 (trunk 234897) (llvm/trunk 234911)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !21, imports: !44) !3 = !DIFile(filename: "gnu-public-names.cpp", directory: "/tmp/dbginfo") !4 = !{} @@ -323,30 +323,30 @@ !20 = !DIDerivedType(tag: DW_TAG_member, name: "A", scope: !17, file: !3, line: 30, baseType: !9, size: 32, align: 32) !21 = !{!0, !22, !24, !26, !28, !34, !37, !40} !22 = !DIGlobalVariableExpression(var: !23) -!23 = !DIGlobalVariable(name: "global_variable", scope: !2, file: !3, line: 17, type: !6, isLocal: false, isDefinition: true) +!23 = distinct !DIGlobalVariable(name: "global_variable", scope: !2, file: !3, line: 17, type: !6, isLocal: false, isDefinition: true, unit: !2) !24 = !DIGlobalVariableExpression(var: !25) -!25 = !DIGlobalVariable(name: "global_namespace_variable", linkageName: "_ZN2ns25global_namespace_variableE", scope: !18, file: !3, line: 27, type: !9, isLocal: false, isDefinition: true) +!25 = distinct !DIGlobalVariable(name: "global_namespace_variable", linkageName: "_ZN2ns25global_namespace_variableE", scope: !18, file: !3, line: 27, type: !9, isLocal: false, isDefinition: true, unit: !2) !26 = !DIGlobalVariableExpression(var: !27) -!27 = !DIGlobalVariable(name: "d", linkageName: "_ZN2ns1dE", scope: !18, file: !3, line: 31, type: !17, isLocal: false, isDefinition: true) +!27 = distinct !DIGlobalVariable(name: "d", linkageName: "_ZN2ns1dE", scope: !18, file: !3, line: 31, type: !17, isLocal: false, isDefinition: true, unit: !2) !28 = !DIGlobalVariableExpression(var: !29) -!29 = !DIGlobalVariable(name: "z", scope: !30, file: !3, line: 41, type: !9, isLocal: true, isDefinition: true) +!29 = distinct !DIGlobalVariable(name: "z", scope: !30, file: !3, line: 41, type: !9, isLocal: true, isDefinition: true, unit: !2) !30 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !3, file: !3, line: 40, type: !31, isLocal: false, isDefinition: true, scopeLine: 40, flags: DIFlagPrototyped, isOptimized: false, unit: !2, variables: !4) !31 = !DISubroutineType(types: !32) !32 = !{!33} !33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, align: 64) !34 = !DIGlobalVariableExpression(var: !35) -!35 = !DIGlobalVariable(name: "i", linkageName: "_ZN12_GLOBAL__N_11iE", scope: !36, file: !3, line: 37, type: !9, isLocal: true, isDefinition: true) +!35 = distinct !DIGlobalVariable(name: "i", linkageName: "_ZN12_GLOBAL__N_11iE", scope: !36, file: !3, line: 37, type: !9, isLocal: true, isDefinition: true, unit: !2) !36 = !DINamespace(scope: null, file: !3, line: 36) !37 = !DIGlobalVariableExpression(var: !38) -!38 = !DIGlobalVariable(name: "b", linkageName: "_ZN12_GLOBAL__N_15inner1bE", scope: !39, file: !3, line: 47, type: !9, isLocal: true, isDefinition: true) +!38 = distinct !DIGlobalVariable(name: "b", linkageName: "_ZN12_GLOBAL__N_15inner1bE", scope: !39, file: !3, line: 47, type: !9, isLocal: true, isDefinition: true, unit: !2) !39 = !DINamespace(name: "inner", scope: !36, file: !3, line: 46) !40 = !DIGlobalVariableExpression(var: !41) -!41 = !DIGlobalVariable(name: "c", linkageName: "_ZN5outer12_GLOBAL__N_11cE", scope: !42, file: !3, line: 53, type: !9, isLocal: true, isDefinition: true) +!41 = distinct !DIGlobalVariable(name: "c", linkageName: "_ZN5outer12_GLOBAL__N_11cE", scope: !42, file: !3, line: 53, type: !9, isLocal: true, isDefinition: true, unit: !2) !42 = !DINamespace(scope: !43, file: !3, line: 52) !43 = !DINamespace(name: "outer", scope: null, file: !3, line: 51) !44 = !{!45, !47} !45 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !2, entity: !46, line: 34) -!46 = !DIGlobalVariable(name: "global_namespace_variable_decl", linkageName: "_ZN2ns30global_namespace_variable_declE", scope: !18, file: !3, line: 28, type: !9, isLocal: false, isDefinition: false) +!46 = distinct !DIGlobalVariable(name: "global_namespace_variable_decl", linkageName: "_ZN2ns30global_namespace_variable_declE", scope: !18, file: !3, line: 28, type: !9, isLocal: false, isDefinition: false, unit: !2) !47 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !43, entity: !42, line: 43) !48 = !{i32 2, !"Dwarf Version", i32 4} !49 = !{i32 2, !"Debug Info Version", i32 3} Index: test/DebugInfo/X86/multiple-aranges.ll =================================================================== --- test/DebugInfo/X86/multiple-aranges.ll +++ test/DebugInfo/X86/multiple-aranges.ll @@ -42,11 +42,11 @@ !llvm.module.flags = !{!12, !13} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "kittens", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "kittens", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true, unit: !7) !2 = !DIFile(filename: "test1.c", directory: "/home/kayamon") !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !4 = !DIGlobalVariableExpression(var: !5) -!5 = !DIGlobalVariable(name: "rainbows", scope: null, file: !6, line: 1, type: !3, isLocal: false, isDefinition: true) +!5 = distinct !DIGlobalVariable(name: "rainbows", scope: null, file: !6, line: 1, type: !3, isLocal: false, isDefinition: true, unit: !10) !6 = !DIFile(filename: "test2.c", directory: "/home/kayamon") !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.4 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, retainedTypes: !8, globals: !9, imports: !8) !8 = !{} Index: test/DebugInfo/X86/split-global.ll =================================================================== --- test/DebugInfo/X86/split-global.ll +++ test/DebugInfo/X86/split-global.ll @@ -35,7 +35,7 @@ !llvm.dbg.cu = !{!1} !llvm.module.flags = !{!10, !11} -!0 = distinct !DIGlobalVariable(name: "point", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true) +!0 = distinct !DIGlobalVariable(name: "point", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true, unit: !1) !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4) !2 = !DIFile(filename: "g.c", directory: "/") !3 = !{} @@ -52,7 +52,7 @@ !14 = !DIGlobalVariableExpression(var: !16, expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32)) !15 = !DIGlobalVariableExpression(var: !16, expr: !DIExpression(DW_OP_constu, 2, DW_OP_stack_value, DW_OP_LLVM_fragment, 32, 32)) -!16 = distinct !DIGlobalVariable(name: "part_const", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true) +!16 = distinct !DIGlobalVariable(name: "part_const", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true, unit: !1) !17 = !DIGlobalVariableExpression(var: !19, expr: !DIExpression(DW_OP_constu, 1, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32)) !18 = !DIGlobalVariableExpression(var: !19, expr: !DIExpression(DW_OP_constu, 2, Index: test/DebugInfo/X86/stack-value-dwarf4.ll =================================================================== --- test/DebugInfo/X86/stack-value-dwarf4.ll +++ test/DebugInfo/X86/stack-value-dwarf4.ll @@ -29,10 +29,9 @@ !3 = !DIExpression(DW_OP_constu, 4, DW_OP_constu, 4, DW_OP_stack_value) !4 = !DIFile(filename: "", directory: "/") !5 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) - !6 = !{i32 2, !"Dwarf Version", i32 2} !7 = !{i32 2, !"Debug Info Version", i32 3} -!8 = distinct !DIGlobalVariable(name: "a", scope: null, isLocal: false, isDefinition: true, type: !5) +!8 = distinct !DIGlobalVariable(name: "a", scope: null, isLocal: false, isDefinition: true, type: !5, unit: !0) !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!6, !7} Index: test/DebugInfo/X86/static_member_array.ll =================================================================== --- test/DebugInfo/X86/static_member_array.ll +++ test/DebugInfo/X86/static_member_array.ll @@ -49,13 +49,13 @@ !llvm.ident = !{!22} !0 = distinct !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "fully_specified", linkageName: "_ZN1A15fully_specifiedE", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true, declaration: !15) +!1 = distinct !DIGlobalVariable(name: "fully_specified", linkageName: "_ZN1A15fully_specifiedE", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true, declaration: !15, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 4.0.0 (trunk 286129) (llvm/trunk 286128)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "static_member_array.cpp", directory: "/Volumes/Data/radar/28706946") !4 = !{} !5 = !{!0, !6} !6 = distinct !DIGlobalVariableExpression(var: !7) -!7 = !DIGlobalVariable(name: "smem", linkageName: "_ZN1A4smemE", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true, declaration: !12) +!7 = distinct !DIGlobalVariable(name: "smem", linkageName: "_ZN1A4smemE", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true, declaration: !12, unit: !2) !8 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 128, elements: !10) !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !10 = !{!11} Index: test/DebugInfo/X86/stringpool.ll =================================================================== --- test/DebugInfo/X86/stringpool.ll +++ test/DebugInfo/X86/stringpool.ll @@ -9,7 +9,7 @@ !llvm.module.flags = !{!7} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "yyyy", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "yyyy", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true, unit: !4) !2 = !DIFile(filename: "z.c", directory: "/home/nicholas") !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !4 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.1 (trunk 143009)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5) Index: test/DebugInfo/X86/tls.ll =================================================================== --- test/DebugInfo/X86/tls.ll +++ test/DebugInfo/X86/tls.ll @@ -112,11 +112,11 @@ !llvm.ident = !{!11} !0 = !DIGlobalVariableExpression(var: !1) -!1 = !DIGlobalVariable(name: "tls", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "tls", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true, unit: !6) !2 = !DIFile(filename: "tls.cpp", directory: "/tmp/dbginfo") !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !4 = !DIGlobalVariableExpression(var: !5) -!5 = !DIGlobalVariable(name: "glbl", scope: null, file: !2, line: 2, type: !3, isLocal: false, isDefinition: true) +!5 = distinct !DIGlobalVariable(name: "glbl", scope: null, file: !2, line: 2, type: !3, isLocal: false, isDefinition: true, unit: !6) !6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 3.5 ", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "-.dwo", emissionKind: FullDebug, enums: !7, retainedTypes: !7, globals: !8, imports: !7) !7 = !{} !8 = !{!0, !4} Index: test/Linker/debug-info-global-var.ll =================================================================== --- test/Linker/debug-info-global-var.ll +++ test/Linker/debug-info-global-var.ll @@ -22,4 +22,4 @@ !7 = !{i32 2, !"Debug Info Version", i32 3} !8 = !{i32 1, !"PIC Level", i32 2} !9 = !{!"clang version 4.0.0 (trunk 286129) (llvm/trunk 286128)"} -!10 = distinct !DIGlobalVariable(name: "g", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true) +!10 = distinct !DIGlobalVariable(name: "g", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true, unit: !1) Index: test/Transforms/ConstantMerge/merge-dbg.ll =================================================================== --- test/Transforms/ConstantMerge/merge-dbg.ll +++ test/Transforms/ConstantMerge/merge-dbg.ll @@ -19,7 +19,7 @@ ; CHECK: [[VB]] = distinct !DIGlobalVariable(name: "x" !0 = !DIGlobalVariableExpression(var: !1) -!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, unit: !2) !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 5.0.0 (trunk 297227) (llvm/trunk 297234)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) !3 = !DIFile(filename: "1.cc", directory: "/build") !4 = !{} @@ -29,4 +29,4 @@ !8 = !{i32 2, !"Debug Info Version", i32 3} !9 = !DIGlobalVariableExpression(var: !10) -!10 = distinct !DIGlobalVariable(name: "y", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!10 = distinct !DIGlobalVariable(name: "y", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, unit: !2) Index: test/Verifier/DIGlobalVariable-no-unit.ll =================================================================== --- /dev/null +++ test/Verifier/DIGlobalVariable-no-unit.ll @@ -0,0 +1,15 @@ +; RUN: not opt -S <%s 2>&1| FileCheck %s + +; CHECK: missing unit field +@g = common global i32 0, align 4, !dbg !3 + +!llvm.dbg.cu = !{!1} +!llvm.module.flags = !{!6, !7} + +!0 = distinct !DIGlobalVariable(name: "g", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true) +!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, emissionKind: FullDebug) +!2 = !DIFile(filename: "a.c", directory: "/") +!3 = !DIGlobalVariableExpression(var: !0) +!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!6 = !{i32 2, !"Dwarf Version", i32 4} +!7 = !{i32 2, !"Debug Info Version", i32 3} Index: test/tools/llvm-objdump/Hexagon/source-interleave-hexagon.ll =================================================================== --- test/tools/llvm-objdump/Hexagon/source-interleave-hexagon.ll +++ test/tools/llvm-objdump/Hexagon/source-interleave-hexagon.ll @@ -45,7 +45,7 @@ !1 = !DIFile(filename: "source-interleave-hexagon.c", directory: "SRC_COMPDIR") !2 = !{} !3 = !{!4} -!4 = !DIGlobalVariableExpression(var: !DIGlobalVariable(name: "a", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true)) +!4 = !DIGlobalVariableExpression(var: !24) !5 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !6 = !{i32 2, !"Dwarf Version", i32 4} !7 = !{i32 2, !"Debug Info Version", i32 3} @@ -65,6 +65,7 @@ !21 = !DILocation(line: 8, column: 15, scope: !14) !22 = !DILocation(line: 8, column: 13, scope: !14) !23 = !DILocation(line: 8, column: 3, scope: !14) +!24 = distinct !DIGlobalVariable(name: "a", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, unit: !0) ; LINES: main: ; LINES-NEXT: SRC_COMPDIR/source-interleave-hexagon.c:6 Index: test/tools/llvm-objdump/X86/source-interleave-x86_64.ll =================================================================== --- test/tools/llvm-objdump/X86/source-interleave-x86_64.ll +++ test/tools/llvm-objdump/X86/source-interleave-x86_64.ll @@ -46,7 +46,7 @@ !1 = !DIFile(filename: "source-interleave-x86_64.c", directory: "SRC_COMPDIR") !2 = !{} !3 = !{!4} -!4 = !DIGlobalVariableExpression(var: !DIGlobalVariable(name: "a", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true)) +!4 = distinct !DIGlobalVariable(name: "a", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true) !5 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !6 = !{i32 2, !"Dwarf Version", i32 4} !7 = !{i32 2, !"Debug Info Version", i32 3} Index: unittests/IR/MetadataTest.cpp =================================================================== --- unittests/IR/MetadataTest.cpp +++ unittests/IR/MetadataTest.cpp @@ -1848,10 +1848,11 @@ DIDerivedType *StaticDataMemberDeclaration = cast(getDerivedType()); uint32_t AlignInBits = 8; + DICompileUnit *Unit = getUnit(); - auto *N = DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, - Type, IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits); + auto *N = DIGlobalVariable::get( + Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, + IsDefinition, StaticDataMemberDeclaration, AlignInBits, Unit); EXPECT_EQ(dwarf::DW_TAG_variable, N->getTag()); EXPECT_EQ(Scope, N->getScope()); EXPECT_EQ(Name, N->getName()); @@ -1863,46 +1864,56 @@ EXPECT_EQ(IsDefinition, N->isDefinition()); EXPECT_EQ(StaticDataMemberDeclaration, N->getStaticDataMemberDeclaration()); EXPECT_EQ(AlignInBits, N->getAlignInBits()); + EXPECT_EQ(Unit, N->getUnit()); EXPECT_EQ(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits)); + StaticDataMemberDeclaration, AlignInBits, + Unit)); - EXPECT_NE(N, - DIGlobalVariable::get(Context, getSubprogram(), Name, LinkageName, - File, Line, Type, IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits)); + EXPECT_NE( + N, DIGlobalVariable::get(Context, getSubprogram(), Name, LinkageName, + File, Line, Type, IsLocalToUnit, IsDefinition, + StaticDataMemberDeclaration, AlignInBits, Unit)); EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, "other", LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits)); + StaticDataMemberDeclaration, AlignInBits, + Unit)); EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, "other", File, Line, Type, IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits)); - EXPECT_NE(N, - DIGlobalVariable::get(Context, Scope, Name, LinkageName, getFile(), - Line, Type, IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits)); - EXPECT_NE(N, - DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, - Line + 1, Type, IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits)); - EXPECT_NE(N, - DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, - getDerivedType(), IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits)); + StaticDataMemberDeclaration, AlignInBits, + Unit)); + EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, + getFile(), Line, Type, IsLocalToUnit, + IsDefinition, StaticDataMemberDeclaration, + AlignInBits, Unit)); + EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, + Line + 1, Type, IsLocalToUnit, + IsDefinition, StaticDataMemberDeclaration, + AlignInBits, Unit)); + EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, + Line, getDerivedType(), IsLocalToUnit, + IsDefinition, StaticDataMemberDeclaration, + AlignInBits, Unit)); EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, Type, !IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits)); + StaticDataMemberDeclaration, AlignInBits, + Unit)); EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, !IsDefinition, - StaticDataMemberDeclaration, AlignInBits)); + StaticDataMemberDeclaration, AlignInBits, + Unit)); EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, cast(getDerivedType()), - AlignInBits)); + AlignInBits, Unit)); EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration, - (AlignInBits << 1))); + (AlignInBits << 1), Unit)); + EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, + Line, Type, IsLocalToUnit, IsDefinition, + StaticDataMemberDeclaration, AlignInBits, + nullptr)); TempDIGlobalVariable Temp = N->clone(); EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); @@ -1924,13 +1935,14 @@ DIDerivedType *StaticDataMemberDeclaration = cast(getDerivedType()); uint32_t AlignInBits = 8; + DICompileUnit *Unit = getUnit(); auto *Var = DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits); + StaticDataMemberDeclaration, AlignInBits, Unit); auto *Var2 = DIGlobalVariable::get(Context, Scope, "other", LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, - StaticDataMemberDeclaration, AlignInBits); + StaticDataMemberDeclaration, AlignInBits, Unit); auto *N = DIGlobalVariableExpression::get(Context, Var, Expr); EXPECT_EQ(Var, N->getVariable());