[flang-commits] [flang] 5ec043e - [FLANG] Generate error for invalid selector.

via flang-commits flang-commits at lists.llvm.org
Wed Sep 9 07:17:24 PDT 2020


Author: compinder
Date: 2020-09-09T19:14:54+05:30
New Revision: 5ec043eae1877add1cde2a7bd6e01ef64549a41d

URL: https://github.com/llvm/llvm-project/commit/5ec043eae1877add1cde2a7bd6e01ef64549a41d
DIFF: https://github.com/llvm/llvm-project/commit/5ec043eae1877add1cde2a7bd6e01ef64549a41d.diff

LOG: [FLANG] Generate error for invalid selector.

Fix of PR47339

Differential Revision: https://reviews.llvm.org/D87073/new/

Added: 
    flang/test/Semantics/resolve95.f90

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/lib/Semantics/tools.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index a75c5b6a829e..54686232dc0d 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5044,6 +5044,9 @@ void ConstructVisitor::Post(const parser::Association &x) {
   const auto &name{std::get<parser::Name>(x.t)};
   GetCurrentAssociation().name = &name;
   if (auto *symbol{MakeAssocEntity()}) {
+    if (ExtractCoarrayRef(GetCurrentAssociation().selector.expr)) { // C1103
+      Say("Selector must not be a coindexed object"_err_en_US);
+    }
     SetTypeFromAssociation(*symbol);
     SetAttrsFromAssociation(*symbol);
   }
@@ -5098,6 +5101,9 @@ void ConstructVisitor::Post(const parser::SelectTypeStmt &x) {
     MakePlaceholder(*name, MiscDetails::Kind::SelectTypeAssociateName);
     association.name = &*name;
     auto exprType{association.selector.expr->GetType()};
+    if (ExtractCoarrayRef(association.selector.expr)) { // C1103
+      Say("Selector must not be a coindexed object"_err_en_US);
+    }
     if (exprType && !exprType->IsPolymorphic()) { // C1159
       Say(association.selector.source,
           "Selector '%s' in SELECT TYPE statement must be "

diff  --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 3f93944cd3c3..7a79dedb00a3 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -739,7 +739,6 @@ bool InProtectedContext(const Symbol &symbol, const Scope &currentScope) {
 }
 
 // C1101 and C1158
-// TODO Need to check for a coindexed object (why? C1103?)
 std::optional<parser::MessageFixedText> WhyNotModifiable(
     const Symbol &symbol, const Scope &scope) {
   const Symbol *root{GetAssociationRoot(symbol)};

diff  --git a/flang/test/Semantics/resolve95.f90 b/flang/test/Semantics/resolve95.f90
new file mode 100644
index 000000000000..78ff09d88d32
--- /dev/null
+++ b/flang/test/Semantics/resolve95.f90
@@ -0,0 +1,15 @@
+! RUN: %S/test_errors.sh %s %t %f18
+! Test SELECT TYPE and ASSOCIATE errors: C1103
+
+subroutine s1()
+  class(*),allocatable :: calc[:]
+  integer,save :: icoa[*]
+  !ERROR: Selector must not be a coindexed object
+  associate(sel=>icoa[2])
+  end associate
+  icoa = 2
+  allocate(integer::calc[*])
+  !ERROR: Selector must not be a coindexed object
+  select type(sel=>calc[2])
+  end select
+end subroutine


        


More information about the flang-commits mailing list