Skip to content

Commit 1721831

Browse files
committed
[DataLayout] Add isNullPointerAllZeroes
Add a function to check for a given address space if its null pointer has an all-zero bit representation.
1 parent 1c837ec commit 1721831

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ 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;
405+
}
406+
401407
/// Returns whether this address space has an "unstable" pointer
402408
/// representation. The bitwise pattern of such pointers is allowed to change
403409
/// in a target-specific way. For example, this could be used for copying

llvm/unittests/IR/DataLayoutTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,15 @@ 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));
710+
}
711+
703712
TEST(DataLayoutTest, CopyAssignmentInvalidatesStructLayout) {
704713
DataLayout DL1 = cantFail(DataLayout::parse("p:32:32"));
705714
DataLayout DL2 = cantFail(DataLayout::parse("p:64:64"));

0 commit comments

Comments
 (0)