diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h index 54458201af0b3..7e6d2f9de506d 100644 --- a/llvm/include/llvm/IR/DataLayout.h +++ b/llvm/include/llvm/IR/DataLayout.h @@ -398,6 +398,10 @@ class DataLayout { PS.HasExternalState; } + /// Returns if the null pointer for this address space has an all-zero bit + /// representation. + bool isNullPointerAllZeroes(unsigned AddrSpace) const { return true; } + /// Returns whether this address space has an "unstable" pointer /// representation. The bitwise pattern of such pointers is allowed to change /// in a target-specific way. For example, this could be used for copying diff --git a/llvm/unittests/IR/DataLayoutTest.cpp b/llvm/unittests/IR/DataLayoutTest.cpp index 9ca88141ca0eb..e26c2aec6549d 100644 --- a/llvm/unittests/IR/DataLayoutTest.cpp +++ b/llvm/unittests/IR/DataLayoutTest.cpp @@ -700,6 +700,15 @@ TEST(DataLayout, NonIntegralHelpers) { } } +TEST(DataLayoutTest, IsNullPointerAllZeroes) { + EXPECT_TRUE(DataLayout("").isNullPointerAllZeroes(0)); + EXPECT_TRUE(DataLayout("").isNullPointerAllZeroes(1)); + EXPECT_TRUE(DataLayout("p:32:32").isNullPointerAllZeroes(0)); + EXPECT_TRUE(DataLayout("p:32:32").isNullPointerAllZeroes(1)); + EXPECT_TRUE(DataLayout("p:64:64").isNullPointerAllZeroes(0)); + EXPECT_TRUE(DataLayout("p:64:64").isNullPointerAllZeroes(1)); +} + TEST(DataLayoutTest, CopyAssignmentInvalidatesStructLayout) { DataLayout DL1 = cantFail(DataLayout::parse("p:32:32")); DataLayout DL2 = cantFail(DataLayout::parse("p:64:64"));