[flang-commits] [PATCH] D139043: [flang] Restore C702 check for ProcEntity symbols

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Nov 30 14:37:11 PST 2022


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

A recent change moved some checking code from name resolution into
declaration checking, and inadvertently disabled C702 checking for
procedure entities.  Fix.


https://reviews.llvm.org/D139043

Files:
  flang/lib/Semantics/check-declarations.cpp
  flang/test/Semantics/resolve69.f90


Index: flang/test/Semantics/resolve69.f90
===================================================================
--- flang/test/Semantics/resolve69.f90
+++ flang/test/Semantics/resolve69.f90
@@ -26,6 +26,16 @@
   character(:) :: colonString2
   !OK because of the allocatable attribute
   character(:), allocatable :: colonString3
+!ERROR: 'foo1' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable or a pointer
+  character(:), external :: foo1
+!ERROR: 'foo2' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable or a pointer
+  procedure(character(:)) :: foo2
+  interface
+    function foo3()
+!ERROR: 'foo3' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable or a pointer
+      character(:) foo3
+    end function
+  end interface
 
 !ERROR: Must have INTEGER type, but is REAL(4)
   character(3.5) :: badParamValue
@@ -75,6 +85,8 @@
   implicit character(:)(f)
 end function
 
+!Not errors.
+
 Program d5
   Type string(maxlen)
     Integer,Kind :: maxlen
@@ -85,7 +97,6 @@
   Print *,Trim(line%value)
 End Program
 
-!Not errors.
 subroutine outer
   integer n
  contains
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -87,6 +87,7 @@
   void CheckGenericOps(const Scope &);
   bool CheckConflicting(const Symbol &, Attr, Attr);
   void WarnMissingFinal(const Symbol &);
+  void CheckSymbolType(const Symbol &); // C702
   bool InPure() const {
     return innermostSymbol_ && IsPureProcedure(*innermostSymbol_);
   }
@@ -493,15 +494,7 @@
 
 void CheckHelper::CheckObjectEntity(
     const Symbol &symbol, const ObjectEntityDetails &details) {
-  if (!IsAllocatableOrPointer(symbol)) { // C702
-    if (auto dyType{evaluate::DynamicType::From(symbol)}) {
-      if (dyType->HasDeferredTypeParameter()) {
-        messages_.Say(
-            "'%s' has a type %s with a deferred type parameter but is neither an allocatable or a pointer"_err_en_US,
-            symbol.name(), dyType->AsFortran());
-      }
-    }
-  }
+  CheckSymbolType(symbol);
   CheckArraySpec(symbol, details.shape());
   Check(details.shape());
   Check(details.coshape());
@@ -800,6 +793,7 @@
 
 void CheckHelper::CheckProcEntity(
     const Symbol &symbol, const ProcEntityDetails &details) {
+  CheckSymbolType(symbol);
   if (details.isDummy()) {
     if (!symbol.attrs().test(Attr::POINTER) && // C843
         (symbol.attrs().test(Attr::INTENT_IN) ||
@@ -2285,6 +2279,18 @@
   }
 }
 
+void CheckHelper::CheckSymbolType(const Symbol &symbol) {
+  if (!IsAllocatableOrPointer(symbol)) { // C702
+    if (auto dyType{evaluate::DynamicType::From(symbol)}) {
+      if (dyType->HasDeferredTypeParameter()) {
+        messages_.Say(
+            "'%s' has a type %s with a deferred type parameter but is neither an allocatable or a pointer"_err_en_US,
+            symbol.name(), dyType->AsFortran());
+      }
+    }
+  }
+}
+
 void SubprogramMatchHelper::Check(
     const Symbol &symbol1, const Symbol &symbol2) {
   const auto details1{symbol1.get<SubprogramDetails>()};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139043.479072.patch
Type: text/x-patch
Size: 3251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221130/c70545c7/attachment.bin>


More information about the flang-commits mailing list