[Mlir-commits] [mlir] [mlir] Add a null pointer check in symbol lookup (PR #115165)

Jacques Pienaar llvmlistbot at llvm.org
Tue Nov 12 14:21:23 PST 2024


https://github.com/jpienaar updated https://github.com/llvm/llvm-project/pull/115165

>From 18eed3a68d30fdf6b738ce1562cf3edaf85f2c92 Mon Sep 17 00:00:00 2001
From: Shlomi Regev <regevs at google.com>
Date: Wed, 6 Nov 2024 14:43:22 +0000
Subject: [PATCH 1/2] Add a null pointer check in symbol lookup

We (TensorFlow project) ran into a case where a dead code analysis
crashed because a symbol that is called/used didn't appear in the symbol
table. Added a nullptr check after symbol table lookup.
---
 mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
index 3c190d4e991919..e805e21d878bf9 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<PredecessorState>(getProgramPointAfter(symbol));
       propagateIfChanged(state, state->setHasUnknownPredecessors());
     }

>From 27eb789628be95741225d7b9c89ed96de3d81d75 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar <jacques+gh at japienaar.info>
Date: Tue, 12 Nov 2024 14:21:14 -0800
Subject: [PATCH 2/2] Update test-dead-code-analysis.mlir

Add test showing previous failure.
---
 mlir/test/Analysis/DataFlow/test-dead-code-analysis.mlir | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mlir/test/Analysis/DataFlow/test-dead-code-analysis.mlir b/mlir/test/Analysis/DataFlow/test-dead-code-analysis.mlir
index 70becc72beb96a..1ae68553515067 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
+}



More information about the Mlir-commits mailing list