Skip to content

Commit 1d3bcf9

Browse files
authored
[flang] Better error recovery for REAL(x, [KIND=]bad) (llvm#108222)
There's two entries in the intrinsic table for REAL; the first handles the REAL(z) case of a COMPLEX argument, and the second handles the data type/kind conversion case. In the case of REAL(x,bad) with a bad or unsupported kind of REAL, neither table entry was matching. In the event of an unrecognized intrinsic function, the compiler emits the first error message that resulted, which was confusing here because it was a complaint about having too many arguments. Reversing the order of the intrinsic table entries would fix the error message, but would also have broken REAL(z) with a complex argument, since it would then be treated as REAL(z,KIND=KIND(0.)) rather than REAL(z,KIND=KIND(z)). The fix is to let the second entry "hit" with improved error recovery.
1 parent eb8cc89 commit 1d3bcf9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,7 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
22642264
messages.Say("'kind=' argument must be a constant scalar integer "
22652265
"whose value is a supported kind for the "
22662266
"intrinsic result type"_err_en_US);
2267-
return std::nullopt;
2267+
// use default kind below for error recovery
22682268
} else if (kindDummyArg->flags.test(ArgFlag::defaultsToSameKind)) {
22692269
CHECK(sameArg);
22702270
resultType = *sameArg->GetType();
@@ -2274,6 +2274,8 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
22742274
DynamicType{TypeCategory::Integer, defaults.sizeIntegerKind()};
22752275
} else {
22762276
CHECK(kindDummyArg->flags.test(ArgFlag::defaultsToDefaultForResult));
2277+
}
2278+
if (!resultType) {
22772279
int kind{defaults.GetDefaultKind(*category)};
22782280
if (*category == TypeCategory::Character) { // ACHAR & CHAR
22792281
resultType = DynamicType{kind, 1};

flang/test/Semantics/kinds06.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
!RUN: %python %S/test_errors.py %s %flang_fc1
2+
!ERROR: 'kind=' argument must be a constant scalar integer whose value is a supported kind for the intrinsic result type
3+
print *, real(1.,666)
4+
end

0 commit comments

Comments
 (0)