[Mlir-commits] [mlir] [mlir][LLVMIR] Add LLVMDialect check in `DIScopeForLLVMFuncOp` (PR #110427)

Longsheng Mou llvmlistbot at llvm.org
Sun Sep 29 08:42:35 PDT 2024


https://github.com/CoTinker created https://github.com/llvm/llvm-project/pull/110427

This PR adds an LLVMDialect check in `DIScopeForLLVMFuncOp` to prevent crashes. Fixes #108390.

>From 2243fd62480a5205cb15a2aed2a72b310c99a9de Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Sun, 29 Sep 2024 23:13:39 +0800
Subject: [PATCH] [mlir][LLVMIR] Add LLVMDialect check in
 `DIScopeForLLVMFuncOp`

This PR adds an LLVMDialect check in `DIScopeForLLVMFuncOp` to
prevent crashes.
---
 mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
index 2cfaffa7c8efce..a4733bd14c9f67 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
@@ -91,6 +91,10 @@ struct DIScopeForLLVMFuncOp
     Location loc = module.getLoc();
 
     MLIRContext *context = &getContext();
+    if (!context->getLoadedDialect<LLVM::LLVMDialect>()) {
+      emitError(loc, "LLVM dialect is not loaded.");
+      return;
+    }
 
     // To find a DICompileUnitAttr attached to a parent (the module for
     // example), otherwise create a default one.



More information about the Mlir-commits mailing list