[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
Wed Aug 12 08:56:42 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] [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
More information about the flang-commits
mailing list