[flang-commits] [flang] 7ea7864 - [flang] Improve error message output (#102324)
via flang-commits
flang-commits at lists.llvm.org
Thu Aug 8 11:08:51 PDT 2024
Author: Peter Klausler
Date: 2024-08-08T11:08:48-07:00
New Revision: 7ea78643fe1577afb60bfc670357a79be53a31e8
URL: https://github.com/llvm/llvm-project/commit/7ea78643fe1577afb60bfc670357a79be53a31e8
DIFF: https://github.com/llvm/llvm-project/commit/7ea78643fe1577afb60bfc670357a79be53a31e8.diff
LOG: [flang] Improve error message output (#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.
Added:
Modified:
flang/lib/Evaluate/check-expression.cpp
flang/test/Semantics/structconst02.f90
Removed:
################################################################################
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