================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits