[Mlir-commits] [mlir] e84f9ca - [MLIR][NVVM] Fix segfault when translating NVVM ops outside a function (#188735)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Mar 27 04:24:42 PDT 2026


Author: Mehdi Amini
Date: 2026-03-27T12:24:38+01:00
New Revision: e84f9cacc972fa12734816b8ee1c921a973e93a6

URL: https://github.com/llvm/llvm-project/commit/e84f9cacc972fa12734816b8ee1c921a973e93a6
DIFF: https://github.com/llvm/llvm-project/commit/e84f9cacc972fa12734816b8ee1c921a973e93a6.diff

LOG: [MLIR][NVVM] Fix segfault when translating NVVM ops outside a function (#188735)

When a GPU barrier op was placed at the top level of a gpu.module (not
inside a gpu.func), the pass pipeline lowered it to nvvm.barrier0 at
module scope. During LLVM IR translation, translateModuleToLLVMIR called
NVVMDialectLLVMIRTranslationInterface::convertOperation for the
misplaced op, which reached createIntrinsicCall with an IRBuilder that
had no active insertion point (null GetInsertBlock()), causing a null
dereference crash.

The fix adds a guard at the top of the NVVM translation interface's
convertOperation: all NVVM ops are instruction-level and require an
active insertion point. If the insert block is null, the op must be
misplaced, so we return a proper MLIR error instead of crashing.

Fixes #186642

Assisted-by: Claude Code

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp
    mlir/test/Target/LLVMIR/nvvmir-invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp
index 18d42e9577095..254be8e63590f 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp
@@ -692,6 +692,13 @@ class NVVMDialectLLVMIRTranslationInterface
   LogicalResult
   convertOperation(Operation *op, llvm::IRBuilderBase &builder,
                    LLVM::ModuleTranslation &moduleTranslation) const final {
+    // All NVVM ops are instruction-level and require an active insertion point.
+    // A null insert block means the op is misplaced (e.g., at module scope),
+    // which would otherwise cause a null dereference in createIntrinsicCall.
+    if (!builder.GetInsertBlock())
+      return op->emitOpError(
+          "cannot be translated to LLVM IR without an active insertion "
+          "point; make sure the op is inside a function");
     Operation &opInst = *op;
 #include "mlir/Dialect/LLVMIR/NVVMConversions.inc"
 

diff  --git a/mlir/test/Target/LLVMIR/nvvmir-invalid.mlir b/mlir/test/Target/LLVMIR/nvvmir-invalid.mlir
index c0fe0fa11f497..785f59b22801f 100644
--- a/mlir/test/Target/LLVMIR/nvvmir-invalid.mlir
+++ b/mlir/test/Target/LLVMIR/nvvmir-invalid.mlir
@@ -595,7 +595,7 @@ func.func @invalid_range_equal_bounds() {
 
 // -----
 
-// Test for correct return type check for wmma.load fragment a for f64 
+// Test for correct return type check for wmma.load fragment a for f64
 llvm.func @nvvm_wmma_load_a_f64(%arg0: !llvm.ptr, %arg1 : i32) {
   // expected-error @below {{'nvvm.wmma.load' op expected destination type to be f64}}
   %0 = nvvm.wmma.load %arg0, %arg1
@@ -603,3 +603,12 @@ llvm.func @nvvm_wmma_load_a_f64(%arg0: !llvm.ptr, %arg1 : i32) {
     : (!llvm.ptr) -> !llvm.struct<(f64)>
   llvm.return
 }
+
+// -----
+
+// Test that nvvm.barrier0 at module scope (outside any function) produces a
+// proper error instead of crashing with a null dereference in
+// createIntrinsicCall. See https://github.com/llvm/llvm-project/issues/186642
+// expected-error @+2 {{'nvvm.barrier0' op cannot be translated to LLVM IR without an active insertion point}}
+// expected-error @+1 {{LLVM Translation failed for operation: nvvm.barrier0}}
+nvvm.barrier0


        


More information about the Mlir-commits mailing list