From 13317502da8ee3885854f67700140586c0edafee Mon Sep 17 00:00:00 2001 From: Shlomi Regev Date: Tue, 12 Nov 2024 22:31:25 +0000 Subject: [PATCH] [mlir] Add a null pointer check in symbol lookup (#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. --- mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp | 2 ++ mlir/test/Analysis/DataFlow/test-dead-code-analysis.mlir | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp index 3c190d4e9919..e805e21d878b 100644 --- a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp +++ b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp @@ -186,6 +186,8 @@ void DeadCodeAnalysis::initializeSymbolCallables(Operation *top) { // If a callable symbol has a non-call use, then we can't be guaranteed to // know all callsites. Operation *symbol = symbolTable.lookupSymbolIn(top, use.getSymbolRef()); + if (!symbol) + continue; auto *state = getOrCreate(getProgramPointAfter(symbol)); propagateIfChanged(state, state->setHasUnknownPredecessors()); } diff --git a/mlir/test/Analysis/DataFlow/test-dead-code-analysis.mlir b/mlir/test/Analysis/DataFlow/test-dead-code-analysis.mlir index 70becc72beb9..1ae685535150 100644 --- a/mlir/test/Analysis/DataFlow/test-dead-code-analysis.mlir +++ b/mlir/test/Analysis/DataFlow/test-dead-code-analysis.mlir @@ -265,3 +265,7 @@ func.func @test_dca_doesnt_crash() -> () { } return } + +func.func @test_dca_doesnt_crash_2() -> () attributes {symbol = @notexistant} { + return +}