[flang-commits] [flang] 10b0a07 - [flang] Fold KIND= arguments in intrinsic function references (#124666)
via flang-commits
flang-commits at lists.llvm.org
Fri Jan 31 10:53:18 PST 2025
Author: Peter Klausler
Date: 2025-01-31T10:53:14-08:00
New Revision: 10b0a07e11b6fc53f2af63b7da7256a3e509835a
URL: https://github.com/llvm/llvm-project/commit/10b0a07e11b6fc53f2af63b7da7256a3e509835a
DIFF: https://github.com/llvm/llvm-project/commit/10b0a07e11b6fc53f2af63b7da7256a3e509835a.diff
LOG: [flang] Fold KIND= arguments in intrinsic function references (#124666)
KIND= arguments in e.g. ACHAR(..., KIND=...) intrinsic function
references must be compilation-time constant expressions. The compiler
was failing to evaluate those expressions if they were not actually
literaly constant values.
Fixes https://github.com/llvm/llvm-project/issues/124618.
Added:
flang/test/Evaluate/bug124618.f90
Modified:
flang/lib/Evaluate/intrinsics.cpp
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 1c7e564f706ad47..ea33034f47c0a16 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -2364,7 +2364,7 @@ std::optional<SpecificCall> 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
@@ -2376,9 +2376,8 @@ std::optional<SpecificCall> 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 000000000000000..939985e588af275
--- /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
More information about the flang-commits
mailing list