[Mlir-commits] [mlir] [mlir] Fix possible null dereference during error logging in EmitC (PR #157456)
Daniel Kuts
llvmlistbot at llvm.org
Mon Sep 15 11:59:06 PDT 2025
https://github.com/apach301 updated https://github.com/llvm/llvm-project/pull/157456
>From 5b131107f618911f5e08deea0edbf919d0a94c2b Mon Sep 17 00:00:00 2001
From: Daniil Kutz <kutz at ispras.ru>
Date: Mon, 8 Sep 2025 16:22:26 +0300
Subject: [PATCH 1/4] [mlir] Fix possible null dereference during error logging
in Dialect/EmitC
---
mlir/lib/Dialect/EmitC/IR/EmitC.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index a73470cdf76c5..6b88e2c525d07 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -1320,7 +1320,11 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
// global has non-array type
auto lvalueType = dyn_cast<LValueType>(resultType);
- if (!lvalueType || lvalueType.getValueType() != globalType)
+ if (!lvalueType)
+ return emitOpError("on non-array type result type is not defined "
+ "for the global @")
+ << getName();
+ if (lvalueType.getValueType() != globalType)
return emitOpError("on non-array type expects result inner type ")
<< lvalueType.getValueType() << " to match type " << globalType
<< " of the global @" << getName();
>From 2cea9f4b95abde7866b047244f8104ac26cf7607 Mon Sep 17 00:00:00 2001
From: Daniil Kutz <kutz at ispras.ru>
Date: Tue, 9 Sep 2025 11:44:21 +0300
Subject: [PATCH 2/4] Improve error message
---
mlir/lib/Dialect/EmitC/IR/EmitC.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index 6b88e2c525d07..5c8564bca6f86 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -1321,8 +1321,8 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
// global has non-array type
auto lvalueType = dyn_cast<LValueType>(resultType);
if (!lvalueType)
- return emitOpError("on non-array type result type is not defined "
- "for the global @")
+ return emitOpError("on non-array type expects result type to be an "
+ "lvalue type for the global @")
<< getName();
if (lvalueType.getValueType() != globalType)
return emitOpError("on non-array type expects result inner type ")
>From c3a3c64b00666e81a7d86d91509908ee0beea895 Mon Sep 17 00:00:00 2001
From: Daniil Kutz <kutz at ispras.ru>
Date: Mon, 15 Sep 2025 20:50:04 +0300
Subject: [PATCH 3/4] [mlir][emitc] Add a test for invalid lvalue for
get_global_op
---
mlir/test/Dialect/EmitC/invalid_ops.mlir | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/mlir/test/Dialect/EmitC/invalid_ops.mlir b/mlir/test/Dialect/EmitC/invalid_ops.mlir
index a97474401645c..30745163543a4 100644
--- a/mlir/test/Dialect/EmitC/invalid_ops.mlir
+++ b/mlir/test/Dialect/EmitC/invalid_ops.mlir
@@ -532,6 +532,16 @@ func.func @use_global() {
// -----
+emitc.global @myglobal_value : f32
+
+func.func @use_global() {
+ // expected-error @+1 {{'emitc.get_global' op on non-array type expects result type to be an lvalue type for the global @myglobal_scalar}}
+ %0 = emitc.get_global @myglobal_scalar : i32
+ return
+}
+
+// -----
+
func.func @member(%arg0: !emitc.lvalue<i32>) {
// expected-error @+1 {{'emitc.member' op operand #0 must be emitc.lvalue of EmitC opaque type values, but got '!emitc.lvalue<i32>'}}
%0 = "emitc.member" (%arg0) {member = "a"} : (!emitc.lvalue<i32>) -> !emitc.lvalue<i32>
>From 6fa4e9e7610b74c2b559c5b142cfe7730e79f936 Mon Sep 17 00:00:00 2001
From: Daniil Kutz <kutz at ispras.ru>
Date: Mon, 15 Sep 2025 21:58:41 +0300
Subject: [PATCH 4/4] fix test
---
mlir/test/Dialect/EmitC/invalid_ops.mlir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/test/Dialect/EmitC/invalid_ops.mlir b/mlir/test/Dialect/EmitC/invalid_ops.mlir
index 30745163543a4..046f6cdad8627 100644
--- a/mlir/test/Dialect/EmitC/invalid_ops.mlir
+++ b/mlir/test/Dialect/EmitC/invalid_ops.mlir
@@ -536,7 +536,7 @@ emitc.global @myglobal_value : f32
func.func @use_global() {
// expected-error @+1 {{'emitc.get_global' op on non-array type expects result type to be an lvalue type for the global @myglobal_scalar}}
- %0 = emitc.get_global @myglobal_scalar : i32
+ %0 = emitc.get_global @myglobal_value : f32
return
}
More information about the Mlir-commits
mailing list