diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp index 29f8e5fcc49d5..ce9d4a4397092 100644 --- a/flang/lib/Evaluate/intrinsics.cpp +++ b/flang/lib/Evaluate/intrinsics.cpp @@ -2357,7 +2357,7 @@ std::optional IntrinsicInterface::Match( if (kindArg) { if (auto *expr{kindArg->UnwrapExpr()}) { CHECK(expr->Rank() == 0); - if (auto code{ToInt64(*expr)}) { + if (auto code{ToInt64(Fold(context, common::Clone(*expr)))}) { if (context.targetCharacteristics().IsTypeEnabled( *category, *code)) { if (*category == TypeCategory::Character) { // ACHAR & CHAR @@ -2369,9 +2369,8 @@ std::optional IntrinsicInterface::Match( } } } - messages.Say("'kind=' argument must be a constant scalar integer " - "whose value is a supported kind for the " - "intrinsic result type"_err_en_US); + messages.Say( + "'kind=' argument must be a constant scalar integer whose value is a supported kind for the intrinsic result type"_err_en_US); // use default kind below for error recovery } else if (kindDummyArg->flags.test(ArgFlag::defaultsToSameKind)) { CHECK(sameArg); diff --git a/flang/test/Evaluate/bug124618.f90 b/flang/test/Evaluate/bug124618.f90 new file mode 100644 index 0000000000000..939985e588af2 --- /dev/null +++ b/flang/test/Evaluate/bug124618.f90 @@ -0,0 +1,5 @@ +! RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck --allow-empty %s +!CHECK-NOT: error: +real x +print *, char(48, kind=size([x])) ! folds down to 1 +end