Skip to content

[flang] Improve error message output #102324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2024
Merged

[flang] Improve error message output #102324

merged 1 commit into from
Aug 8, 2024

Conversation

klausler
Copy link
Contributor

@klausler klausler commented Aug 7, 2024

When a local character variable with non-constant length has an initializer, it's an error in a couple of ways (SAVE variable with unknown size, static initializer that isn't constant due to conversion to an unknown length). The error that f18 reports is the latter, but the message contains a formatted representation of the initialization expression that exposes a non-Fortran %SET_LENGTH() operation. Print the original expression in the message instead.

When a local character variable with non-constant length has an
initializer, it's an error in a couple of ways (SAVE variable with
unknown size, static initializer that isn't constant due to conversion
to an unknown length).  The error that f18 reports is the latter,
but the message contains a formatted representation of the initialization
expression that exposes a non-Fortran %SET_LENGTH() operation.
Print the original expression in the message instead.
@klausler klausler requested a review from clementval August 7, 2024 15:30
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Aug 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 7, 2024

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

When a local character variable with non-constant length has an initializer, it's an error in a couple of ways (SAVE variable with unknown size, static initializer that isn't constant due to conversion to an unknown length). The error that f18 reports is the latter, but the message contains a formatted representation of the initialization expression that exposes a non-Fortran %SET_LENGTH() operation. Print the original expression in the message instead.


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

2 Files Affected:

  • (modified) flang/lib/Evaluate/check-expression.cpp (+1-1)
  • (modified) flang/test/Semantics/structconst02.f90 (+1-1)
diff --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 342aac4dd5d53e..fef4620857a08a 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -493,7 +493,7 @@ std::optional<Expr<SomeType>> NonPointerInitializationExpr(const Symbol &symbol,
       } else {
         context.messages().Say(
             "Initialization expression for '%s' (%s) cannot be computed as a constant value"_err_en_US,
-            symbol.name(), folded.AsFortran());
+            symbol.name(), x.AsFortran());
       }
     } else if (xType) {
       context.messages().Say(
diff --git a/flang/test/Semantics/structconst02.f90 b/flang/test/Semantics/structconst02.f90
index 24ec0a19640157..71d6b720fb41a4 100644
--- a/flang/test/Semantics/structconst02.f90
+++ b/flang/test/Semantics/structconst02.f90
@@ -14,7 +14,7 @@ end function realfunc
     integer(kind=ik) :: ix = int(0,kind=ik)
     real(kind=rk) :: rx = real(0.,kind=rk)
     complex(kind=zk) :: zx = cmplx(0.,0.,kind=zk)
-    !ERROR: Initialization expression for 'cx' (%SET_LENGTH(" ",len)) cannot be computed as a constant value
+    !ERROR: Initialization expression for 'cx' (" ") cannot be computed as a constant value
     character(kind=ck,len=len) :: cx = ' '
     logical(kind=lk) :: lx = .false.
     real(kind=rk), pointer :: rp => NULL()

Copy link
Contributor

@clementval clementval left a comment

Choose a reason for hiding this comment

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

LGTM

@klausler klausler merged commit 7ea7864 into llvm:main Aug 8, 2024
10 checks passed
@klausler klausler deleted the ij8 branch August 8, 2024 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants