llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-ir

Author: Alexis Engelke (aengelke)

<details>
<summary>Changes</summary>

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.


---

Patch is 30.69 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/200649.diff


27 Files Affected:

- (modified) clang/lib/CodeGen/CGClass.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGDebugInfo.h (+3-3) 
- (modified) llvm/include/llvm/AsmParser/LLParser.h (+5) 
- (modified) llvm/include/llvm/IR/DebugLoc.h (+8-19) 
- (modified) llvm/include/llvm/IR/DebugProgramInstruction.h (+6-9) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+26-2) 
- (modified) llvm/lib/CodeGen/MIRParser/MIParser.cpp (+1-1) 
- (modified) llvm/lib/IR/AutoUpgrade.cpp (+6-14) 
- (modified) llvm/lib/IR/Core.cpp (+3-3) 
- (modified) llvm/lib/IR/DebugInfo.cpp (+1-1) 
- (modified) llvm/lib/IR/DebugLoc.cpp (+2-6) 
- (modified) llvm/lib/IR/DebugProgramInstruction.cpp (+8-9) 
- (modified) llvm/lib/IR/Metadata.cpp (+1-1) 
- (renamed) llvm/test/Assembler/dbg-declare-invalid-debug-loc.ll (+3-7) 
- (added) llvm/test/Assembler/dbg.ll (+12) 
- (modified) llvm/test/CodeGen/X86/stack-protector-dbginfo.ll (+1-1) 
- (modified) llvm/test/DebugInfo/Generic/2009-10-16-Phi.ll (+2-1) 
- (modified) llvm/test/DebugInfo/Generic/location-verifier.ll (+3-4) 
- (modified) llvm/test/DebugInfo/MIR/X86/regcoalescer.mir (+1-1) 
- (modified) llvm/test/Transforms/MergeFunc/mergefunc-preserve-nonnull.ll 
(+2-1) 
- (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll 
(-16) 
- (modified) llvm/test/Verifier/dbg.ll (+1-4) 
- (modified) llvm/test/tools/llvm-reduce/remove-metadata.ll (+3-3) 
- (modified) llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp (+7-5) 
- (modified) llvm/unittests/CodeGen/MachineInstrTest.cpp (+6-2) 
- (modified) llvm/unittests/IR/InstructionsTest.cpp (+2-2) 
- (modified) llvm/unittests/SandboxIR/SandboxIRTest.cpp (+1-1) 


``````````diff
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: "IgnoreIntrinsi...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/200649
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to