[flang-commits] [flang] [flang] Improve error message output (PR #102324)
via flang-commits
flang-commits at lists.llvm.org
Wed Aug 7 08:31:09 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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
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()
``````````
</details>
https://github.com/llvm/llvm-project/pull/102324
More information about the flang-commits
mailing list