[mlir] Fix ignoring return value warning for Toy CLIs
authorKai Sasaki <lewuathe@gmail.com>
Sun, 2 Apr 2023 21:36:56 +0000 (06:36 +0900)
committerKai Sasaki <lewuathe@gmail.com>
Sun, 2 Apr 2023 21:41:54 +0000 (06:41 +0900)
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

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

index 8597913..4b7f412 100644 (file)
@@ -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());
index b866ffa..5e46b41 100644 (file)
@@ -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());
index 3cc2683..abe052a 100644 (file)
@@ -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;
index e637cf9..f19744b 100644 (file)
@@ -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;
index c2effc7..a4990dc 100644 (file)
@@ -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;