[flang-commits] [flang] [flang] Catch deferred type parameters in ALLOCATE(type-spec::) (PR #139334)
via flang-commits
flang-commits at lists.llvm.org
Fri May 9 15:20:16 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
The type-spec in ALLOCATE may not have any deferred type parameters.
Fixes https://github.com/llvm/llvm-project/issues/138979.
---
Full diff: https://github.com/llvm/llvm-project/pull/139334.diff
2 Files Affected:
- (modified) flang/lib/Semantics/check-allocate.cpp (+8-2)
- (modified) flang/test/Semantics/allocate01.f90 (+4)
``````````diff
diff --git a/flang/lib/Semantics/check-allocate.cpp b/flang/lib/Semantics/check-allocate.cpp
index b426dd81334bb..2c215f45bf516 100644
--- a/flang/lib/Semantics/check-allocate.cpp
+++ b/flang/lib/Semantics/check-allocate.cpp
@@ -116,13 +116,19 @@ static std::optional<AllocateCheckerInfo> CheckAllocateOptions(
// C937
if (auto it{FindCoarrayUltimateComponent(*derived)}) {
context
- .Say("Type-spec in ALLOCATE must not specify a type with a coarray"
- " ultimate component"_err_en_US)
+ .Say(
+ "Type-spec in ALLOCATE must not specify a type with a coarray ultimate component"_err_en_US)
.Attach(it->name(),
"Type '%s' has coarray ultimate component '%s' declared here"_en_US,
info.typeSpec->AsFortran(), it.BuildResultDesignatorName());
}
}
+ if (auto dyType{evaluate::DynamicType::From(*info.typeSpec)}) {
+ if (dyType->HasDeferredTypeParameter()) {
+ context.Say(
+ "Type-spec in ALLOCATE must not have a deferred type parameter"_err_en_US);
+ }
+ }
}
const parser::Expr *parserSourceExpr{nullptr};
diff --git a/flang/test/Semantics/allocate01.f90 b/flang/test/Semantics/allocate01.f90
index a66e2467cbe4e..a10a7259ae94f 100644
--- a/flang/test/Semantics/allocate01.f90
+++ b/flang/test/Semantics/allocate01.f90
@@ -62,6 +62,7 @@ subroutine bar()
real, pointer, save :: okp3
real, allocatable, save :: oka3, okac4[:,:]
real, allocatable :: okacd5(:, :)[:]
+ character(:), allocatable :: chvar
!ERROR: Name in ALLOCATE statement must be a variable name
allocate(foo)
@@ -102,6 +103,8 @@ subroutine bar()
allocate(edc9%nok)
!ERROR: Entity in ALLOCATE statement must have the ALLOCATABLE or POINTER attribute
allocate(edc10)
+ !ERROR: Type-spec in ALLOCATE must not have a deferred type parameter
+ allocate(character(:) :: chvar)
! No errors expected below:
allocate(a_var)
@@ -117,4 +120,5 @@ subroutine bar()
allocate(edc9%ok(4))
allocate(edc10%ok)
allocate(rp)
+ allocate(character(123) :: chvar)
end subroutine
``````````
</details>
https://github.com/llvm/llvm-project/pull/139334
More information about the flang-commits
mailing list