[flang-commits] [flang] [flang] Improve error message output (PR #102324)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Wed Aug 7 08:30:36 PDT 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/102324
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.
>From 25bc625bde2a658f54907e003afaf93509679a70 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 7 Aug 2024 08:25:42 -0700
Subject: [PATCH] [flang] Improve error message output
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.
---
flang/lib/Evaluate/check-expression.cpp | 2 +-
flang/test/Semantics/structconst02.f90 | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
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()
More information about the flang-commits
mailing list