[flang-commits] [flang] [flang] fix some FIR verifiers that did not return expected failure (PR #158686)

via flang-commits flang-commits at lists.llvm.org
Mon Sep 15 10:00:16 PDT 2025


https://github.com/jeanPerier created https://github.com/llvm/llvm-project/pull/158686

Some `return` were missing before `emitOpError`, leading the compiler to print an error and continue, leading to the same error to be raised again and again at each verifier pass without a proper abort.

>From dc5fa454f509bebbc60637453d099e77507495e9 Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Mon, 15 Sep 2025 09:27:44 -0700
Subject: [PATCH] [flang] fix some FIR verifiers that did not return expected
 failure

---
 flang/lib/Optimizer/Dialect/FIROps.cpp        | 25 +++++++++++--------
 .../Dialect/FortranVariableInterface.cpp      | 10 +++++---
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 87f9899aa7879..31dacaee23fb0 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1774,12 +1774,13 @@ llvm::LogicalResult fir::CoordinateOp::verify() {
             return emitOpError("too many operands for len_param_index case");
         }
         if (eleTy != index.getOnType())
-          emitOpError(
+          return emitOpError(
               "len_param_index type not compatible with reference type");
         return mlir::success();
       } else if (auto index = mlir::dyn_cast<fir::FieldIndexOp>(defOp)) {
         if (eleTy != index.getOnType())
-          emitOpError("field_index type not compatible with reference type");
+          return emitOpError(
+              "field_index type not compatible with reference type");
         if (auto recTy = mlir::dyn_cast<fir::RecordType>(eleTy)) {
           eleTy = recTy.getType(index.getFieldName());
           continue;
@@ -3406,26 +3407,30 @@ llvm::LogicalResult fir::SaveResultOp::verify() {
   auto eleTy = resultType;
   if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(resultType)) {
     if (seqTy.getDimension() != shapeTyRank)
-      emitOpError("shape operand must be provided and have the value rank "
-                  "when the value is a fir.array");
+      return emitOpError(
+          "shape operand must be provided and have the value rank "
+          "when the value is a fir.array");
     eleTy = seqTy.getEleTy();
   } else {
     if (shapeTyRank != 0)
-      emitOpError(
+      return emitOpError(
           "shape operand should only be provided if the value is a fir.array");
   }
 
   if (auto recTy = mlir::dyn_cast<fir::RecordType>(eleTy)) {
     if (recTy.getNumLenParams() != getTypeparams().size())
-      emitOpError("length parameters number must match with the value type "
-                  "length parameters");
+      return emitOpError(
+          "length parameters number must match with the value type "
+          "length parameters");
   } else if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
     if (getTypeparams().size() > 1)
-      emitOpError("no more than one length parameter must be provided for "
-                  "character value");
+      return emitOpError(
+          "no more than one length parameter must be provided for "
+          "character value");
   } else {
     if (!getTypeparams().empty())
-      emitOpError("length parameters must not be provided for this value type");
+      return emitOpError(
+          "length parameters must not be provided for this value type");
   }
 
   return mlir::success();
diff --git a/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp b/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp
index f16072a90dfae..925276e1f86c4 100644
--- a/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp
+++ b/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp
@@ -53,8 +53,9 @@ fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) {
         shapeRank = shapeShiftType.getRank();
       } else {
         if (!sourceIsBoxValue)
-          emitOpError("of array entity with a raw address base must have a "
-                      "shape operand that is a shape or shapeshift");
+          return emitOpError(
+              "of array entity with a raw address base must have a "
+              "shape operand that is a shape or shapeshift");
         shapeRank = mlir::cast<fir::ShiftType>(shape.getType()).getRank();
       }
 
@@ -62,8 +63,9 @@ fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) {
       if (!rank || *rank != shapeRank)
         return emitOpError("has conflicting shape and base operand ranks");
     } else if (!sourceIsBox) {
-      emitOpError("of array entity with a raw address base must have a shape "
-                  "operand that is a shape or shapeshift");
+      return emitOpError(
+          "of array entity with a raw address base must have a shape "
+          "operand that is a shape or shapeshift");
     }
   }
   return mlir::success();



More information about the flang-commits mailing list