Skip to content

[NFC][AutoUpgrade] Use ConstantPointerNull::get instead of Constant::getNullValue for known pointer types #139984

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

Conversation

shiltian
Copy link
Contributor

This is a preparation change for upcoming PRs that will update the semantics of
ConstantPointerNull, making it to represent an actual nullptr rather than a
zero-valued pointer.

…t::getNullValue` for pointer types

This is a preparation change for upcoming PRs that will update the semantics of
`ConstantPointerNull`, making it to represent an actual `nullptr` rather than a
zero-valued pointer.
Copy link
Contributor Author

@shiltian shiltian requested review from nikic and arsenm May 15, 2025 00:22
@llvmbot
Copy link
Member

llvmbot commented May 15, 2025

@llvm/pr-subscribers-llvm-ir

Author: Shilei Tian (shiltian)

Changes

This is a preparation change for upcoming PRs that will update the semantics of
ConstantPointerNull, making it to represent an actual nullptr rather than a
zero-valued pointer.


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

1 Files Affected:

  • (modified) llvm/lib/IR/AutoUpgrade.cpp (+9-9)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 9091e7585f9d9..41aa06add6aba 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -1613,7 +1613,7 @@ GlobalVariable *llvm::UpgradeGlobalVariable(GlobalVariable *GV) {
     auto Ctor = cast<Constant>(Init->getOperand(i));
     NewCtors[i] = ConstantStruct::get(EltTy, Ctor->getAggregateElement(0u),
                                       Ctor->getAggregateElement(1),
-                                      Constant::getNullValue(IRB.getPtrTy()));
+                                      ConstantPointerNull::get(IRB.getPtrTy()));
   }
   Constant *NewInit = ConstantArray::get(ArrayType::get(EltTy, N), NewCtors);
 
@@ -4721,10 +4721,10 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
     }
 
     // Create a new call with an added null annotation attribute argument.
-    NewCall =
-        Builder.CreateCall(NewFn, {CI->getArgOperand(0), CI->getArgOperand(1),
-                                   CI->getArgOperand(2), CI->getArgOperand(3),
-                                   Constant::getNullValue(Builder.getPtrTy())});
+    NewCall = Builder.CreateCall(
+        NewFn,
+        {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2),
+         CI->getArgOperand(3), ConstantPointerNull::get(Builder.getPtrTy())});
     NewCall->takeName(CI);
     CI->replaceAllUsesWith(NewCall);
     CI->eraseFromParent();
@@ -4737,10 +4737,10 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
       return;
     }
     // Create a new call with an added null annotation attribute argument.
-    NewCall =
-        Builder.CreateCall(NewFn, {CI->getArgOperand(0), CI->getArgOperand(1),
-                                   CI->getArgOperand(2), CI->getArgOperand(3),
-                                   Constant::getNullValue(Builder.getPtrTy())});
+    NewCall = Builder.CreateCall(
+        NewFn,
+        {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2),
+         CI->getArgOperand(3), ConstantPointerNull::get(Builder.getPtrTy())});
     NewCall->takeName(CI);
     CI->replaceAllUsesWith(NewCall);
     CI->eraseFromParent();

@shiltian shiltian changed the title [NFC][AutoUpgrade] Use ConstantPointerNull::get instead of Constant::getNullValue for pointer types [NFC][AutoUpgrade] Use ConstantPointerNull::get instead of Constant::getNullValue for known pointer types May 15, 2025
@@ -1613,7 +1613,7 @@ GlobalVariable *llvm::UpgradeGlobalVariable(GlobalVariable *GV) {
auto Ctor = cast<Constant>(Init->getOperand(i));
NewCtors[i] = ConstantStruct::get(EltTy, Ctor->getAggregateElement(0u),
Ctor->getAggregateElement(1),
Constant::getNullValue(IRB.getPtrTy()));
ConstantPointerNull::get(IRB.getPtrTy()));
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a preexisting bug here. It's not using the type of this value, which may not be addrspace(0)

@shiltian shiltian merged commit 7314d38 into main May 15, 2025
13 checks passed
@shiltian shiltian deleted the users/shiltian/use-constantpointernull-for-autoupgrade branch May 15, 2025 14:03
TIFitis pushed a commit to TIFitis/llvm-project that referenced this pull request May 19, 2025
…t::getNullValue` for known pointer types (llvm#139984)

This is a preparation change for upcoming PRs that will update the
semantics of
`ConstantPointerNull`, making it to represent an actual `nullptr` rather
than a
zero-valued pointer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants