Skip to content

Commit

Permalink
[flang] Improve error message output (llvm#102324)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
klausler authored Aug 8, 2024
1 parent b949a6f commit 7ea7864
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flang/lib/Evaluate/check-expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Semantics/structconst02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7ea7864

Please sign in to comment.