Skip to content

Commit 1331750

Browse files
authored
[mlir] Add a null pointer check in symbol lookup (llvm#115165)
Dead code analysis crashed because a symbol that is called/used didn't appear in the symbol table. This patch fixes this by adding a nullptr check after symbol table lookup.
1 parent 5a5122c commit 1331750

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ void DeadCodeAnalysis::initializeSymbolCallables(Operation *top) {
186186
// If a callable symbol has a non-call use, then we can't be guaranteed to
187187
// know all callsites.
188188
Operation *symbol = symbolTable.lookupSymbolIn(top, use.getSymbolRef());
189+
if (!symbol)
190+
continue;
189191
auto *state = getOrCreate<PredecessorState>(getProgramPointAfter(symbol));
190192
propagateIfChanged(state, state->setHasUnknownPredecessors());
191193
}

mlir/test/Analysis/DataFlow/test-dead-code-analysis.mlir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,7 @@ func.func @test_dca_doesnt_crash() -> () {
265265
}
266266
return
267267
}
268+
269+
func.func @test_dca_doesnt_crash_2() -> () attributes {symbol = @notexistant} {
270+
return
271+
}

0 commit comments

Comments
 (0)