Skip to content

Commit 9eee396

Browse files
[flang] "Almost NFC" changes to fir::runtime::genCharCompare() (#168563)
As part of investigating a related issue, I made the following changes to fir::runtime::genCharCompare(): - Renamed a variable - Added an error check for the same kind of input args - Updated another error check to use the same error found elsewhere in this source file
1 parent 7fe3564 commit 9eee396

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

flang/lib/Optimizer/Builder/Runtime/Character.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,34 @@ fir::runtime::genCharCompare(fir::FirOpBuilder &builder, mlir::Location loc,
9494
mlir::arith::CmpIPredicate cmp,
9595
mlir::Value lhsBuff, mlir::Value lhsLen,
9696
mlir::Value rhsBuff, mlir::Value rhsLen) {
97-
mlir::func::FuncOp beginFunc;
98-
switch (discoverKind(lhsBuff.getType())) {
97+
int lhsKind = discoverKind(lhsBuff.getType());
98+
int rhsKind = discoverKind(rhsBuff.getType());
99+
if (lhsKind != rhsKind) {
100+
fir::emitFatalError(loc, "runtime does not support comparison of different "
101+
"CHARACTER kind values");
102+
}
103+
mlir::func::FuncOp func;
104+
switch (lhsKind) {
99105
case 1:
100-
beginFunc = fir::runtime::getRuntimeFunc<mkRTKey(CharacterCompareScalar1)>(
106+
func = fir::runtime::getRuntimeFunc<mkRTKey(CharacterCompareScalar1)>(
101107
loc, builder);
102108
break;
103109
case 2:
104-
beginFunc = fir::runtime::getRuntimeFunc<mkRTKey(CharacterCompareScalar2)>(
110+
func = fir::runtime::getRuntimeFunc<mkRTKey(CharacterCompareScalar2)>(
105111
loc, builder);
106112
break;
107113
case 4:
108-
beginFunc = fir::runtime::getRuntimeFunc<mkRTKey(CharacterCompareScalar4)>(
114+
func = fir::runtime::getRuntimeFunc<mkRTKey(CharacterCompareScalar4)>(
109115
loc, builder);
110116
break;
111117
default:
112-
llvm_unreachable("runtime does not support CHARACTER KIND");
118+
fir::emitFatalError(
119+
loc, "unsupported CHARACTER kind value. Runtime expects 1, 2, or 4.");
113120
}
114-
auto fTy = beginFunc.getFunctionType();
121+
auto fTy = func.getFunctionType();
115122
auto args = fir::runtime::createArguments(builder, loc, fTy, lhsBuff, rhsBuff,
116123
lhsLen, rhsLen);
117-
auto tri = fir::CallOp::create(builder, loc, beginFunc, args).getResult(0);
124+
auto tri = fir::CallOp::create(builder, loc, func, args).getResult(0);
118125
auto zero = builder.createIntegerConstant(loc, tri.getType(), 0);
119126
return mlir::arith::CmpIOp::create(builder, loc, cmp, tri, zero);
120127
}

0 commit comments

Comments
 (0)