diff --git a/docs/SourceLevelDebugging.rst b/docs/SourceLevelDebugging.rst index 5d7a528c2eb..f957a7dfd4a 100644 --- a/docs/SourceLevelDebugging.rst +++ b/docs/SourceLevelDebugging.rst @@ -567,7 +567,7 @@ Local variables metadata, ;; Reference to file where defined i32, ;; 24 bit - Line number where defined ;; 8 bit - Argument number. 1 indicates 1st argument. - metadata, ;; Type descriptor + metadata, ;; Reference to the type descriptor i32, ;; flags metadata ;; (optional) Reference to inline location } diff --git a/include/llvm/IR/DIBuilder.h b/include/llvm/IR/DIBuilder.h index a61726a7a32..40fa0950cd7 100644 --- a/include/llvm/IR/DIBuilder.h +++ b/include/llvm/IR/DIBuilder.h @@ -466,7 +466,7 @@ namespace llvm { /// @param Val llvm::Value of the variable. DIGlobalVariable createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo, - DIType Ty, bool isLocalToUnit, llvm::Value *Val); + DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val); /// \brief Create a new descriptor for the specified global. /// @param Name Name of the variable. @@ -479,7 +479,7 @@ namespace llvm { /// @param Val llvm::Value of the variable. DIGlobalVariable createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile File, - unsigned LineNo, DIType Ty, bool isLocalToUnit, + unsigned LineNo, DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val); /// createStaticVariable - Create a new descriptor for the specified @@ -497,7 +497,7 @@ namespace llvm { DIGlobalVariable createStaticVariable(DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile File, unsigned LineNo, - DIType Ty, bool isLocalToUnit, llvm::Value *Val, + DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val, MDNode *Decl = NULL); @@ -518,7 +518,7 @@ namespace llvm { DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNo, - DIType Ty, bool AlwaysPreserve = false, + DITypeRef Ty, bool AlwaysPreserve = false, unsigned Flags = 0, unsigned ArgNo = 0); @@ -537,7 +537,7 @@ namespace llvm { /// number. 1 indicates 1st argument. DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope, StringRef Name, DIFile F, unsigned LineNo, - DIType Ty, ArrayRef Addr, + DITypeRef Ty, ArrayRef Addr, unsigned ArgNo = 0); /// createFunction - Create a new descriptor for the specified subprogram. diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index f4d70ad3373..a8fb24565e6 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -224,6 +224,7 @@ template class DIRef { friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const; friend DIScopeRef DIScope::getContext() const; friend DIScopeRef DIScope::getRef() const; + friend class DIType; /// Val can be either a MDNode or a MDString, in the latter, /// MDString specifies the type identifier. @@ -284,6 +285,11 @@ protected: public: explicit DIType(const MDNode *N = 0) : DIScope(N) {} + operator DITypeRef () const { + assert(isType() && + "constructing DITypeRef from an MDNode that is not a type"); + return DITypeRef(&*getRef()); + } /// Verify - Verify that a type descriptor is well formed. bool Verify() const; @@ -616,7 +622,7 @@ public: } unsigned getLineNumber() const { return getUnsignedField(7); } - DIType getType() const { return getFieldAs(8); } + DITypeRef getType() const { return getFieldAs(8); } unsigned isLocalToUnit() const { return getUnsignedField(9); } unsigned isDefinition() const { return getUnsignedField(10); } @@ -648,7 +654,7 @@ public: unsigned L = getUnsignedField(4); return L >> 24; } - DIType getType() const { return getFieldAs(5); } + DITypeRef getType() const { return getFieldAs(5); } /// isArtificial - Return true if this variable is marked as "artificial". bool isArtificial() const { @@ -681,7 +687,9 @@ public: /// isBlockByrefVariable - Return true if the variable was declared as /// a "__block" variable (Apple Blocks). - bool isBlockByrefVariable() const { return getType().isBlockByrefStruct(); } + bool isBlockByrefVariable(const DITypeIdentifierMap &Map) const { + return (getType().resolve(Map)).isBlockByrefStruct(); + } /// isInlinedFnArgument - Return true if this variable provides debugging /// information for an inlined function arguments. diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 03906f0110b..ecd10460a59 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -115,11 +115,17 @@ template T DbgVariable::resolve(DIRef Ref) const { return DD->resolve(Ref); } +bool DbgVariable::isBlockByrefVariable() const { + assert(Var.isVariable() && "Invalid complex DbgVariable!"); + return Var.isBlockByrefVariable(DD->getTypeIdentifierMap()); +} + + DIType DbgVariable::getType() const { - DIType Ty = Var.getType(); + DIType Ty = Var.getType().resolve(DD->getTypeIdentifierMap()); // FIXME: isBlockByrefVariable should be reformulated in terms of complex // addresses instead. - if (Var.isBlockByrefVariable()) { + if (Var.isBlockByrefVariable(DD->getTypeIdentifierMap())) { /* Byref variables, in Blocks, are declared by the programmer as "SomeType VarName;", but the compiler creates a __Block_byref_x_VarName struct, and gives the variable VarName @@ -2301,7 +2307,7 @@ void DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry) { DIVariable DV(Entry.getVariable()); if (Entry.isInt()) { - DIBasicType BTy(DV.getType()); + DIBasicType BTy(resolve(DV.getType())); if (BTy.Verify() && (BTy.getEncoding() == dwarf::DW_ATE_signed || BTy.getEncoding() == dwarf::DW_ATE_signed_char)) { Streamer.EmitInt8(dwarf::DW_OP_consts, "DW_OP_consts"); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index 44eed9406fe..2f6c2546ed4 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -199,10 +199,7 @@ public: assert(Var.isVariable() && "Invalid complex DbgVariable!"); return Var.hasComplexAddress(); } - bool isBlockByrefVariable() const { - assert(Var.isVariable() && "Invalid complex DbgVariable!"); - return Var.isBlockByrefVariable(); - } + bool isBlockByrefVariable() const; unsigned getNumAddrElements() const { assert(Var.isVariable() && "Invalid complex DbgVariable!"); return Var.getNumAddrElements(); @@ -777,6 +774,11 @@ public: return Ref.resolve(TypeIdentifierMap); } + /// \brief Return the TypeIdentifierMap. + const DITypeIdentifierMap& getTypeIdentifierMap() const { + return TypeIdentifierMap; + } + /// Find the DwarfCompileUnit for the given CU Die. DwarfCompileUnit *lookupUnit(const DIE *CU) const { return CUDieMap.lookup(CU); diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 2eda435f86e..a7b43d80328 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1604,7 +1604,7 @@ void DwarfCompileUnit::createGlobalVariableDIE(DIGlobalVariable GV) { assert(GV.isGlobalVariable()); DIScope GVContext = GV.getContext(); - DIType GTy = GV.getType(); + DIType GTy = DD->resolve(GV.getType()); // If this is a static data member definition, some attributes belong // to the declaration DIE. diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index 634240c9458..8f3d979712a 100644 --- a/lib/IR/DIBuilder.cpp +++ b/lib/IR/DIBuilder.cpp @@ -927,7 +927,7 @@ DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile F, unsigned LineNumber, - DIType Ty, bool isLocalToUnit, + DITypeRef Ty, bool isLocalToUnit, Value *Val) { Value *Elts[] = { GetTagConstant(VMContext, dwarf::DW_TAG_variable), @@ -951,7 +951,8 @@ DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, /// \brief Create a new descriptor for the specified global. DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F, - unsigned LineNumber, DIType Ty, + unsigned LineNumber, + DITypeRef Ty, bool isLocalToUnit, Value *Val) { return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit, @@ -964,7 +965,8 @@ DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F, unsigned LineNumber, - DIType Ty, bool isLocalToUnit, + DITypeRef Ty, + bool isLocalToUnit, Value *Val, MDNode *Decl) { Value *Elts[] = { GetTagConstant(VMContext, dwarf::DW_TAG_variable), @@ -989,14 +991,12 @@ DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context, /// createVariable - Create a new descriptor for the specified variable. DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, StringRef Name, DIFile File, - unsigned LineNo, DIType Ty, + unsigned LineNo, DITypeRef Ty, bool AlwaysPreserve, unsigned Flags, unsigned ArgNo) { DIDescriptor Context(getNonCompileUnitScope(Scope)); assert((!Context || Context.isScope()) && "createLocalVariable should be called with a valid Context"); - assert(Ty.isType() && - "createLocalVariable should be called with a valid type"); Value *Elts[] = { GetTagConstant(VMContext, Tag), getNonCompileUnitScope(Scope), @@ -1027,7 +1027,8 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope, StringRef Name, DIFile F, unsigned LineNo, - DIType Ty, ArrayRef Addr, + DITypeRef Ty, + ArrayRef Addr, unsigned ArgNo) { SmallVector Elts; Elts.push_back(GetTagConstant(VMContext, Tag)); diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index d69138e057b..afeeb7b685b 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -541,10 +541,11 @@ bool DIGlobalVariable::Verify() const { if (getDisplayName().empty()) return false; - // Make sure context @ field 2 and type @ field 8 are MDNodes. + // Make sure context @ field 2 is an MDNode. if (!fieldIsMDNode(DbgNode, 2)) return false; - if (!fieldIsMDNode(DbgNode, 8)) + // Make sure that type @ field 8 is a DITypeRef. + if (!fieldIsTypeRef(DbgNode, 8)) return false; // Make sure StaticDataMemberDeclaration @ field 12 is MDNode. if (!fieldIsMDNode(DbgNode, 12)) @@ -558,10 +559,11 @@ bool DIVariable::Verify() const { if (!isVariable()) return false; - // Make sure context @ field 1 and type @ field 5 are MDNodes. + // Make sure context @ field 1 is an MDNode. if (!fieldIsMDNode(DbgNode, 1)) return false; - if (!fieldIsMDNode(DbgNode, 5)) + // Make sure that type @ field 5 is a DITypeRef. + if (!fieldIsTypeRef(DbgNode, 5)) return false; return DbgNode->getNumOperands() >= 8; } @@ -999,7 +1001,7 @@ void DebugInfoFinder::processModule(const Module &M) { DIGlobalVariable DIG(GVs.getElement(i)); if (addGlobalVariable(DIG)) { processScope(DIG.getContext()); - processType(DIG.getType()); + processType(DIG.getType().resolve(TypeIdentifierMap)); } } DIArray SPs = CU.getSubprograms(); @@ -1133,7 +1135,7 @@ void DebugInfoFinder::processDeclare(const Module &M, if (!NodesSeen.insert(DV)) return; processScope(DIVariable(N).getContext()); - processType(DIVariable(N).getType()); + processType(DIVariable(N).getType().resolve(TypeIdentifierMap)); } void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) { @@ -1149,7 +1151,7 @@ void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) { if (!NodesSeen.insert(DV)) return; processScope(DIVariable(N).getContext()); - processType(DIVariable(N).getType()); + processType(DIVariable(N).getType().resolve(TypeIdentifierMap)); } /// addType - Add type into Tys. diff --git a/test/Linker/type-unique-odr-a.ll b/test/Linker/type-unique-odr-a.ll index 3ab20bfb323..a1b8d28e645 100644 --- a/test/Linker/type-unique-odr-a.ll +++ b/test/Linker/type-unique-odr-a.ll @@ -93,6 +93,6 @@ attributes #1 = { nounwind readnone } !21 = metadata !{i32 1, metadata !"Debug Info Version", i32 1} !22 = metadata !{metadata !"clang version 3.5.0 "} !23 = metadata !{i32 11, i32 0, metadata !15, null} -!24 = metadata !{i32 786688, metadata !19, metadata !"a", metadata !16, i32 8, metadata !4, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [a] [line 8] +!24 = metadata !{i32 786688, metadata !19, metadata !"a", metadata !16, i32 8, metadata !"_ZTS1A", i32 0, i32 0} ; [ DW_TAG_auto_variable ] [a] [line 8] !25 = metadata !{i32 8, i32 0, metadata !19, null} ; [ DW_TAG_imported_declaration ] !26 = metadata !{i32 9, i32 0, metadata !19, null}