Skip to content

Commit ad96f68

Browse files
authored
[mlir] Fix possible null dereference during error logging in EmitC (#157456)
Fixes #157452
1 parent 1858532 commit ad96f68

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

mlir/lib/Dialect/EmitC/IR/EmitC.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,11 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
13201320

13211321
// global has non-array type
13221322
auto lvalueType = dyn_cast<LValueType>(resultType);
1323-
if (!lvalueType || lvalueType.getValueType() != globalType)
1323+
if (!lvalueType)
1324+
return emitOpError("on non-array type expects result type to be an "
1325+
"lvalue type for the global @")
1326+
<< getName();
1327+
if (lvalueType.getValueType() != globalType)
13241328
return emitOpError("on non-array type expects result inner type ")
13251329
<< lvalueType.getValueType() << " to match type " << globalType
13261330
<< " of the global @" << getName();

mlir/test/Dialect/EmitC/invalid_ops.mlir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,16 @@ func.func @use_global() {
532532

533533
// -----
534534

535+
emitc.global @myglobal_value : f32
536+
537+
func.func @use_global() {
538+
// expected-error @+1 {{'emitc.get_global' op on non-array type expects result type to be an lvalue type for the global @myglobal_value}}
539+
%0 = emitc.get_global @myglobal_value : !emitc.array<2xf32>
540+
return
541+
}
542+
543+
// -----
544+
535545
func.func @member(%arg0: !emitc.lvalue<i32>) {
536546
// expected-error @+1 {{'emitc.member' op operand #0 must be emitc.lvalue of EmitC opaque type values, but got '!emitc.lvalue<i32>'}}
537547
%0 = "emitc.member" (%arg0) {member = "a"} : (!emitc.lvalue<i32>) -> !emitc.lvalue<i32>

0 commit comments

Comments
 (0)