summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/possible-contents.cpp10
-rw-r--r--test/gtest/possible-contents.cpp9
2 files changed, 17 insertions, 2 deletions
diff --git a/src/ir/possible-contents.cpp b/src/ir/possible-contents.cpp
index 8349939e1..cd8bd1516 100644
--- a/src/ir/possible-contents.cpp
+++ b/src/ir/possible-contents.cpp
@@ -195,11 +195,17 @@ void PossibleContents::intersectWithFullCone(const PossibleContents& other) {
}
// If the heap types are not compatible then they are in separate hierarchies
- // and there is no intersection.
+ // and there is no intersection, aside from possibly a null of the bottom
+ // type.
auto isSubType = HeapType::isSubType(heapType, otherHeapType);
auto otherIsSubType = HeapType::isSubType(otherHeapType, heapType);
if (!isSubType && !otherIsSubType) {
- value = None();
+ if (nullability == Nullable &&
+ heapType.getBottom() == otherHeapType.getBottom()) {
+ value = Literal::makeNull(heapType.getBottom());
+ } else {
+ value = None();
+ }
return;
}
diff --git a/test/gtest/possible-contents.cpp b/test/gtest/possible-contents.cpp
index 04c288806..7b8f0c4a8 100644
--- a/test/gtest/possible-contents.cpp
+++ b/test/gtest/possible-contents.cpp
@@ -481,6 +481,8 @@ void assertIntersection(PossibleContents a,
auto intersection = a;
intersection.intersectWithFullCone(b);
EXPECT_EQ(intersection, result);
+
+ EXPECT_EQ(PossibleContents::haveIntersection(a, b), !result.isNone());
}
TEST_F(PossibleContentsTest, TestStructCones) {
@@ -713,6 +715,13 @@ TEST_F(PossibleContentsTest, TestStructCones) {
assertIntersection(nnExactA, PossibleContents::fullConeType(nullB), none);
assertIntersection(exactA, PossibleContents::fullConeType(nnB), none);
+ // A and E have no intersection, so the only possibility is a null, and that
+ // null must be the bottom type.
+ assertIntersection(
+ exactA,
+ PossibleContents::fullConeType(nullE),
+ PossibleContents::literal(Literal::makeNull(HeapType::none)));
+
assertIntersection(PossibleContents::coneType(nnA, 1),
PossibleContents::fullConeType(nnB),
nnExactB);