File tree Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
712712TEST (DataLayoutTest, CopyAssignmentInvalidatesStructLayout) {
You can’t perform that action at this time.
0 commit comments