[Mlir-commits] [mlir] ad96f68 - [mlir] Fix possible null dereference during error logging in EmitC (#157456)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Sep 15 14:05:03 PDT 2025
Author: Daniel Kuts
Date: 2025-09-15T23:04:58+02:00
New Revision: ad96f68a583381def7c09ffd5593e529bbe17ebf
URL: https://github.com/llvm/llvm-project/commit/ad96f68a583381def7c09ffd5593e529bbe17ebf
DIFF: https://github.com/llvm/llvm-project/commit/ad96f68a583381def7c09ffd5593e529bbe17ebf.diff
LOG: [mlir] Fix possible null dereference during error logging in EmitC (#157456)
Fixes #157452
Added:
Modified:
mlir/lib/Dialect/EmitC/IR/EmitC.cpp
mlir/test/Dialect/EmitC/invalid_ops.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index a73470cdf76c5..5c8564bca6f86 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 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 ")
<< lvalueType.getValueType() << " to match type " << globalType
<< " of the global @" << getName();
diff --git a/mlir/test/Dialect/EmitC/invalid_ops.mlir b/mlir/test/Dialect/EmitC/invalid_ops.mlir
index a97474401645c..f4c15f50053a8 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_value}}
+ %0 = emitc.get_global @myglobal_value : !emitc.array<2xf32>
+ 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>
More information about the Mlir-commits
mailing list