Skip to content

Commit dd29fbd

Browse files
authored
[flang] fix some FIR verifiers that did not return expected failure (#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.
1 parent 2a296ba commit dd29fbd

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,12 +1774,13 @@ llvm::LogicalResult fir::CoordinateOp::verify() {
17741774
return emitOpError("too many operands for len_param_index case");
17751775
}
17761776
if (eleTy != index.getOnType())
1777-
emitOpError(
1777+
return emitOpError(
17781778
"len_param_index type not compatible with reference type");
17791779
return mlir::success();
17801780
} else if (auto index = mlir::dyn_cast<fir::FieldIndexOp>(defOp)) {
17811781
if (eleTy != index.getOnType())
1782-
emitOpError("field_index type not compatible with reference type");
1782+
return emitOpError(
1783+
"field_index type not compatible with reference type");
17831784
if (auto recTy = mlir::dyn_cast<fir::RecordType>(eleTy)) {
17841785
eleTy = recTy.getType(index.getFieldName());
17851786
continue;
@@ -3406,26 +3407,30 @@ llvm::LogicalResult fir::SaveResultOp::verify() {
34063407
auto eleTy = resultType;
34073408
if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(resultType)) {
34083409
if (seqTy.getDimension() != shapeTyRank)
3409-
emitOpError("shape operand must be provided and have the value rank "
3410-
"when the value is a fir.array");
3410+
return emitOpError(
3411+
"shape operand must be provided and have the value rank "
3412+
"when the value is a fir.array");
34113413
eleTy = seqTy.getEleTy();
34123414
} else {
34133415
if (shapeTyRank != 0)
3414-
emitOpError(
3416+
return emitOpError(
34153417
"shape operand should only be provided if the value is a fir.array");
34163418
}
34173419

34183420
if (auto recTy = mlir::dyn_cast<fir::RecordType>(eleTy)) {
34193421
if (recTy.getNumLenParams() != getTypeparams().size())
3420-
emitOpError("length parameters number must match with the value type "
3421-
"length parameters");
3422+
return emitOpError(
3423+
"length parameters number must match with the value type "
3424+
"length parameters");
34223425
} else if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
34233426
if (getTypeparams().size() > 1)
3424-
emitOpError("no more than one length parameter must be provided for "
3425-
"character value");
3427+
return emitOpError(
3428+
"no more than one length parameter must be provided for "
3429+
"character value");
34263430
} else {
34273431
if (!getTypeparams().empty())
3428-
emitOpError("length parameters must not be provided for this value type");
3432+
return emitOpError(
3433+
"length parameters must not be provided for this value type");
34293434
}
34303435

34313436
return mlir::success();

flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,19 @@ fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) {
5353
shapeRank = shapeShiftType.getRank();
5454
} else {
5555
if (!sourceIsBoxValue)
56-
emitOpError("of array entity with a raw address base must have a "
57-
"shape operand that is a shape or shapeshift");
56+
return emitOpError(
57+
"of array entity with a raw address base must have a "
58+
"shape operand that is a shape or shapeshift");
5859
shapeRank = mlir::cast<fir::ShiftType>(shape.getType()).getRank();
5960
}
6061

6162
std::optional<unsigned> rank = getRank();
6263
if (!rank || *rank != shapeRank)
6364
return emitOpError("has conflicting shape and base operand ranks");
6465
} else if (!sourceIsBox) {
65-
emitOpError("of array entity with a raw address base must have a shape "
66-
"operand that is a shape or shapeshift");
66+
return emitOpError(
67+
"of array entity with a raw address base must have a shape "
68+
"operand that is a shape or shapeshift");
6769
}
6870
}
6971
return mlir::success();

0 commit comments

Comments
 (0)