Skip to content

Commit d5461d5

Browse files
author
Simon Camphausen
committed
Disallow lvalues as block arguments
1 parent efc5a36 commit d5461d5

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

mlir/lib/Target/Cpp/TranslateToCpp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,9 @@ static LogicalResult printFunctionBody(CppEmitter &emitter,
987987
if (emitter.hasValueInScope(arg))
988988
return functionOp->emitOpError(" block argument #")
989989
<< arg.getArgNumber() << " is out of scope";
990-
if (isa<ArrayType>(arg.getType()))
990+
if (isa<ArrayType, LValueType>(arg.getType()))
991991
return functionOp->emitOpError("cannot emit block argument #")
992-
<< arg.getArgNumber() << " with array type";
992+
<< arg.getArgNumber() << " with type " << arg.getType();
993993
if (failed(
994994
emitter.emitType(block.getParentOp()->getLoc(), arg.getType()))) {
995995
return failure();
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
// RUN: mlir-translate -split-input-file -declare-variables-at-top -mlir-to-cpp -verify-diagnostics %s
22

3-
// expected-error@+1 {{'func.func' op cannot emit block argument #0 with array type}}
3+
// expected-error@+1 {{'func.func' op cannot emit block argument #0 with type '!emitc.array<4xi8>'}}
44
func.func @array_as_block_argument(!emitc.array<4xi8>) {
55
^bb0(%arg0 : !emitc.array<4xi8>):
66
cf.br ^bb1(%arg0 : !emitc.array<4xi8>)
77
^bb1(%a : !emitc.array<4xi8>):
8-
return
8+
return
9+
}
10+
11+
// -----
12+
13+
// expected-error@+1 {{'emitc.func' op cannot emit block argument #0 with type '!emitc.lvalue<i32>'}}
14+
emitc.func @lvalue_as_block_argument() {
15+
^bb0:
16+
%0 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>
17+
cf.br ^bb1(%0 : !emitc.lvalue<i32>)
18+
^bb1(%a : !emitc.lvalue<i32>):
19+
emitc.return
920
}

0 commit comments

Comments
 (0)