[flang-commits] [flang] [flang] To issue error message for unsupported usage of vector type. (PR #215248)

Daniel Chen via flang-commits flang-commits at lists.llvm.org
Fri Aug 14 06:48:22 PDT 2026


https://github.com/DanielCChen updated https://github.com/llvm/llvm-project/pull/215248

>From 91f7ac255743b01829f623393b8124daf5991ce3 Mon Sep 17 00:00:00 2001
From: Daniel Chen <cdchen at ca.ibm.com>
Date: Mon, 10 Aug 2026 07:16:59 -0400
Subject: [PATCH 1/3] [flang] To issue error message for unsupported usage of
 vector type.

---
 flang/lib/Evaluate/tools.cpp                  |  3 +-
 flang/lib/Semantics/check-allocate.cpp        |  6 +++
 flang/lib/Semantics/expression.cpp            | 10 +++++
 .../PowerPC/ppc-vector-poly-checks.f90        | 45 +++++++++++++++++++
 4 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Semantics/PowerPC/ppc-vector-poly-checks.f90

diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 589aab5132a65..5eceb4562c4ba 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -2767,7 +2767,8 @@ bool IsLenTypeParameter(const Symbol &symbol) {
 }
 
 bool IsExtensibleType(const DerivedTypeSpec *derived) {
-  return !IsSequenceOrBindCType(derived) && !IsIsoCType(derived);
+  return !IsSequenceOrBindCType(derived) && !IsIsoCType(derived) &&
+      !(derived && derived->IsVectorType());
 }
 
 bool IsSequenceOrBindCType(const DerivedTypeSpec *derived) {
diff --git a/flang/lib/Semantics/check-allocate.cpp b/flang/lib/Semantics/check-allocate.cpp
index 7f099d51221c0..2ac242abd5788 100644
--- a/flang/lib/Semantics/check-allocate.cpp
+++ b/flang/lib/Semantics/check-allocate.cpp
@@ -238,6 +238,12 @@ static std::optional<AllocateCheckerInfo> CheckAllocateOptions(
       info.sourceExprLoc = parserSourceExpr->source;
       if (const DerivedTypeSpec *
           derived{evaluate::GetDerivedTypeSpec(info.sourceExprType)}) {
+        if (derived->IsVectorType()) {
+          context.Say(at,
+              "SOURCE or MOLD expression must not be a vector type '%s'"_err_en_US,
+              info.sourceExprType.value().AsFortran());
+          return std::nullopt;
+        }
         // C949
         if (auto it{FindCoarrayUltimateComponent(*derived)}) {
           context
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index fc57cc43e981c..1cc3715330b64 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -3852,6 +3852,16 @@ const Assignment *ExpressionAnalyzer::Analyze(const parser::AssignmentStmt &x) {
               Warn(common::UsageWarning::IgnoredNoReallocateLHS,
                   "-fno-realloc-lhs is ignored for assignment to polymorphic allocatable"_warn_en_US);
             }
+            const Expr<SomeType> &rhs{analyzer.GetExpr(1)};
+            if (auto rhsType{rhs.GetType()}) {
+              if (const auto *rhsDerived{GetDerivedTypeSpec(*rhsType)}) {
+                if (rhsDerived->IsVectorType()) {
+                  Say(rhsExpr.source,
+                      "Vector type '%s' may not be used as the right-hand side of a polymorphic intrinsic assignment"_err_en_US,
+                      rhsType->AsFortran());
+                }
+              }
+            }
           }
           if (auto *derived{GetDerivedTypeSpec(*dyType)}) {
             if (auto iter{FindAllocatableUltimateComponent(*derived)}) {
diff --git a/flang/test/Semantics/PowerPC/ppc-vector-poly-checks.f90 b/flang/test/Semantics/PowerPC/ppc-vector-poly-checks.f90
new file mode 100644
index 0000000000000..e047cf838f9ea
--- /dev/null
+++ b/flang/test/Semantics/PowerPC/ppc-vector-poly-checks.f90
@@ -0,0 +1,45 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1
+! REQUIRES: target=powerpc{{.*}}
+
+! Test that vector types are rejected in polymorphic contexts:
+!   1. ALLOCATE SOURCE=/MOLD= must not have a vector type expression
+!   2. RHS of intrinsic assignment must not be a vector type when LHS is polymorphic
+!      (uses Fortran standard auto-allocation, no prior ALLOCATE)
+!   3. SAME_TYPE_AS / EXTENDS_TYPE_OF must not receive a vector type argument
+!      (enforced via IsExtensibleType returning false for vector types)
+
+subroutine test_allocate_source()
+  vector(integer(4)) :: vi(2)
+  class(*), allocatable :: x(:)
+  !ERROR: SOURCE or MOLD expression must not be a vector type 'vector(integer(4))'
+  allocate(x(2), source=vi)
+end subroutine
+
+subroutine test_allocate_mold()
+  vector(real(4)) :: vr(2)
+  class(*), allocatable :: x(:)
+  !ERROR: SOURCE or MOLD expression must not be a vector type 'vector(real(4))'
+  allocate(x(2), mold=vr)
+end subroutine
+
+subroutine test_poly_assign_vector_rhs()
+  vector(real(4)) :: vr(2)
+  class(*), allocatable :: x(:)
+  ! x is unallocated; auto-allocation from RHS type must be rejected
+  !ERROR: Vector type 'vector(real(4))' may not be used as the right-hand side of a polymorphic intrinsic assignment
+  x = vr
+end subroutine
+
+subroutine test_same_type_as()
+  vector(integer(4)) :: vi(2)
+  logical :: res
+  !ERROR: Actual argument for 'a=' has type 'vector(integer(4))', but was expected to be an extensible or unlimited polymorphic type
+  res = same_type_as(vi, vi)
+end subroutine
+
+subroutine test_extends_type_of()
+  vector(real(4)) :: vr(2)
+  logical :: res
+  !ERROR: Actual argument for 'a=' has type 'vector(real(4))', but was expected to be an extensible or unlimited polymorphic type
+  res = extends_type_of(vr, vr)
+end subroutine

>From 4484aa9d24843d83559451ea351057c0d1e4ce0d Mon Sep 17 00:00:00 2001
From: Daniel Chen <cdchen at ca.ibm.com>
Date: Wed, 12 Aug 2026 12:09:03 -0400
Subject: [PATCH 2/3] To address review comments.

---
 .../PowerPC/ppc-vector-diagnostics.f90        | 43 ++++++++++++++++++
 .../PowerPC/ppc-vector-poly-checks.f90        | 45 -------------------
 2 files changed, 43 insertions(+), 45 deletions(-)
 delete mode 100644 flang/test/Semantics/PowerPC/ppc-vector-poly-checks.f90

diff --git a/flang/test/Semantics/PowerPC/ppc-vector-diagnostics.f90 b/flang/test/Semantics/PowerPC/ppc-vector-diagnostics.f90
index 636c3a764f055..f7e00cd036f6a 100644
--- a/flang/test/Semantics/PowerPC/ppc-vector-diagnostics.f90
+++ b/flang/test/Semantics/PowerPC/ppc-vector-diagnostics.f90
@@ -13,3 +13,46 @@ subroutine test_vector_assignment()
   !ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches operand types vector(integer(4)) and vector(real(4))
   v1 = v2
 end subroutine
+
+! Test that vector types are rejected in polymorphic contexts:
+!   1. ALLOCATE SOURCE=/MOLD= must not have a vector type expression
+!   2. RHS of intrinsic assignment must not be a vector type when LHS is polymorphic
+!      (uses Fortran standard auto-allocation, no prior ALLOCATE)
+!   3. SAME_TYPE_AS / EXTENDS_TYPE_OF must not receive a vector type argument
+!      (enforced via IsExtensibleType returning false for vector types)
+
+subroutine test_allocate_source()
+  vector(integer(4)) :: vi(2)
+  class(*), allocatable :: x(:)
+  !ERROR: SOURCE or MOLD expression must not be a vector type 'vector(integer(4))'
+  allocate(x(2), source=vi)
+end subroutine
+
+subroutine test_allocate_mold()
+  vector(real(4)) :: vr(2)
+  class(*), allocatable :: x(:)
+  !ERROR: SOURCE or MOLD expression must not be a vector type 'vector(real(4))'
+  allocate(x(2), mold=vr)
+end subroutine
+
+subroutine test_poly_assign_vector_rhs()
+  vector(real(4)) :: vr(2)
+  class(*), allocatable :: x(:)
+  ! x is unallocated; auto-allocation from RHS type must be rejected
+  !ERROR: Vector type 'vector(real(4))' may not be used as the right-hand side of a polymorphic intrinsic assignment
+  x = vr
+end subroutine
+
+subroutine test_same_type_as()
+  vector(integer(4)) :: vi(2)
+  logical :: res
+  !ERROR: Actual argument for 'a=' has type 'vector(integer(4))', but was expected to be an extensible or unlimited polymorphic type
+  res = same_type_as(vi, vi)
+end subroutine
+
+subroutine test_extends_type_of()
+  vector(real(4)) :: vr(2)
+  logical :: res
+  !ERROR: Actual argument for 'a=' has type 'vector(real(4))', but was expected to be an extensible or unlimited polymorphic type
+  res = extends_type_of(vr, vr)
+end subroutine
diff --git a/flang/test/Semantics/PowerPC/ppc-vector-poly-checks.f90 b/flang/test/Semantics/PowerPC/ppc-vector-poly-checks.f90
deleted file mode 100644
index e047cf838f9ea..0000000000000
--- a/flang/test/Semantics/PowerPC/ppc-vector-poly-checks.f90
+++ /dev/null
@@ -1,45 +0,0 @@
-! RUN: %python %S/../test_errors.py %s %flang_fc1
-! REQUIRES: target=powerpc{{.*}}
-
-! Test that vector types are rejected in polymorphic contexts:
-!   1. ALLOCATE SOURCE=/MOLD= must not have a vector type expression
-!   2. RHS of intrinsic assignment must not be a vector type when LHS is polymorphic
-!      (uses Fortran standard auto-allocation, no prior ALLOCATE)
-!   3. SAME_TYPE_AS / EXTENDS_TYPE_OF must not receive a vector type argument
-!      (enforced via IsExtensibleType returning false for vector types)
-
-subroutine test_allocate_source()
-  vector(integer(4)) :: vi(2)
-  class(*), allocatable :: x(:)
-  !ERROR: SOURCE or MOLD expression must not be a vector type 'vector(integer(4))'
-  allocate(x(2), source=vi)
-end subroutine
-
-subroutine test_allocate_mold()
-  vector(real(4)) :: vr(2)
-  class(*), allocatable :: x(:)
-  !ERROR: SOURCE or MOLD expression must not be a vector type 'vector(real(4))'
-  allocate(x(2), mold=vr)
-end subroutine
-
-subroutine test_poly_assign_vector_rhs()
-  vector(real(4)) :: vr(2)
-  class(*), allocatable :: x(:)
-  ! x is unallocated; auto-allocation from RHS type must be rejected
-  !ERROR: Vector type 'vector(real(4))' may not be used as the right-hand side of a polymorphic intrinsic assignment
-  x = vr
-end subroutine
-
-subroutine test_same_type_as()
-  vector(integer(4)) :: vi(2)
-  logical :: res
-  !ERROR: Actual argument for 'a=' has type 'vector(integer(4))', but was expected to be an extensible or unlimited polymorphic type
-  res = same_type_as(vi, vi)
-end subroutine
-
-subroutine test_extends_type_of()
-  vector(real(4)) :: vr(2)
-  logical :: res
-  !ERROR: Actual argument for 'a=' has type 'vector(real(4))', but was expected to be an extensible or unlimited polymorphic type
-  res = extends_type_of(vr, vr)
-end subroutine

>From 9a6c539f6f25199cd6c97d57af40cd12369b916c Mon Sep 17 00:00:00 2001
From: Daniel Chen <cdchen at ca.ibm.com>
Date: Fri, 14 Aug 2026 09:47:52 -0400
Subject: [PATCH 3/3] To address review comments to check allocatable and
 pointer scalar and UDIO dtv argument where a normal derived type is required.

---
 flang/lib/Semantics/check-declarations.cpp    | 12 +++++
 .../PowerPC/ppc-vector-diagnostics.f90        | 53 +++++++++++++++++++
 2 files changed, 65 insertions(+)

diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index a4cb1c4e9f90c..07c6b88f0562a 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1323,6 +1323,12 @@ void CheckHelper::CheckObjectEntity(
       SayWithDeclaration(symbol,
           "Assumed rank entity of %s type is not supported"_err_en_US,
           typeName);
+    } else if (IsPointer(symbol)) {
+      SayWithDeclaration(
+          symbol, "Pointer to %s type is not supported"_err_en_US, typeName);
+    } else if (IsAllocatable(symbol)) {
+      SayWithDeclaration(symbol,
+          "Allocatable entity of %s type is not supported"_err_en_US, typeName);
     }
   }
 }
@@ -3679,6 +3685,12 @@ void CheckHelper::CheckDioDummyIsDerived(const Symbol &proc, const Symbol &arg,
     common::DefinedIo ioKind, const Symbol &generic) {
   if (const DeclTypeSpec *type{arg.GetType()}) {
     if (const DerivedTypeSpec *derivedType{type->AsDerived()}) {
+      if (derivedType->IsVectorType()) {
+        messages_.Say(arg.name(),
+            "Dummy argument '%s' of a defined input/output procedure must not be a vector type"_err_en_US,
+            arg.name());
+        return;
+      }
       CheckAlreadySeenDefinedIo(*derivedType, ioKind, proc, generic);
       bool isPolymorphic{type->IsPolymorphic()};
       if (isPolymorphic != IsExtensibleType(derivedType)) {
diff --git a/flang/test/Semantics/PowerPC/ppc-vector-diagnostics.f90 b/flang/test/Semantics/PowerPC/ppc-vector-diagnostics.f90
index f7e00cd036f6a..1ed79c13fe5c9 100644
--- a/flang/test/Semantics/PowerPC/ppc-vector-diagnostics.f90
+++ b/flang/test/Semantics/PowerPC/ppc-vector-diagnostics.f90
@@ -56,3 +56,56 @@ subroutine test_extends_type_of()
   !ERROR: Actual argument for 'a=' has type 'vector(real(4))', but was expected to be an extensible or unlimited polymorphic type
   res = extends_type_of(vr, vr)
 end subroutine
+
+! Test scalar POINTER and ALLOCATABLE vector type declarations (not supported)
+subroutine test_scalar_pointer()
+  !ERROR: Pointer to vector(integer(4)) type is not supported
+  vector(integer(4)), pointer :: p
+end subroutine
+
+subroutine test_scalar_allocatable()
+  !ERROR: Allocatable entity of vector(integer(4)) type is not supported
+  vector(integer(4)), allocatable :: v
+end subroutine
+
+! SAME_TYPE_AS with one unlimited polymorphic arg and one vector arg
+subroutine test_same_type_as_mixed(x)
+  class(*), intent(in) :: x
+  vector(integer(4)) :: vi(2)
+  logical :: res
+  !ERROR: Actual argument for 'b=' has type 'vector(integer(4))', but was expected to be an extensible or unlimited polymorphic type
+  res = same_type_as(x, vi)
+end subroutine
+
+! UDTI: dtv argument must not be a vector type
+module test_udti_vector_read_mod
+  interface read(formatted)
+    module procedure rf
+  end interface
+contains
+  subroutine rf(dtv, unit, iotype, vlist, iostat, iomsg)
+    !ERROR: Dummy argument 'dtv' of a defined input/output procedure must not be a vector type
+    vector(integer(4)), intent(inout) :: dtv
+    integer, intent(in) :: unit
+    character(*), intent(in) :: iotype
+    integer, intent(in) :: vlist(:)
+    integer, intent(out) :: iostat
+    character(*), intent(inout) :: iomsg
+  end subroutine
+end module
+
+module test_udti_vector_write_mod
+  interface write(formatted)
+    module procedure wf
+  end interface
+contains
+  subroutine wf(dtv, unit, iotype, vlist, iostat, iomsg)
+    !ERROR: Dummy argument 'dtv' of a defined input/output procedure must not be a vector type
+    vector(integer(4)), intent(in) :: dtv
+    integer, intent(in) :: unit
+    character(*), intent(in) :: iotype
+    integer, intent(in) :: vlist(:)
+    integer, intent(out) :: iostat
+    character(*), intent(inout) :: iomsg
+  end subroutine
+end module



More information about the flang-commits mailing list