Skip to content

[Metadata] Replace undef VAMs with poison VAMs #129450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

pedroclobo
Copy link
Member

undef debug info can be replaced with poison debug info.

@llvmbot
Copy link
Member

llvmbot commented Mar 2, 2025

@llvm/pr-subscribers-llvm-ir

Author: Pedro Lobo (pedroclobo)

Changes

undef debug info can be replaced with poison debug info.


Full diff: https://github.com/llvm/llvm-project/pull/129450.diff

2 Files Affected:

  • (modified) llvm/lib/IR/Metadata.cpp (+3-3)
  • (modified) llvm/test/DebugInfo/X86/undef-dbg-val.ll (+1-1)
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index e3a46840eea0e..3bd2244c5e90f 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -339,7 +339,7 @@ void ReplaceableMetadataImpl::SalvageDebugInfo(const Constant &C) {
   ValueAsMetadata *MD = I->second;
   using UseTy =
       std::pair<void *, std::pair<MetadataTracking::OwnerTy, uint64_t>>;
-  // Copy out uses and update value of Constant used by debug info metadata with undef below
+  // Copy out uses and update value of Constant used by debug info metadata with poison below
   SmallVector<UseTy, 8> Uses(MD->UseMap.begin(), MD->UseMap.end());
 
   for (const auto &Pair : Uses) {
@@ -349,7 +349,7 @@ void ReplaceableMetadataImpl::SalvageDebugInfo(const Constant &C) {
     // Check for MetadataAsValue.
     if (isa<MetadataAsValue *>(Owner)) {
       cast<MetadataAsValue *>(Owner)->handleChangedMetadata(
-          ValueAsMetadata::get(UndefValue::get(C.getType())));
+          ValueAsMetadata::get(PoisonValue::get(C.getType())));
       continue;
     }
     if (!isa<Metadata *>(Owner))
@@ -359,7 +359,7 @@ void ReplaceableMetadataImpl::SalvageDebugInfo(const Constant &C) {
       continue;
     if (isa<DINode>(OwnerMD)) {
       OwnerMD->handleChangedOperand(
-          Pair.first, ValueAsMetadata::get(UndefValue::get(C.getType())));
+          Pair.first, ValueAsMetadata::get(PoisonValue::get(C.getType())));
     }
   }
 }
diff --git a/llvm/test/DebugInfo/X86/undef-dbg-val.ll b/llvm/test/DebugInfo/X86/undef-dbg-val.ll
index 61f3776c22d5a..02b94d9112a51 100644
--- a/llvm/test/DebugInfo/X86/undef-dbg-val.ll
+++ b/llvm/test/DebugInfo/X86/undef-dbg-val.ll
@@ -1,5 +1,5 @@
 ; RUN:  opt -S -passes=globalopt --experimental-debuginfo-iterators=false <%s | FileCheck %s
-; CHECK: #dbg_value(ptr undef, 
+; CHECK: #dbg_value(ptr poison,
 ; CHECK-SAME:    [[VAR:![0-9]+]],
 ; CHECK-SAME:    !DIExpression()
 ; CHECK: [[VAR]] = !DILocalVariable(name: "_format"

@llvmbot
Copy link
Member

llvmbot commented Mar 2, 2025

@llvm/pr-subscribers-debuginfo

Author: Pedro Lobo (pedroclobo)

Changes

undef debug info can be replaced with poison debug info.


Full diff: https://github.com/llvm/llvm-project/pull/129450.diff

2 Files Affected:

  • (modified) llvm/lib/IR/Metadata.cpp (+3-3)
  • (modified) llvm/test/DebugInfo/X86/undef-dbg-val.ll (+1-1)
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index e3a46840eea0e..3bd2244c5e90f 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -339,7 +339,7 @@ void ReplaceableMetadataImpl::SalvageDebugInfo(const Constant &C) {
   ValueAsMetadata *MD = I->second;
   using UseTy =
       std::pair<void *, std::pair<MetadataTracking::OwnerTy, uint64_t>>;
-  // Copy out uses and update value of Constant used by debug info metadata with undef below
+  // Copy out uses and update value of Constant used by debug info metadata with poison below
   SmallVector<UseTy, 8> Uses(MD->UseMap.begin(), MD->UseMap.end());
 
   for (const auto &Pair : Uses) {
@@ -349,7 +349,7 @@ void ReplaceableMetadataImpl::SalvageDebugInfo(const Constant &C) {
     // Check for MetadataAsValue.
     if (isa<MetadataAsValue *>(Owner)) {
       cast<MetadataAsValue *>(Owner)->handleChangedMetadata(
-          ValueAsMetadata::get(UndefValue::get(C.getType())));
+          ValueAsMetadata::get(PoisonValue::get(C.getType())));
       continue;
     }
     if (!isa<Metadata *>(Owner))
@@ -359,7 +359,7 @@ void ReplaceableMetadataImpl::SalvageDebugInfo(const Constant &C) {
       continue;
     if (isa<DINode>(OwnerMD)) {
       OwnerMD->handleChangedOperand(
-          Pair.first, ValueAsMetadata::get(UndefValue::get(C.getType())));
+          Pair.first, ValueAsMetadata::get(PoisonValue::get(C.getType())));
     }
   }
 }
diff --git a/llvm/test/DebugInfo/X86/undef-dbg-val.ll b/llvm/test/DebugInfo/X86/undef-dbg-val.ll
index 61f3776c22d5a..02b94d9112a51 100644
--- a/llvm/test/DebugInfo/X86/undef-dbg-val.ll
+++ b/llvm/test/DebugInfo/X86/undef-dbg-val.ll
@@ -1,5 +1,5 @@
 ; RUN:  opt -S -passes=globalopt --experimental-debuginfo-iterators=false <%s | FileCheck %s
-; CHECK: #dbg_value(ptr undef, 
+; CHECK: #dbg_value(ptr poison,
 ; CHECK-SAME:    [[VAR:![0-9]+]],
 ; CHECK-SAME:    !DIExpression()
 ; CHECK: [[VAR]] = !DILocalVariable(name: "_format"

Copy link

github-actions bot commented Mar 2, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link

github-actions bot commented Mar 2, 2025

⚠️ undef deprecator found issues in your code. ⚠️

You can test this locally with the following command:
git diff -U0 --pickaxe-regex -S '([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' f5f5286da3a64608b5874d70b32f955267039e1c abc138136447d78e9355064091c2a6596d58e692 llvm/lib/IR/Metadata.cpp llvm/test/DebugInfo/X86/undef-dbg-val.ll

The following files introduce new uses of undef:

  • llvm/test/DebugInfo/X86/undef-dbg-val.ll

Undef is now deprecated and should only be used in the rare cases where no replacement is possible. For example, a load of uninitialized memory yields undef. You should use poison values for placeholders instead.

In tests, avoid using undef and having tests that trigger undefined behavior. If you need an operand with some unimportant value, you can add a new argument to the function and use that instead.

For example, this is considered a bad practice:

define void @fn() {
  ...
  br i1 undef, ...
}

Please use the following instead:

define void @fn(i1 %cond) {
  ...
  br i1 %cond, ...
}

Please refer to the Undefined Behavior Manual for more information.

`undef` debug info can be replaced with `poison` debug info.
Copy link
Contributor

@OCHyams OCHyams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nikic nikic merged commit 05589ee into llvm:main Mar 3, 2025
10 of 11 checks passed
@pedroclobo pedroclobo deleted the metadata-undef branch March 4, 2025 15:12
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
`undef` debug info can be replaced with `poison` debug info.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants