Skip to content

Commit 9113b53

Browse files
ro-iarichardson
andcommitted
move to getNullPointerValue
Co-authored-by: Alexander Richardson <[email protected]>
1 parent 1721831 commit 9113b53

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,14 @@ class DataLayout {
398398
PS.HasExternalState;
399399
}
400400

401-
/// Returns if the null pointer for this address space has an all-zero bit
402-
/// representation.
403-
bool isNullPointerAllZeroes(unsigned AddrSpace) const {
404-
return AddrSpace == 0;
401+
/// Return the bit value of the null pointer for the given address space.
402+
std::optional<APInt> getNullPointerValue(unsigned AS) const {
403+
// Address space zero is currently defined to always have an all-zero null
404+
// pointer representation, the others are target-specific and will require a
405+
// data layout property (work-in-progress).
406+
if (AS == 0)
407+
return APInt::getZero(getPointerSizeInBits(AS));
408+
return std::nullopt;
405409
}
406410

407411
/// Returns whether this address space has an "unstable" pointer

llvm/unittests/IR/DataLayoutTest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -700,13 +700,13 @@ TEST(DataLayout, NonIntegralHelpers) {
700700
}
701701
}
702702

703-
TEST(DataLayoutTest, IsNullPointerAllZeroes) {
704-
EXPECT_TRUE(DataLayout("").isNullPointerAllZeroes(0));
705-
EXPECT_FALSE(DataLayout("").isNullPointerAllZeroes(1));
706-
EXPECT_TRUE(DataLayout("p:32:32").isNullPointerAllZeroes(0));
707-
EXPECT_FALSE(DataLayout("p:32:32").isNullPointerAllZeroes(1));
708-
EXPECT_TRUE(DataLayout("p:64:64").isNullPointerAllZeroes(0));
709-
EXPECT_FALSE(DataLayout("p:64:64").isNullPointerAllZeroes(1));
703+
TEST(DataLayoutTest, GetNullPointerValue) {
704+
EXPECT_EQ(DataLayout("").getNullPointerValue(0), APInt::getZero(64));
705+
EXPECT_EQ(DataLayout("").getNullPointerValue(1), std::nullopt);
706+
EXPECT_EQ(DataLayout("p:32:32").getNullPointerValue(0), APInt::getZero(32));
707+
EXPECT_EQ(DataLayout("p:32:32").getNullPointerValue(1), std::nullopt);
708+
EXPECT_EQ(DataLayout("p:64:64").getNullPointerValue(0), APInt::getZero(64));
709+
EXPECT_EQ(DataLayout("p:64:64").getNullPointerValue(1), std::nullopt);
710710
}
711711

712712
TEST(DataLayoutTest, CopyAssignmentInvalidatesStructLayout) {

0 commit comments

Comments
 (0)