File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -386,9 +386,7 @@ OpFoldResult emitc::ConstantOp::fold(FoldAdaptor adaptor) { return getValue(); }
386
386
Operation *ExpressionOp::getRootOp () {
387
387
auto yieldOp = cast<YieldOp>(getBody ()->getTerminator ());
388
388
Value yieldedValue = yieldOp.getResult ();
389
- Operation *rootOp = yieldedValue.getDefiningOp ();
390
- assert (rootOp && " Yielded value not defined within expression" );
391
- return rootOp;
389
+ return yieldedValue.getDefiningOp ();
392
390
}
393
391
394
392
LogicalResult ExpressionOp::verify () {
@@ -406,6 +404,14 @@ LogicalResult ExpressionOp::verify() {
406
404
if (!yieldResult)
407
405
return emitOpError (" must yield a value at termination" );
408
406
407
+ Operation *rootOp = yieldResult.getDefiningOp ();
408
+
409
+ if (!rootOp)
410
+ return emitOpError (" yielded value has no defining op" );
411
+
412
+ if (rootOp->getParentOp () != getOperation ())
413
+ return emitOpError (" yielded value not defined within expression" );
414
+
409
415
Type yieldType = yieldResult.getType ();
410
416
411
417
if (resultType != yieldType)
Original file line number Diff line number Diff line change @@ -346,6 +346,28 @@ func.func @test_expression_multiple_results(%arg0: i32) -> i32 {
346
346
347
347
// -----
348
348
349
+ emitc.func @test_expression_no_defining_op (%a : i32 ) {
350
+ // expected-error @+1 {{'emitc.expression' op yielded value has no defining op}}
351
+ %res = emitc.expression : i32 {
352
+ emitc.yield %a : i32
353
+ }
354
+
355
+ return
356
+ }
357
+
358
+ // -----
359
+
360
+ emitc.func @test_expression_op_outside_expression () {
361
+ %cond = literal " true" : i1
362
+ // expected-error @+1 {{'emitc.expression' op yielded value not defined within expression}}
363
+ %res = emitc.expression : i1 {
364
+ emitc.yield %cond : i1
365
+ }
366
+ return
367
+ }
368
+
369
+ // -----
370
+
349
371
// expected-error @+1 {{'emitc.func' op requires zero or exactly one result, but has 2}}
350
372
emitc.func @multiple_results (%0: i32 ) -> (i32 , i32 ) {
351
373
emitc.return %0 : i32
You can’t perform that action at this time.
0 commit comments