-
Notifications
You must be signed in to change notification settings - Fork 14k
[mlir][emitc] Fix the emitc::ExpressionOp #143894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-emitc Author: Vlad Lazar (Vladislave0-0) ChangesFix the lack of verification that the definingOp of the return value belongs to emitc::ExpressionOp Full diff: https://github.com/llvm/llvm-project/pull/143894.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index 1709654b90138..b917b00da7ffc 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -386,9 +386,7 @@ OpFoldResult emitc::ConstantOp::fold(FoldAdaptor adaptor) { return getValue(); }
Operation *ExpressionOp::getRootOp() {
auto yieldOp = cast<YieldOp>(getBody()->getTerminator());
Value yieldedValue = yieldOp.getResult();
- Operation *rootOp = yieldedValue.getDefiningOp();
- assert(rootOp && "Yielded value not defined within expression");
- return rootOp;
+ return yieldedValue.getDefiningOp();
}
LogicalResult ExpressionOp::verify() {
@@ -406,6 +404,14 @@ LogicalResult ExpressionOp::verify() {
if (!yieldResult)
return emitOpError("must yield a value at termination");
+ Operation *rootOp = yieldResult.getDefiningOp();
+
+ if (!rootOp)
+ return emitOpError("yielded value has no defining op");
+
+ if (!isa<emitc::ExpressionOp>(rootOp->getParentOp()))
+ return emitOpError("yielded value not defined within expression");
+
Type yieldType = yieldResult.getType();
if (resultType != yieldType)
diff --git a/mlir/test/Dialect/EmitC/invalid_ops.mlir b/mlir/test/Dialect/EmitC/invalid_ops.mlir
index 3793dfe3f173b..3946a36a83c6f 100644
--- a/mlir/test/Dialect/EmitC/invalid_ops.mlir
+++ b/mlir/test/Dialect/EmitC/invalid_ops.mlir
@@ -346,6 +346,28 @@ func.func @test_expression_multiple_results(%arg0: i32) -> i32 {
// -----
+emitc.func @test_expression_no_defining_op(%a : i32) {
+ // expected-error @+1 {{'emitc.expression' op yielded value has no defining op}}
+ %res = emitc.expression : i32 {
+ emitc.yield %a : i32
+ }
+
+ return
+}
+
+// -----
+
+emitc.func @test_expression_op_outside_expression() {
+ %cond = literal "true" : i1
+ // expected-error @+1 {{'emitc.expression' op yielded value not defined within expression}}
+ %res = emitc.expression : i1 {
+ emitc.yield %cond : i1
+ }
+ return
+}
+
+// -----
+
// expected-error @+1 {{'emitc.func' op requires zero or exactly one result, but has 2}}
emitc.func @multiple_results(%0: i32) -> (i32, i32) {
emitc.return %0 : i32
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good to me!
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ C/C++ code formatter, clang-format found issues in your code.⚠️ You can test this locally with the following command:
View the diff from clang-format here.
Seems you have some trailing whitespaces which you need to remove.
Fix the lack of verification that the definingOp of the return value belongs to emitc::ExpressionOp
46ff1ea
to
604fff1
Compare
Thanks! Resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can make the check more explicit; other than that LGTM.
Fixed the check that the yielded value is defined within expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Let me know if I should merge on your behalf.
Yes, that would be nice, because I don't have the rights to merge. |
@Vladislave0-0, before merging, please follow https://llvm.org/docs/DeveloperPolicy.html#email-addresses:
|
Thanks, changed. |
@Vladislave0-0 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/30943 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/80/builds/14074 Here is the relevant piece of the build log for the reference
|
Fix the lack of verification that the definingOp of the return value belongs to emitc::ExpressionOp.
Fix the lack of verification that the definingOp of the return value belongs to emitc::ExpressionOp.