[flang-commits] [PATCH] D87073: Fix for PR47339

Inderjeet via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Sep 2 23:10:41 PDT 2020


inderjeet-hcl created this revision.
inderjeet-hcl added reviewers: Flang, flang-commits, PeteSteinfeld, sscalpone.
inderjeet-hcl added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
inderjeet-hcl requested review of this revision.

Issue is raised as PR 47339.
Following test case should generate compile time error for invalid selector at line #4 and #9 :

R1105 selector is expr

  or variable 

C1103 (R1105) variable shall not be a coindexed object.

[root at localhost flang]# cat -n /root/LLVM/selecttype_coarray.f90

   1	class(*),allocatable :: calc[:]
   2	integer :: icoa[*]
   3	
   4	associate(sel=>icoa[2])
   5	end associate
   6	
   7	icoa = 2
   8	allocate(integer::calc[*])
   9	select type(sel=>calc[2])
  10	 type is(integer)
  11	  sel = 2
  12	end select
  13	end


https://reviews.llvm.org/D87073

Files:
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/resolve95.f90


Index: flang/test/Semantics/resolve95.f90
===================================================================
--- /dev/null
+++ 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
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -5044,6 +5044,19 @@
   const auto &name{std::get<parser::Name>(x.t)};
   GetCurrentAssociation().name = &name;
   if (auto *symbol{MakeAssocEntity()}) {
+    auto &details{symbol->get<AssocEntityDetails>()};
+    const MaybeExpr *pexpr{&details.expr()};
+    if (!*pexpr) {
+      pexpr = &GetCurrentAssociation().selector.expr;
+    }
+    if (*pexpr) {
+      const SomeExpr &expr{**pexpr};
+      if (std::optional<evaluate::DynamicType> type{expr.GetType()}) {
+        if (ExtractCoarrayRef(expr)) { // C1103
+          Say("Selector must not be a coindexed object"_err_en_US);
+        }
+      }
+    }
     SetTypeFromAssociation(*symbol);
     SetAttrsFromAssociation(*symbol);
   }
@@ -5098,6 +5111,9 @@
     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 "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87073.289642.patch
Type: text/x-patch
Size: 1969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200903/db62b146/attachment-0001.bin>


More information about the flang-commits mailing list