[Mlir-commits] [mlir] [mlir] Fix a crash in ensure-debug-info-scope-on-llvm-func. (PR #178337)

Peter Hawkins llvmlistbot at llvm.org
Tue Jan 27 17:51:16 PST 2026


https://github.com/hawkinsp created https://github.com/llvm/llvm-project/pull/178337

This pass was not defensive enough about the presence of non-llvm functions with call site locs.

>From 75b8f0ff1ed6d305040d7e0bd7c9afcd5d580a38 Mon Sep 17 00:00:00 2001
From: Peter Hawkins <phawkins at google.com>
Date: Wed, 28 Jan 2026 01:49:05 +0000
Subject: [PATCH] [mlir] Fix a crash in ensure-debug-info-scope-on-llvm-func.

This pass was not defensive enough about the presence of non-llvm functions with call
site locs.
---
 .../LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp     | 11 +++++++----
 .../Dialect/LLVMIR/add-debuginfo-func-scope.mlir   | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
index 12dd22581a979..790d9dc7b3260 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
@@ -121,10 +121,13 @@ static void setLexicalBlockFileAttr(Operation *op) {
     // We assemble the full inline stack so the parent of this loc must be a
     // function
     auto funcOp = op->getParentOfType<LLVM::LLVMFuncOp>();
-    if (auto funcOpLoc = llvm::dyn_cast_if_present<FusedLoc>(funcOp.getLoc())) {
-      scopeAttr = cast<LLVM::DISubprogramAttr>(funcOpLoc.getMetadata());
-      op->setLoc(
-          CallSiteLoc::get(getNestedLoc(op, scopeAttr, calleeLoc), callerLoc));
+    if (funcOp) {
+      if (auto funcOpLoc =
+              llvm::dyn_cast_if_present<FusedLoc>(funcOp.getLoc())) {
+        scopeAttr = cast<LLVM::DISubprogramAttr>(funcOpLoc.getMetadata());
+        op->setLoc(CallSiteLoc::get(getNestedLoc(op, scopeAttr, calleeLoc),
+                                    callerLoc));
+      }
     }
 
     return;
diff --git a/mlir/test/Dialect/LLVMIR/add-debuginfo-func-scope.mlir b/mlir/test/Dialect/LLVMIR/add-debuginfo-func-scope.mlir
index ffeb871d56c6c..5b58315493808 100644
--- a/mlir/test/Dialect/LLVMIR/add-debuginfo-func-scope.mlir
+++ b/mlir/test/Dialect/LLVMIR/add-debuginfo-func-scope.mlir
@@ -160,3 +160,17 @@ module {
   } loc(#loc)
 } loc(unknown)
 
+// -----
+
+// Test that operations with CallSiteLoc outside of an llvm.func do not crash.
+module {
+  llvm.func @dummy()
+  func.func @test_func() {
+    return
+  } loc(#loc2)
+} loc(unknown)
+
+#loc = loc("a.py":1150:34)
+#loc1 = loc("b.py":321:17)
+#loc2 = loc(callsite(#loc at #loc1))
+



More information about the Mlir-commits mailing list