Skip to content

Commit 0e18d5e

Browse files
committed
[mlir][SubElements] Re-add null guards to better enable downstream adoption
We used to allow this, and it can break clients that still rely on it.
1 parent a782922 commit 0e18d5e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

mlir/lib/IR/SubElementInterfaces.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ static void walkSubElementsImpl(InterfaceT interface,
2727
DenseSet<Type> &visitedTypes) {
2828
interface.walkImmediateSubElements(
2929
[&](Attribute attr) {
30+
// Guard against potentially null inputs. This removes the need for the
31+
// derived attribute/type to do it.
32+
if (!attr)
33+
return;
34+
3035
// Avoid infinite recursion when visiting sub attributes later, if this
3136
// is a mutable attribute.
3237
if (LLVM_UNLIKELY(attr.hasTrait<AttributeTrait::IsMutable>())) {
@@ -43,6 +48,11 @@ static void walkSubElementsImpl(InterfaceT interface,
4348
walkAttrsFn(attr);
4449
},
4550
[&](Type type) {
51+
// Guard against potentially null inputs. This removes the need for the
52+
// derived attribute/type to do it.
53+
if (!type)
54+
return;
55+
4656
// Avoid infinite recursion when visiting sub types later, if this
4757
// is a mutable type.
4858
if (LLVM_UNLIKELY(type.hasTrait<TypeTrait::IsMutable>())) {
@@ -93,6 +103,10 @@ static void updateSubElementImpl(
93103
return;
94104
newElements.push_back(element);
95105

106+
// Guard against potentially null inputs. We always map null to null.
107+
if (!element)
108+
return;
109+
96110
// Check for an existing mapping for this element, and walk it if we haven't
97111
// yet.
98112
T *mappedElement = &visited[element];

0 commit comments

Comments
 (0)