[flang-commits] [flang] [flang] Catch usage of : and * lengths in array c'tors (PR #128974)
via flang-commits
flang-commits at lists.llvm.org
Wed Feb 26 16:19:10 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
The definition of an array constructor doesn't prelude the use of [character(:)::] or [character(*)::] directly, but there is language elsewhere in the standard that restricts their use to specific contexts, neither of which include explicitly typed array constructors.
Fixes https://github.com/llvm/llvm-project/issues/128755.
---
Full diff: https://github.com/llvm/llvm-project/pull/128974.diff
2 Files Affected:
- (modified) flang/lib/Semantics/expression.cpp (+4-2)
- (modified) flang/test/Semantics/array-constr-len.f90 (+4)
``````````diff
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 6949e5693d08f..2aeb8aabf5ddb 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -78,8 +78,10 @@ static std::optional<DynamicTypeWithLength> AnalyzeTypeSpec(
const semantics::CharacterTypeSpec &cts{
typeSpec->characterTypeSpec()};
const semantics::ParamValue &len{cts.length()};
- // N.B. CHARACTER(LEN=*) is allowed in type-specs in ALLOCATE() &
- // type guards, but not in array constructors.
+ if (len.isAssumed() || len.isDeferred()) {
+ context.messages().Say(
+ "A length specifier of '*' or ':' may not appear in the type of an array constructor"_err_en_US);
+ }
DynamicTypeWithLength type{DynamicType{kind, len}};
if (auto lenExpr{type.LEN()}) {
type.length = Fold(context,
diff --git a/flang/test/Semantics/array-constr-len.f90 b/flang/test/Semantics/array-constr-len.f90
index 4de9c76c7041c..9b23026a16012 100644
--- a/flang/test/Semantics/array-constr-len.f90
+++ b/flang/test/Semantics/array-constr-len.f90
@@ -11,4 +11,8 @@ subroutine subr(s,n)
print *, [(s(1:1),j=1,0)] ! ok
print *, [character(2)::(s(1:n),j=1,0)] ! ok
print *, [character(n)::(s(1:n),j=1,0)]
+ !ERROR: A length specifier of '*' or ':' may not appear in the type of an array constructor
+ print *, [ character(:) :: ]
+ !ERROR: A length specifier of '*' or ':' may not appear in the type of an array constructor
+ print *, [ character(*) :: ]
end
``````````
</details>
https://github.com/llvm/llvm-project/pull/128974
More information about the flang-commits
mailing list