[clang] [lld] [llvm] [WIP][IR][Constants] Change the semantic of `ConstantPointerNull` to represent an actual `nullptr` instead of a zero-value pointer (PR #166667)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 21 21:10:15 PST 2025
================
@@ -4275,8 +4275,15 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
return emitGlobalConstantFP(CFP, AP);
}
- if (isa<ConstantPointerNull>(CV)) {
- AP.OutStreamer->emitIntValue(0, Size);
+ if (auto *NullPtr = dyn_cast<ConstantPointerNull>(CV)) {
+ if (std::optional<APInt> NullPtrVal =
+ DL.getNullPtrValue(NullPtr->getType()->getPointerAddressSpace())) {
+ AP.OutStreamer->emitIntValue(NullPtrVal->getSExtValue(), Size);
+ } else {
+ // We fall back to the default behavior of emitting a zero value if we
+ // can't get the null pointer value from the data layout.
+ AP.OutStreamer->emitIntValue(0, Size);
+ }
----------------
shiltian wrote:
That sounds like a good idea. I can do that but I guess we'd need an RFC.
https://github.com/llvm/llvm-project/pull/166667
More information about the llvm-commits
mailing list