[llvm] 6cb66ee - [RemoveDIs][DebugInfo] Handle RAUW from dead constants (#80837)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 05:06:59 PST 2024


Author: Stephen Tozer
Date: 2024-02-07T13:06:55Z
New Revision: 6cb66ee5f8827040c5178fc2a479c138f4838eca

URL: https://github.com/llvm/llvm-project/commit/6cb66ee5f8827040c5178fc2a479c138f4838eca
DIFF: https://github.com/llvm/llvm-project/commit/6cb66ee5f8827040c5178fc2a479c138f4838eca.diff

LOG: [RemoveDIs][DebugInfo] Handle RAUW from dead constants (#80837)

Ensure that when a constant value dies, all ValueAsMetadata uses of that
constant in a DebugValueUser will be replaced with a PoisonValue instead
of a nullptr. This has little visible effect currently, as any nullptr metadata
uses in a DebugValueUser would be converted to an empty MDNode in
the end anyway, but this patch adds an assert that would be triggered by
two existing tests without the functional component of this patch:

  llvm/test/Transforms/Inline/delete-function-with-metadata-use.ll
  llvm/test/DebugInfo/X86/array2.ll

Added: 
    

Modified: 
    llvm/lib/IR/DebugProgramInstruction.cpp
    llvm/lib/IR/Metadata.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/DebugProgramInstruction.cpp b/llvm/lib/IR/DebugProgramInstruction.cpp
index 1a62902115be1..a2640d59242ac 100644
--- a/llvm/lib/IR/DebugProgramInstruction.cpp
+++ b/llvm/lib/IR/DebugProgramInstruction.cpp
@@ -286,6 +286,7 @@ DPValue::createDebugIntrinsic(Module *M, Instruction *InsertBefore) const {
   // Create the intrinsic from this DPValue's information, optionally insert
   // into the target location.
   DbgVariableIntrinsic *DVI;
+  assert(getRawLocation() && "DPValue's RawLocation should be non-null.");
   if (isDbgAssign()) {
     Value *AssignArgs[] = {
         MetadataAsValue::get(Context, getRawLocation()),

diff  --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 37017a222d485..06db91fe4f8e7 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -158,6 +158,12 @@ void DebugValueUser::handleChangedValue(void *Old, Metadata *New) {
   // getOwner, if needed.
   auto OldMD = static_cast<Metadata **>(Old);
   ptr
diff _t Idx = std::distance(&*DebugValues.begin(), OldMD);
+  // If replacing a ValueAsMetadata with a nullptr, replace it with a
+  // PoisonValue instead.
+  if (OldMD && isa<ValueAsMetadata>(*OldMD) && !New) {
+    auto *OldVAM = cast<ValueAsMetadata>(*OldMD);
+    New = ValueAsMetadata::get(PoisonValue::get(OldVAM->getValue()->getType()));
+  }
   resetDebugValue(Idx, New);
 }
 


        


More information about the llvm-commits mailing list