[Mlir-commits] [mlir] 6331460 - [mlir] Fix ignoring return value warning for Toy CLIs
Kai Sasaki
llvmlistbot at llvm.org
Sun Apr 2 14:42:32 PDT 2023
Author: Kai Sasaki
Date: 2023-04-03T06:41:54+09:00
New Revision: 633146093c4ea78dc8f56a27006fe4eed84be370
URL: https://github.com/llvm/llvm-project/commit/633146093c4ea78dc8f56a27006fe4eed84be370
DIFF: https://github.com/llvm/llvm-project/commit/633146093c4ea78dc8f56a27006fe4eed84be370.diff
LOG: [mlir] Fix ignoring return value warning for Toy CLIs
After [the change](https://github.com/llvm/llvm-project/commit/470f3cee3557974bb1820722bf82d86b8909199b) returning LogicalResult from applyPassManagerCLIOptions, the warning message is shown in the Toy CLIs saying it's not using the returned values. We can check the result and return non-zero value as the pass failure.
```
/Users/sasaki/dev/llvm-project/mlir/examples/toy/Ch3/toyc.cpp:118:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
applyPassManagerCLOptions(pm);
^~~~~~~~~~~~~~~~~~~~~~~~~ ~~
1 warning generated.
[473/485] Building CXX object tools/mlir/examples/toy/Ch4/CMakeFiles/toyc-ch4.dir/toyc.cpp.o
/Users/sasaki/dev/llvm-project/mlir/examples/toy/Ch4/toyc.cpp:119:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
applyPassManagerCLOptions(pm);
^~~~~~~~~~~~~~~~~~~~~~~~~ ~~
1 warning generated.
[477/485] Building CXX object tools/mlir/examples/toy/Ch5/CMakeFiles/toyc-ch5.dir/toyc.cpp.o
/Users/sasaki/dev/llvm-project/mlir/examples/toy/Ch5/toyc.cpp:122:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
applyPassManagerCLOptions(pm);
^~~~~~~~~~~~~~~~~~~~~~~~~ ~~
1 warning generated.
[479/485] Building CXX object tools/mlir/examples/toy/Ch6/CMakeFiles/toyc-ch6.dir/toyc.cpp.o
/Users/sasaki/dev/llvm-project/mlir/examples/toy/Ch6/toyc.cpp:139:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
applyPassManagerCLOptions(pm);
^~~~~~~~~~~~~~~~~~~~~~~~~ ~~
1 warning generated.
[481/485] Building CXX object tools/mlir/examples/toy/Ch7/CMakeFiles/toyc-ch7.dir/toyc.cpp.o
/Users/sasaki/dev/llvm-project/mlir/examples/toy/Ch7/toyc.cpp:139:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
applyPassManagerCLOptions(pm);
^~~~~~~~~~~~~~~~~~~~~~~~~ ~~
1 warning generated.
```
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D147402
Added:
Modified:
mlir/examples/toy/Ch3/toyc.cpp
mlir/examples/toy/Ch4/toyc.cpp
mlir/examples/toy/Ch5/toyc.cpp
mlir/examples/toy/Ch6/toyc.cpp
mlir/examples/toy/Ch7/toyc.cpp
Removed:
################################################################################
diff --git a/mlir/examples/toy/Ch3/toyc.cpp b/mlir/examples/toy/Ch3/toyc.cpp
index 859791336ab2f..4b7f41285e066 100644
--- a/mlir/examples/toy/Ch3/toyc.cpp
+++ b/mlir/examples/toy/Ch3/toyc.cpp
@@ -115,7 +115,8 @@ int dumpMLIR() {
if (enableOpt) {
mlir::PassManager pm(module.get()->getName());
// Apply any generic pass manager command line options and run the pipeline.
- (void)applyPassManagerCLOptions(pm);
+ if (mlir::failed(mlir::applyPassManagerCLOptions(pm)))
+ return 4;
// Add a run of the canonicalizer to optimize the mlir module.
pm.addNestedPass<mlir::toy::FuncOp>(mlir::createCanonicalizerPass());
diff --git a/mlir/examples/toy/Ch4/toyc.cpp b/mlir/examples/toy/Ch4/toyc.cpp
index b866ffaeb62cb..5e46b41ed1294 100644
--- a/mlir/examples/toy/Ch4/toyc.cpp
+++ b/mlir/examples/toy/Ch4/toyc.cpp
@@ -116,7 +116,8 @@ int dumpMLIR() {
if (enableOpt) {
mlir::PassManager pm(module.get()->getName());
// Apply any generic pass manager command line options and run the pipeline.
- (void)applyPassManagerCLOptions(pm);
+ if (mlir::failed(mlir::applyPassManagerCLOptions(pm)))
+ return 4;
// Inline all functions into main and then delete them.
pm.addPass(mlir::createInlinerPass());
diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp
index 3cc2683c193ff..abe052ab5ebed 100644
--- a/mlir/examples/toy/Ch5/toyc.cpp
+++ b/mlir/examples/toy/Ch5/toyc.cpp
@@ -119,7 +119,8 @@ int dumpMLIR() {
mlir::PassManager pm(module.get()->getName());
// Apply any generic pass manager command line options and run the pipeline.
- (void)applyPassManagerCLOptions(pm);
+ if (mlir::failed(mlir::applyPassManagerCLOptions(pm)))
+ return 4;
// Check to see what granularity of MLIR we are compiling to.
bool isLoweringToAffine = emitAction >= Action::DumpMLIRAffine;
diff --git a/mlir/examples/toy/Ch6/toyc.cpp b/mlir/examples/toy/Ch6/toyc.cpp
index e637cf976c014..f19744b36e642 100644
--- a/mlir/examples/toy/Ch6/toyc.cpp
+++ b/mlir/examples/toy/Ch6/toyc.cpp
@@ -136,7 +136,8 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
mlir::PassManager pm(module.get()->getName());
// Apply any generic pass manager command line options and run the pipeline.
- (void)applyPassManagerCLOptions(pm);
+ if (mlir::failed(mlir::applyPassManagerCLOptions(pm)))
+ return 4;
// Check to see what granularity of MLIR we are compiling to.
bool isLoweringToAffine = emitAction >= Action::DumpMLIRAffine;
diff --git a/mlir/examples/toy/Ch7/toyc.cpp b/mlir/examples/toy/Ch7/toyc.cpp
index c2effc7317c0f..a4990dcd65a1a 100644
--- a/mlir/examples/toy/Ch7/toyc.cpp
+++ b/mlir/examples/toy/Ch7/toyc.cpp
@@ -136,7 +136,8 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
mlir::PassManager pm(module.get()->getName());
// Apply any generic pass manager command line options and run the pipeline.
- (void)applyPassManagerCLOptions(pm);
+ if (mlir::failed(mlir::applyPassManagerCLOptions(pm)))
+ return 4;
// Check to see what granularity of MLIR we are compiling to.
bool isLoweringToAffine = emitAction >= Action::DumpMLIRAffine;
More information about the Mlir-commits
mailing list