Skip to content

[flang] Catch deferred type parameters in ALLOCATE(type-spec::) #139334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

klausler
Copy link
Contributor

@klausler klausler commented May 9, 2025

The type-spec in ALLOCATE may not have any deferred type parameters.

Fixes #138979.

The type-spec in ALLOCATE may not have any deferred type parameters.

Fixes llvm#138979.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels May 9, 2025
@llvmbot
Copy link
Member

llvmbot commented May 9, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

The type-spec in ALLOCATE may not have any deferred type parameters.

Fixes #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 --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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] Missing diagnostic on deferred length parameter being used in type-spec of an ALLOCATE statement
3 participants