Skip to content

Conversation

akuhlens
Copy link
Contributor

@akuhlens akuhlens commented Oct 3, 2025

fixes #161694

Exposes that some sequences of duplicate messages are being printed, which is fixed in #161916 .

@akuhlens akuhlens requested a review from klausler October 3, 2025 21:57
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Oct 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 3, 2025

@llvm/pr-subscribers-flang-parser

@llvm/pr-subscribers-flang-semantics

Author: Andre Kuhlenschmidt (akuhlens)

Changes

fixes #161694

Exposes that some sequences of duplicate messages are being printed.


Full diff: https://github.com/llvm/llvm-project/pull/161915.diff

3 Files Affected:

  • (modified) flang/lib/Evaluate/check-expression.cpp (+11-6)
  • (modified) flang/test/Semantics/intrinsics03.f90 (+4-1)
  • (modified) flang/test/Semantics/intrinsics04.f90 (+4-1)
diff --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 8931cbe485ac2..012b44e7d3747 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -135,16 +135,21 @@ bool IsConstantExprHelper<INVARIANT>::operator()(
     } else if (proc.IsPure()) {
       std::size_t j{0};
       for (const auto &arg : call.arguments()) {
-        if (const auto *dataDummy{j < proc.dummyArguments.size()
-                    ? std::get_if<characteristics::DummyDataObject>(
-                          &proc.dummyArguments[j].u)
-                    : nullptr};
-            dataDummy &&
+        const auto *dataDummy{j < proc.dummyArguments.size()
+                ? std::get_if<characteristics::DummyDataObject>(
+                      &proc.dummyArguments[j].u)
+                : nullptr};
+        if (dataDummy &&
             dataDummy->attrs.test(
                 characteristics::DummyDataObject::Attr::OnlyIntrinsicInquiry)) {
           // The value of the argument doesn't matter
         } else if (!arg) {
-          return false;
+          // Missing optional arguments are constant
+          if (!(dataDummy &&
+                  dataDummy->attrs.test(
+                      characteristics::DummyDataObject::Attr::Optional))) {
+            return false;
+          }
         } else if (const auto *expr{arg->UnwrapExpr()};
             !expr || !(*this)(*expr)) {
           return false;
diff --git a/flang/test/Semantics/intrinsics03.f90 b/flang/test/Semantics/intrinsics03.f90
index a5b13b655cf41..2b07c5ee98eaf 100644
--- a/flang/test/Semantics/intrinsics03.f90
+++ b/flang/test/Semantics/intrinsics03.f90
@@ -129,6 +129,9 @@ subroutine ichar_tests()
   !Without -Wportability, the warning isn't emitted and the parameter is constant.
   integer, parameter :: a2 = ichar('B ')
   !ERROR: Character in intrinsic function ichar must have length one
-  !ERROR: Must be a constant value
+  !ERROR: Value of named constant 'a3' (ichar("")) cannot be computed as a constant value
+  !ERROR: Character in intrinsic function ichar must have length one
+  !ERROR: Value of named constant 'a3' (ichar("")) cannot be computed as a constant value
+  !ERROR: Character in intrinsic function ichar must have length one
   integer, parameter :: a3 = ichar('')
 end subroutine
diff --git a/flang/test/Semantics/intrinsics04.f90 b/flang/test/Semantics/intrinsics04.f90
index abb8fe321a572..8b6b29fed2128 100644
--- a/flang/test/Semantics/intrinsics04.f90
+++ b/flang/test/Semantics/intrinsics04.f90
@@ -29,6 +29,9 @@ subroutine ichar_tests()
   !WARNING: Character in intrinsic function ichar should have length one [-Wportability]
   integer, parameter :: a2 = ichar('B ')
   !ERROR: Character in intrinsic function ichar must have length one
-  !ERROR: Must be a constant value
+  !ERROR: Value of named constant 'a3' (ichar("")) cannot be computed as a constant value
+  !ERROR: Character in intrinsic function ichar must have length one
+  !ERROR: Value of named constant 'a3' (ichar("")) cannot be computed as a constant value
+  !ERROR: Character in intrinsic function ichar must have length one
   integer, parameter :: a3 = ichar('')
 end subroutine

@akuhlens akuhlens requested a review from klausler October 3, 2025 22:22
@akuhlens akuhlens force-pushed the andre/issue-161694 branch from d853b5d to b6f9548 Compare October 3, 2025 23:13
akuhlens added a commit that referenced this pull request Oct 4, 2025
Fixes bug exposed by #161915 by keeping a cache of messages printed at a given location.
@akuhlens akuhlens force-pushed the andre/issue-161694 branch from b6f9548 to b395191 Compare October 4, 2025 04:43
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 4, 2025
Fixes bug exposed by llvm/llvm-project#161915 by keeping a cache of messages printed at a given location.
@akuhlens akuhlens merged commit 823094e into llvm:main Oct 4, 2025
9 checks passed
Copy link
Contributor

@DanielCChen DanielCChen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test cases are fixed.
Thanks.

!ERROR: Value of KIND type parameter 'r' must be constant
!WARNING: specification expression refers to local object 'six' (initialized and saved) [-Wsaved-local-in-spec-expr]
!WARNING: specification expression refers to local object 'twenty_three' (initialized and saved) [-Wsaved-local-in-spec-expr]
type(a(six, twenty_three)) :: a2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there is a trailing blank after a2, which caused a warning when apply the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:parser flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] Flang seems too restrictive on constant expression usage.
4 participants