@@ -1360,8 +1360,21 @@ llvm::LogicalResult hlfir::CShiftOp::verify() {
13601360 mlir::Type shiftTy = hlfir::getFortranElementOrSequenceType (shift.getType ());
13611361
13621362 if (eleTy != resultEleTy)
1363- return emitOpError (
1364- " input and output arrays should have the same element type" );
1363+ if (mlir::isa<fir::CharacterType>(eleTy) &&
1364+ mlir::isa<fir::CharacterType>(resultEleTy)) {
1365+ auto eleCharTy = mlir::cast<fir::CharacterType>(eleTy);
1366+ auto resultCharTy = mlir::cast<fir::CharacterType>(resultEleTy);
1367+ if (eleCharTy.getFKind () != resultCharTy.getFKind ())
1368+ return emitOpError (" kind mismatch between input and output arrays" );
1369+ if (eleCharTy.getLen () != fir::CharacterType::unknownLen () &&
1370+ resultCharTy.getLen () != fir::CharacterType::unknownLen () &&
1371+ eleCharTy.getLen () != resultCharTy.getLen ())
1372+ return emitOpError (
1373+ " character LEN mismatch between input and output arrays" );
1374+ } else {
1375+ return emitOpError (
1376+ " input and output arrays should have the same element type" );
1377+ }
13651378
13661379 if (arrayRank != resultRank)
13671380 return emitOpError (" input and output arrays should have the same rank" );
@@ -1379,7 +1392,10 @@ llvm::LogicalResult hlfir::CShiftOp::verify() {
13791392 else if (auto dim = fir::getIntIfConstant (getDim ()))
13801393 dimVal = *dim;
13811394
1382- if (dimVal != -1 ) {
1395+ // The DIM argument may be statically invalid (e.g. exceed the
1396+ // input array rank) in dead code after constant propagation,
1397+ // so avoid some checks unless useStrictIntrinsicVerifier is true.
1398+ if (useStrictIntrinsicVerifier && dimVal != -1 ) {
13831399 if (dimVal < 1 )
13841400 return emitOpError (" DIM must be >= 1" );
13851401 if (dimVal > static_cast <int64_t >(arrayRank))
@@ -1394,7 +1410,7 @@ llvm::LogicalResult hlfir::CShiftOp::verify() {
13941410 return emitOpError (
13951411 " SHIFT's rank must be 1 less than the input array's rank" );
13961412
1397- if (dimVal != -1 ) {
1413+ if (useStrictIntrinsicVerifier && dimVal != -1 ) {
13981414 // SHIFT's shape must be [d(1), d(2), ..., d(DIM-1), d(DIM+1), ..., d(n)],
13991415 // where [d(1), d(2), ..., d(n)] is the shape of the ARRAY.
14001416 int64_t arrayDimIdx = 0 ;
0 commit comments