https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/200649
TrackingMDNodeRef is expensive and the tracking functionality is only used when parsing textual LLVM IR. Therefore, store a plain DILocation pointer in DebugLoc and update the debug locs explicitly when parsing finishes. Invalid debug metadata now fails directly at parsing and not (just) later when verifying. A consequence is that old-style DILocations cannot be parsed from textual IR anymore. While work on changing DILocation to no longer be metadata is on the way, it is going to take a while to finish, we can get this immediate performance and max-rss improvement earlier. >From c7a7e13a66c060a29d93a2787f1002ce8c25c6e8 Mon Sep 17 00:00:00 2001 From: Alexis Engelke <[email protected]> Date: Sun, 31 May 2026 09:46:47 +0000 Subject: [PATCH] [spr] initial version Created using spr 1.3.8-wip --- clang/lib/CodeGen/CGClass.cpp | 2 +- clang/lib/CodeGen/CGDebugInfo.h | 6 ++-- llvm/include/llvm/AsmParser/LLParser.h | 5 ++++ llvm/include/llvm/IR/DebugLoc.h | 27 ++++++------------ .../include/llvm/IR/DebugProgramInstruction.h | 15 ++++------ llvm/lib/AsmParser/LLParser.cpp | 28 +++++++++++++++++-- llvm/lib/CodeGen/MIRParser/MIParser.cpp | 2 +- llvm/lib/IR/AutoUpgrade.cpp | 20 ++++--------- llvm/lib/IR/Core.cpp | 6 ++-- llvm/lib/IR/DebugInfo.cpp | 2 +- llvm/lib/IR/DebugLoc.cpp | 8 ++---- llvm/lib/IR/DebugProgramInstruction.cpp | 17 ++++++----- llvm/lib/IR/Metadata.cpp | 2 +- .../dbg-declare-invalid-debug-loc.ll | 10 ++----- llvm/test/Assembler/dbg.ll | 12 ++++++++ .../CodeGen/X86/stack-protector-dbginfo.ll | 2 +- llvm/test/DebugInfo/Generic/2009-10-16-Phi.ll | 3 +- .../DebugInfo/Generic/location-verifier.ll | 7 ++--- llvm/test/DebugInfo/MIR/X86/regcoalescer.mir | 2 +- .../MergeFunc/mergefunc-preserve-nonnull.ll | 3 +- .../llvm.dbg.intrinsic-dbg-attachment.ll | 16 ----------- llvm/test/Verifier/dbg.ll | 5 +--- .../test/tools/llvm-reduce/remove-metadata.ll | 6 ++-- .../Analysis/IRSimilarityIdentifierTest.cpp | 12 ++++---- llvm/unittests/CodeGen/MachineInstrTest.cpp | 8 ++++-- llvm/unittests/IR/InstructionsTest.cpp | 4 +-- llvm/unittests/SandboxIR/SandboxIRTest.cpp | 2 +- 27 files changed, 115 insertions(+), 117 deletions(-) rename llvm/test/{Verifier => Assembler}/dbg-declare-invalid-debug-loc.ll (83%) create mode 100644 llvm/test/Assembler/dbg.ll diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index de11e8bca43f1..d6aa877617515 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -1796,7 +1796,7 @@ class DestroyField final : public EHScopeStack::Cleanup { class DeclAsInlineDebugLocation { CGDebugInfo *DI; - llvm::MDNode *InlinedAt; + llvm::DILocation *InlinedAt; std::optional<ApplyDebugLocation> Location; public: diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 62b1afa224ffc..4c385c26efc4e 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -72,7 +72,7 @@ class CGDebugInfo { llvm::DIFile *CurLocFile = nullptr; unsigned CurLocLine = 0; unsigned CurLocColumn = 0; - llvm::MDNode *CurInlinedAt = nullptr; + llvm::DILocation *CurInlinedAt = nullptr; llvm::DIType *VTablePtrType = nullptr; llvm::DIType *ClassTy = nullptr; llvm::DICompositeType *ObjTy = nullptr; @@ -477,10 +477,10 @@ class CGDebugInfo { /// Update the current inline scope. All subsequent calls to \p EmitLocation /// will create a location with this inlinedAt field. - void setInlinedAt(llvm::MDNode *InlinedAt) { CurInlinedAt = InlinedAt; } + void setInlinedAt(llvm::DILocation *InlinedAt) { CurInlinedAt = InlinedAt; } /// \return the current inline scope. - llvm::MDNode *getInlinedAt() const { return CurInlinedAt; } + llvm::DILocation *getInlinedAt() const { return CurInlinedAt; } // Converts a SourceLocation to a DebugLoc llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Loc); diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h index 938a45951e074..b545b7886e26e 100644 --- a/llvm/include/llvm/AsmParser/LLParser.h +++ b/llvm/include/llvm/AsmParser/LLParser.h @@ -185,6 +185,11 @@ namespace llvm { /// scoped local types. SmallVector<DISubprogram *> NewDistinctSPs; + SmallVector<std::tuple<LocTy, DbgRecord *, TrackingMDNodeRef>> + PendingDbgRecords; + SmallVector<std::tuple<LocTy, Instruction *, TrackingMDNodeRef>> + PendingDbgInsts; + /// Only the llvm-as tool may set this to false to bypass /// UpgradeDebuginfo so it can generate broken bitcode. bool UpgradeDebugInfo; diff --git a/llvm/include/llvm/IR/DebugLoc.h b/llvm/include/llvm/IR/DebugLoc.h index 484adbb6e6a6c..5a6081f745f92 100644 --- a/llvm/include/llvm/IR/DebugLoc.h +++ b/llvm/include/llvm/IR/DebugLoc.h @@ -108,35 +108,24 @@ template <> struct simplify_type<const DILocAndCoverageTracking> { } }; -using DebugLocTrackingRef = DILocAndCoverageTracking; +using DebugLocRef = DILocAndCoverageTracking; #else -using DebugLocTrackingRef = TrackingMDNodeRef; +using DebugLocRef = DILocation *; #endif // LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE /// A debug info location. /// -/// This class is a wrapper around a tracking reference to an \a DILocation +/// This class is a wrapper around an \a DILocation /// pointer. /// /// To avoid extra includes, \a DebugLoc doubles the \a DILocation API with a /// one based on relatively opaque \a MDNode pointers. class DebugLoc { - - DebugLocTrackingRef Loc; + DebugLocRef Loc = {}; public: - DebugLoc() = default; - /// Construct from an \a DILocation. - LLVM_ABI DebugLoc(const DILocation *L); - - /// Construct from an \a MDNode. - /// - /// Note: if \c N is not an \a DILocation, a verifier check will fail, and - /// accessors will crash. However, construction from other nodes is - /// supported in order to handle forward references when reading textual - /// IR. - LLVM_ABI explicit DebugLoc(const MDNode *N); + DebugLoc(const DILocation *L = nullptr) : Loc(const_cast<DILocation *>(L)) {} #if LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE DebugLoc(DebugLocKind Kind) : Loc(Kind) {} @@ -225,7 +214,7 @@ class DebugLoc { /// /// \pre !*this or \c isa<DILocation>(getAsMDNode()). /// @{ - LLVM_ABI DILocation *get() const; + DILocation *get() const { return Loc; } operator DILocation *() const { return get(); } DILocation *operator->() const { return get(); } DILocation &operator*() const { return *get(); } @@ -240,7 +229,7 @@ class DebugLoc { explicit operator bool() const { return Loc; } /// Check whether this has a trivial destructor. - bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); } + bool hasTrivialDestructor() const { return true; } enum { ReplaceLastInlinedAt = true }; /// Rebuild the entire inlined-at chain for this instruction so that the top @@ -287,7 +276,7 @@ class DebugLoc { LLVM_ABI DebugLoc getFnDebugLoc() const; /// Return \c this as a bar \a MDNode. - MDNode *getAsMDNode() const { return Loc; } + LLVM_ABI MDNode *getAsMDNode() const; /// Check if the DebugLoc corresponds to an implicit code. LLVM_ABI bool isImplicitCode() const; diff --git a/llvm/include/llvm/IR/DebugProgramInstruction.h b/llvm/include/llvm/IR/DebugProgramInstruction.h index 20f11b4fb8bac..b7cedc60689c7 100644 --- a/llvm/include/llvm/IR/DebugProgramInstruction.h +++ b/llvm/include/llvm/IR/DebugProgramInstruction.h @@ -240,7 +240,7 @@ class DbgLabelRecord : public DbgRecord { /// This constructor intentionally left private, so that it is only called via /// "createUnresolvedDbgLabelRecord", which clearly expresses that it is for /// parsing only. - DbgLabelRecord(MDNode *Label, MDNode *DL); + DbgLabelRecord(MDNode *Label); public: LLVM_ABI DbgLabelRecord(DILabel *Label, DebugLoc DL); @@ -249,8 +249,7 @@ class DbgLabelRecord : public DbgRecord { /// MDNodes. Trying to access the resulting DbgLabelRecord's fields before /// they are resolved, or if they resolve to the wrong type, will result in a /// crash. - LLVM_ABI static DbgLabelRecord *createUnresolvedDbgLabelRecord(MDNode *Label, - MDNode *DL); + LLVM_ABI static DbgLabelRecord *createUnresolvedDbgLabelRecord(MDNode *Label); LLVM_ABI DbgLabelRecord *clone() const; LLVM_ABI void print(raw_ostream &O, bool IsForDebug = false) const; @@ -323,7 +322,7 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser { /// depending on which Type is passed. DbgVariableRecord(LocationType Type, Metadata *Val, MDNode *Variable, MDNode *Expression, MDNode *AssignID, Metadata *Address, - MDNode *AddressExpression, MDNode *DI); + MDNode *AddressExpression); public: /// Used to create DbgVariableRecords during parsing, where some metadata @@ -333,11 +332,9 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser { /// for all types of DbgVariableRecords for simplicity while parsing, but /// asserts if any necessary fields are empty or unused fields are not empty, /// i.e. if the #dbg_assign fields are used for a non-dbg-assign type. - LLVM_ABI static DbgVariableRecord * - createUnresolvedDbgVariableRecord(LocationType Type, Metadata *Val, - MDNode *Variable, MDNode *Expression, - MDNode *AssignID, Metadata *Address, - MDNode *AddressExpression, MDNode *DI); + LLVM_ABI static DbgVariableRecord *createUnresolvedDbgVariableRecord( + LocationType Type, Metadata *Val, MDNode *Variable, MDNode *Expression, + MDNode *AssignID, Metadata *Address, MDNode *AddressExpression); LLVM_ABI static DbgVariableRecord * createDVRAssign(Value *Val, DILocalVariable *Variable, diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index b9c36c28d04cd..848132538b450 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -188,6 +188,11 @@ void LLParser::dropUnknownMetadataReferences() { for (GlobalVariable &GV : M->globals()) GV.eraseMetadataIf(Pred); + llvm::erase_if(PendingDbgRecords, + [](const auto &E) { return std::get<2>(E)->isTemporary(); }); + llvm::erase_if(PendingDbgInsts, + [](const auto &E) { return std::get<2>(E)->isTemporary(); }); + for (const auto &[ID, Info] : make_early_inc_range(ForwardRefMDNodes)) { // Check whether there is only a single use left, which would be in our // own NumberedMetadata. @@ -425,6 +430,20 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { "use of undefined metadata '!" + Twine(ForwardRefMDNodes.begin()->first) + "'"); + // Set debug locations. + for (auto [Loc, DR, MD] : PendingDbgRecords) { + if (auto *DI = dyn_cast<DILocation>(MD)) + DR->setDebugLoc(DebugLoc(DI)); + else + return error(Loc, "invalid debug location"); + } + for (auto [Loc, I, MD] : PendingDbgInsts) { + if (auto *DI = dyn_cast<DILocation>(MD)) + I->setDebugLoc(DebugLoc(DI)); + else + return error(Loc, "invalid !dbg metadata"); + } + // Resolve metadata cycles. for (auto &N : NumberedMetadata) { if (N.second && !N.second->isResolved()) @@ -2407,11 +2426,14 @@ bool LLParser::parseInstructionMetadata(Instruction &Inst) { unsigned MDK; MDNode *N; + auto Loc = Lex.getLoc(); if (parseMetadataAttachment(MDK, N)) return true; if (MDK == LLVMContext::MD_DIAssignID) TempDIAssignIDAttachments[N].push_back(&Inst); + else if (MDK == LLVMContext::MD_dbg) + PendingDbgInsts.emplace_back(Loc, &Inst, N); else Inst.setMetadata(MDK, N); @@ -7479,7 +7501,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) { return true; if (parseToken(lltok::rparen, "Expected ')' here")) return true; - DR = DbgLabelRecord::createUnresolvedDbgLabelRecord(Label, DbgLoc); + DR = DbgLabelRecord::createUnresolvedDbgLabelRecord(Label); + PendingDbgRecords.emplace_back(DVRLoc, DR, DbgLoc); return false; } @@ -7547,7 +7570,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) { return true; DR = DbgVariableRecord::createUnresolvedDbgVariableRecord( ValueType, ValLocMD, Variable, Expression, AssignID, AddressLocation, - AddressExpression, DebugLoc); + AddressExpression); + PendingDbgRecords.emplace_back(DVRLoc, DR, DebugLoc); return false; } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 6c646787ae623..206eb22a633e4 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -1198,7 +1198,7 @@ bool MIParser::parse(MachineInstr *&MI) { } if (!isa<DILocation>(Node)) return error("referenced metadata is not a DILocation"); - DebugLocation = DebugLoc(Node); + DebugLocation = DebugLoc(cast<DILocation>(Node)); } // Parse the machine memory operands. diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index a3699344e918a..86a8a3ec06ff3 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -4894,32 +4894,24 @@ static Metadata *unwrapMAVMetadataOp(CallBase *CI, unsigned Op) { return nullptr; } -static MDNode *getDebugLocSafe(const Instruction *I) { - // The MDNode attached to this instruction might not be the correct type, - // as the verifier has not yet be run. Fetch it as a bare MDNode. - return I->getDebugLoc().getAsMDNode(); -} - /// Convert debug intrinsic calls to non-instruction debug records. /// \p Name - Final part of the intrinsic name, e.g. 'value' in llvm.dbg.value. /// \p CI - The debug intrinsic call. static void upgradeDbgIntrinsicToDbgRecord(StringRef Name, CallBase *CI) { DbgRecord *DR = nullptr; if (Name == "label") { - DR = DbgLabelRecord::createUnresolvedDbgLabelRecord(unwrapMAVOp(CI, 0), - CI->getDebugLoc()); + DR = DbgLabelRecord::createUnresolvedDbgLabelRecord(unwrapMAVOp(CI, 0)); } else if (Name == "assign") { DR = DbgVariableRecord::createUnresolvedDbgVariableRecord( DbgVariableRecord::LocationType::Assign, unwrapMAVMetadataOp(CI, 0), unwrapMAVOp(CI, 1), unwrapMAVOp(CI, 2), unwrapMAVOp(CI, 3), unwrapMAVMetadataOp(CI, 4), /*The address is a Value ref, it will be stored as a Metadata */ - unwrapMAVOp(CI, 5), getDebugLocSafe(CI)); + unwrapMAVOp(CI, 5)); } else if (Name == "declare") { DR = DbgVariableRecord::createUnresolvedDbgVariableRecord( DbgVariableRecord::LocationType::Declare, unwrapMAVMetadataOp(CI, 0), - unwrapMAVOp(CI, 1), unwrapMAVOp(CI, 2), nullptr, nullptr, nullptr, - getDebugLocSafe(CI)); + unwrapMAVOp(CI, 1), unwrapMAVOp(CI, 2), nullptr, nullptr, nullptr); } else if (Name == "addr") { // Upgrade dbg.addr to dbg.value with DW_OP_deref. MDNode *ExprNode = unwrapMAVOp(CI, 2); @@ -4930,8 +4922,7 @@ static void upgradeDbgIntrinsicToDbgRecord(StringRef Name, CallBase *CI) { } DR = DbgVariableRecord::createUnresolvedDbgVariableRecord( DbgVariableRecord::LocationType::Value, unwrapMAVMetadataOp(CI, 0), - unwrapMAVOp(CI, 1), ExprNode, nullptr, nullptr, nullptr, - getDebugLocSafe(CI)); + unwrapMAVOp(CI, 1), ExprNode, nullptr, nullptr, nullptr); } else if (Name == "value") { // An old version of dbg.value had an extra offset argument. unsigned VarOp = 1; @@ -4947,8 +4938,9 @@ static void upgradeDbgIntrinsicToDbgRecord(StringRef Name, CallBase *CI) { DR = DbgVariableRecord::createUnresolvedDbgVariableRecord( DbgVariableRecord::LocationType::Value, unwrapMAVMetadataOp(CI, 0), unwrapMAVOp(CI, VarOp), unwrapMAVOp(CI, ExprOp), nullptr, nullptr, - nullptr, getDebugLocSafe(CI)); + nullptr); } + DR->setDebugLoc(CI->getDebugLoc()); assert(DR && "Unhandled intrinsic kind in upgrade to DbgRecord"); CI->getParent()->insertDbgRecordBefore(DR, CI->getIterator()); } diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 5e6b03d01b6ba..e64341aa0d1d7 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -3486,14 +3486,14 @@ LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder) { void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc) { if (Loc) - unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(unwrap<MDNode>(Loc))); + unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(unwrap<DILocation>(Loc))); else unwrap(Builder)->SetCurrentDebugLocation(DebugLoc()); } void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) { - MDNode *Loc = - L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr; + DILocation *Loc = + L ? cast<DILocation>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr; unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(Loc)); } diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index f65973f2b5735..7889de7ebb49a 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -1990,7 +1990,7 @@ LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst) { void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc) { if (Loc) - unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc(unwrap<MDNode>(Loc))); + unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc(unwrap<DILocation>(Loc))); else unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc()); } diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp index a3c98aec98c81..6aacd8075168e 100644 --- a/llvm/lib/IR/DebugLoc.cpp +++ b/llvm/lib/IR/DebugLoc.cpp @@ -42,12 +42,6 @@ DILocAndCoverageTracking::DILocAndCoverageTracking(const DILocation *L) //===----------------------------------------------------------------------===// // DebugLoc Implementation //===----------------------------------------------------------------------===// -DebugLoc::DebugLoc(const DILocation *L) : Loc(const_cast<DILocation *>(L)) {} -DebugLoc::DebugLoc(const MDNode *L) : Loc(const_cast<MDNode *>(L)) {} - -DILocation *DebugLoc::get() const { - return cast_or_null<DILocation>(Loc.get()); -} unsigned DebugLoc::getLine() const { assert(get() && "Expected valid DebugLoc"); @@ -82,6 +76,8 @@ DebugLoc DebugLoc::getFnDebugLoc() const { return DebugLoc(); } +MDNode *DebugLoc::getAsMDNode() const { return Loc; } + bool DebugLoc::isImplicitCode() const { if (DILocation *Loc = get()) return Loc->isImplicitCode(); diff --git a/llvm/lib/IR/DebugProgramInstruction.cpp b/llvm/lib/IR/DebugProgramInstruction.cpp index 9efa3c71c0bb8..98335728665ba 100644 --- a/llvm/lib/IR/DebugProgramInstruction.cpp +++ b/llvm/lib/IR/DebugProgramInstruction.cpp @@ -145,8 +145,8 @@ DbgRecord::createDebugIntrinsic(Module *M, Instruction *InsertBefore) const { llvm_unreachable("unsupported DbgRecord kind"); } -DbgLabelRecord::DbgLabelRecord(MDNode *Label, MDNode *DL) - : DbgRecord(LabelKind, DebugLoc(DL)), Label(Label) { +DbgLabelRecord::DbgLabelRecord(MDNode *Label) + : DbgRecord(LabelKind, DebugLoc()), Label(Label) { assert(Label && "Unexpected nullptr"); assert((isa<DILabel>(Label) || Label->isTemporary()) && "Label type must be or resolve to a DILabel"); @@ -156,26 +156,25 @@ DbgLabelRecord::DbgLabelRecord(DILabel *Label, DebugLoc DL) assert(Label && "Unexpected nullptr"); } -DbgLabelRecord *DbgLabelRecord::createUnresolvedDbgLabelRecord(MDNode *Label, - MDNode *DL) { - return new DbgLabelRecord(Label, DL); +DbgLabelRecord *DbgLabelRecord::createUnresolvedDbgLabelRecord(MDNode *Label) { + return new DbgLabelRecord(Label); } DbgVariableRecord::DbgVariableRecord(DbgVariableRecord::LocationType Type, Metadata *Val, MDNode *Variable, MDNode *Expression, MDNode *AssignID, Metadata *Address, - MDNode *AddressExpression, MDNode *DI) - : DbgRecord(ValueKind, DebugLoc(DI)), + MDNode *AddressExpression) + : DbgRecord(ValueKind, DebugLoc()), DebugValueUser({Val, Address, AssignID}), Type(Type), Variable(Variable), Expression(Expression), AddressExpression(AddressExpression) {} DbgVariableRecord *DbgVariableRecord::createUnresolvedDbgVariableRecord( DbgVariableRecord::LocationType Type, Metadata *Val, MDNode *Variable, MDNode *Expression, MDNode *AssignID, Metadata *Address, - MDNode *AddressExpression, MDNode *DI) { + MDNode *AddressExpression) { return new DbgVariableRecord(Type, Val, Variable, Expression, AssignID, - Address, AddressExpression, DI); + Address, AddressExpression); } DbgVariableRecord * diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 82f224438eec5..491c788fc4445 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -1754,7 +1754,7 @@ void Instruction::setMetadata(unsigned KindID, MDNode *Node) { // Handle 'dbg' as a special case since it is not stored in the hash table. if (KindID == LLVMContext::MD_dbg) { - DbgLoc = DebugLoc(Node); + DbgLoc = DebugLoc(cast_or_null<DILocation>(Node)); return; } diff --git a/llvm/test/Verifier/dbg-declare-invalid-debug-loc.ll b/llvm/test/Assembler/dbg-declare-invalid-debug-loc.ll similarity index 83% rename from llvm/test/Verifier/dbg-declare-invalid-debug-loc.ll rename to llvm/test/Assembler/dbg-declare-invalid-debug-loc.ll index c521a9b8eb11b..534bee253c6f8 100644 --- a/llvm/test/Verifier/dbg-declare-invalid-debug-loc.ll +++ b/llvm/test/Assembler/dbg-declare-invalid-debug-loc.ll @@ -1,14 +1,10 @@ -; RUN: opt %s -o /dev/null -S 2>&1 | FileCheck %s +; RUN: not opt %s -o /dev/null -S 2>&1 | FileCheck %s ; ; The last dbg.declare intrinsic in this file has an illegal DILocation -- this ; needs to pass through the autoupgrade to #dbg_declare process and then get -; caught by the verifier. +; caught at the end of the parser. ; -; CHECK: invalid #dbg record DILocation -; CHECK-NEXT: #dbg_declare(ptr %1, ![[VAR:[0-9]+]], !DIExpression(), ![[PROG:[0-9]+]]) -; CHECK-NEXT: ![[PROG]] = distinct !DISubprogram(name: "IgnoreIntrinsicTest", -; CHECK-NEXT: label %0 -; CHECK-NEXT: ptr @IgnoreIntrinsicTest +; CHECK: invalid !dbg metadata declare void @llvm.dbg.declare(metadata, metadata, metadata) diff --git a/llvm/test/Assembler/dbg.ll b/llvm/test/Assembler/dbg.ll new file mode 100644 index 0000000000000..63d9c0aa382dd --- /dev/null +++ b/llvm/test/Assembler/dbg.ll @@ -0,0 +1,12 @@ +; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s + +define void @foo() { + ret void, !dbg !{} +; CHECK: invalid !dbg metadata +} + +!llvm.module.flags = !{!0} +!0 = !{i32 2, !"Debug Info Version", i32 3} +!1 = distinct !DISubprogram(type: !3) +!2 = !{null} +!3 = !DISubroutineType(types: !2) diff --git a/llvm/test/CodeGen/X86/stack-protector-dbginfo.ll b/llvm/test/CodeGen/X86/stack-protector-dbginfo.ll index 27ca9fd47e085..a001ab5dd9b6b 100644 --- a/llvm/test/CodeGen/X86/stack-protector-dbginfo.ll +++ b/llvm/test/CodeGen/X86/stack-protector-dbginfo.ll @@ -21,7 +21,7 @@ entry: define i32 @IgnoreIntrinsicTest() #1 { ; IGNORE_INTRIN: IgnoreIntrinsicTest: %1 = alloca i32, align 4 - call void @llvm.dbg.declare(metadata ptr %1, metadata !73, metadata !DIExpression()), !dbg !74 + call void @llvm.dbg.declare(metadata ptr %1, metadata !73, metadata !DIExpression()), !dbg !75 store volatile i32 1, ptr %1, align 4 %2 = load volatile i32, ptr %1, align 4 %3 = mul nsw i32 %2, 42 diff --git a/llvm/test/DebugInfo/Generic/2009-10-16-Phi.ll b/llvm/test/DebugInfo/Generic/2009-10-16-Phi.ll index e14653f6fcf28..2acb7389e0c8b 100644 --- a/llvm/test/DebugInfo/Generic/2009-10-16-Phi.ll +++ b/llvm/test/DebugInfo/Generic/2009-10-16-Phi.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as %s -disable-output +; RUN: not llvm-as %s -disable-output 2>&1 | FileCheck %s define i32 @foo() { E: @@ -6,6 +6,7 @@ E: B1: br label %B2 B2: +; CHECK: error: invalid !dbg metadata %0 = phi i32 [ 0, %E ], [ 1, %B1 ], !dbg !0 ret i32 %0 } diff --git a/llvm/test/DebugInfo/Generic/location-verifier.ll b/llvm/test/DebugInfo/Generic/location-verifier.ll index 19b510ded3cb7..fccf094719846 100644 --- a/llvm/test/DebugInfo/Generic/location-verifier.ll +++ b/llvm/test/DebugInfo/Generic/location-verifier.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as -disable-output -o - < %s 2>&1 | FileCheck %s +; RUN: not llvm-as -disable-output -o - < %s 2>&1 | FileCheck %s ; ModuleID = 'test.c' target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.10.0" @@ -27,7 +27,6 @@ attributes #0 = { nounwind ssp uwtable } !10 = !{i32 2, !"Debug Info Version", i32 3} !11 = !{i32 1, !"PIC Level", i32 2} !12 = !{!"clang version 3.7.0 "} -; An old-style DILocation should not pass verify. -; CHECK: invalid !dbg metadata attachment +; An old-style DILocation should not parse. +; CHECK: invalid !dbg metadata !13 = !{i32 2, i32 2, !4, null} -; CHECK: warning: ignoring invalid debug info diff --git a/llvm/test/DebugInfo/MIR/X86/regcoalescer.mir b/llvm/test/DebugInfo/MIR/X86/regcoalescer.mir index 30c3bd27b0a2a..25d7048df3627 100644 --- a/llvm/test/DebugInfo/MIR/X86/regcoalescer.mir +++ b/llvm/test/DebugInfo/MIR/X86/regcoalescer.mir @@ -6,7 +6,7 @@ define i32 @main() local_unnamed_addr !dbg !14 { entry: - %shl = shl i32 undef, undef, !dbg !19 + %shl = shl i32 undef, undef, !dbg !20 tail call void @llvm.dbg.value(metadata i32 %shl, metadata !18, metadata !DIExpression()), !dbg !20 ret i32 %shl, !dbg !21 } diff --git a/llvm/test/Transforms/MergeFunc/mergefunc-preserve-nonnull.ll b/llvm/test/Transforms/MergeFunc/mergefunc-preserve-nonnull.ll index 3481d53b626fc..544bba4909ea1 100644 --- a/llvm/test/Transforms/MergeFunc/mergefunc-preserve-nonnull.ll +++ b/llvm/test/Transforms/MergeFunc/mergefunc-preserve-nonnull.ll @@ -55,7 +55,7 @@ define void @noundef_dbg(ptr %0, ptr %1) { ; CHECK-NEXT: tail call void @noundef(ptr [[TMP0:%.*]], ptr [[TMP1:%.*]]) ; CHECK-NEXT: ret void ; - %3 = load ptr, ptr %1, align 8, !noundef !0, !dbg !1 + %3 = load ptr, ptr %1, align 8, !noundef !0, !dbg !8 store ptr %3, ptr %0, align 8 ret void } @@ -79,3 +79,4 @@ define void @noalias_2(ptr %0, ptr %1) { !5 = !{!5} !6 = !{!6, !5} !7 = !{!6} +!8 = !DILocation(line: 1, column: 1, scope: !{}) diff --git a/llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll b/llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll index db1f62c07da74..b1d70e2f975c4 100644 --- a/llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll +++ b/llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll @@ -1,22 +1,6 @@ ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s define void @foo() { entry: - #dbg_value( - ptr undef, - !DILocalVariable(scope: !1), - !DIExpression(), - !{}) -; CHECK-LABEL: invalid #dbg record DILocation -; CHECK-NEXT: #dbg_value({{.*}}) - - #dbg_declare( - ptr undef, - !DILocalVariable(scope: !1), - !DIExpression(), - !{}) -; CHECK-LABEL: invalid #dbg record DILocation -; CHECK-NEXT: #dbg_declare({{.*}}) - #dbg_value( ptr undef, !DILocalVariable(scope: !1), diff --git a/llvm/test/Verifier/dbg.ll b/llvm/test/Verifier/dbg.ll index 20958e9ede0b1..0202c1346cc0a 100644 --- a/llvm/test/Verifier/dbg.ll +++ b/llvm/test/Verifier/dbg.ll @@ -8,10 +8,7 @@ entry: ; CHECK-NEXT: ![[IA]] = !{} exit: - ret void, !dbg !{} -; CHECK: invalid !dbg metadata attachment -; CHECK-NEXT: ret void, !dbg ![[LOC:[0-9]+]] -; CHECK-NEXT: ![[LOC]] = !{} + ret void } ; CHECK: warning: ignoring invalid debug info diff --git a/llvm/test/tools/llvm-reduce/remove-metadata.ll b/llvm/test/tools/llvm-reduce/remove-metadata.ll index 3ff2d8b2d6848..ae86277642fed 100644 --- a/llvm/test/tools/llvm-reduce/remove-metadata.ll +++ b/llvm/test/tools/llvm-reduce/remove-metadata.ll @@ -7,10 +7,10 @@ ; RUN: llvm-reduce -abort-on-invalid-reduction --test %python --test-arg %p/Inputs/remove-metadata.py %s -o %t ; RUN: FileCheck --implicit-check-not=! %s < %t -@global = global i32 0, !dbg !0 +@global = global i32 0, !foo !0 -define void @main() !dbg !0 { - ret void, !dbg !0 +define void @main() !foo !0 { + ret void, !foo !0 } !uninteresting = !{!0} diff --git a/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp b/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp index a4187c242870d..c74f9c63af219 100644 --- a/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp +++ b/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp @@ -1318,12 +1318,13 @@ TEST(IRInstructionMapper, DebugInfoInvisible) { define i32 @f(i32 %a, i32 %b) { then: %0 = add i32 %a, %b - #dbg_value(i32 0, !0, !0, !0) + #dbg_value(i32 0, !0, !0, !1) %1 = add i32 %a, %b ret i32 0 } - !0 = distinct !{!"test\00", i32 10})"; + !0 = distinct !{!"test\00", i32 10} + !1 = !DILocation(line: 1, column: 1, scope: !{}))"; LLVMContext Context; std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString); @@ -1925,12 +1926,12 @@ TEST(IRSimilarityCandidate, IdenticalWithDebug) { define i32 @f(i32 %a, i32 %b) { bb0: %0 = add i32 %a, %b - #dbg_value(i32 0, !0, !0, !0) + #dbg_value(i32 0, !0, !0, !2) %1 = add i32 %b, %a ret i32 0 bb1: %2 = add i32 %a, %b - #dbg_value(i32 1, !1, !1, !1) + #dbg_value(i32 1, !1, !1, !2) %3 = add i32 %b, %a ret i32 0 bb2: @@ -1940,7 +1941,8 @@ TEST(IRSimilarityCandidate, IdenticalWithDebug) { } !0 = distinct !{!"test\00", i32 10} - !1 = distinct !{!"test\00", i32 11})"; + !1 = distinct !{!"test\00", i32 11} + !2 = !DILocation(line: 1, column: 1, scope: !{}))"; LLVMContext Context; std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString); diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp b/llvm/unittests/CodeGen/MachineInstrTest.cpp index e53044a50b606..47e260104775f 100644 --- a/llvm/unittests/CodeGen/MachineInstrTest.cpp +++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp @@ -512,8 +512,12 @@ MATCHER_P(HasMIMetadata, MIMD, "") { TEST(MachineInstrBuilder, BuildMI) { LLVMContext Ctx; MDNode *PCS = MDNode::getDistinct(Ctx, {}); - MDNode *DI = MDNode::getDistinct(Ctx, {}); - DebugLoc DL(DI); + DIFile *DIF = DIFile::getDistinct(Ctx, "filename", ""); + DISubprogram *DIS = DISubprogram::getDistinct( + Ctx, nullptr, "", "", DIF, 0, nullptr, 0, nullptr, 0, 0, DINode::FlagZero, + DISubprogram::SPFlagZero, nullptr); + DILocation *DIL = DILocation::get(Ctx, 1, 5, DIS); + DebugLoc DL(DIL); MIMetadata MIMD(DL, PCS); EXPECT_EQ(MIMD.getDL(), DL); EXPECT_EQ(MIMD.getPCSections(), PCS); diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp index 1c4361e4c0f20..a1f22bbac02a1 100644 --- a/llvm/unittests/IR/InstructionsTest.cpp +++ b/llvm/unittests/IR/InstructionsTest.cpp @@ -768,7 +768,7 @@ TEST(InstructionsTest, AlterCallBundles) { AttrBuilder AB(C); AB.addAttribute(Attribute::Cold); Call->setAttributes(AttributeList::get(C, AttributeList::FunctionIndex, AB)); - Call->setDebugLoc(DebugLoc(MDNode::get(C, {}))); + Call->setDebugLoc(DebugLoc(DILocation::get(C, 1, 1, MDNode::get(C, {})))); OperandBundleDef NewBundle("after", ConstantInt::get(Int32Ty, 7)); std::unique_ptr<CallInst> Clone(CallInst::Create(Call.get(), NewBundle)); @@ -798,7 +798,7 @@ TEST(InstructionsTest, AlterInvokeBundles) { AB.addAttribute(Attribute::Cold); Invoke->setAttributes( AttributeList::get(C, AttributeList::FunctionIndex, AB)); - Invoke->setDebugLoc(DebugLoc(MDNode::get(C, {}))); + Invoke->setDebugLoc(DebugLoc(DILocation::get(C, 1, 1, MDNode::get(C, {})))); OperandBundleDef NewBundle("after", ConstantInt::get(Int32Ty, 7)); std::unique_ptr<InvokeInst> Clone( diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp index c3137a31a15c9..03b3667abc333 100644 --- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp +++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp @@ -2010,7 +2010,7 @@ define void @foo(i8 %v1, ptr %ptr) { ret void, !tbaa !2 } -!1 = !{} +!1 = !DILocation(line: 12, column: 1, scope: !{}) !2 = !{} )IR"); llvm::Function *LLVMF = &*M->getFunction("foo"); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
