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(); }
386386Operation *ExpressionOp::getRootOp () {
387387 auto yieldOp = cast<YieldOp>(getBody ()->getTerminator ());
388388 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 ();
392390}
393391
394392LogicalResult ExpressionOp::verify () {
@@ -406,6 +404,14 @@ LogicalResult ExpressionOp::verify() {
406404 if (!yieldResult)
407405 return emitOpError (" must yield a value at termination" );
408406
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+
409415 Type yieldType = yieldResult.getType ();
410416
411417 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 {
346346
347347// -----
348348
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+
349371// expected-error @+1 {{'emitc.func' op requires zero or exactly one result, but has 2}}
350372emitc.func @multiple_results (%0: i32 ) -> (i32 , i32 ) {
351373 emitc.return %0 : i32
You can’t perform that action at this time.
0 commit comments