From: Peter Klausler Date: Wed, 2 Nov 2022 16:59:10 +0000 (-0700) Subject: [flang] Restore C702 check for ProcEntity symbols X-Git-Tag: upstream/17.0.6~25538 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=78da80e2ef6e0531ebdc53f240d87187f9191f3f;p=platform%2Fupstream%2Fllvm.git [flang] Restore C702 check for ProcEntity symbols A recent change moved some checking code from name resolution into declaration checking, and inadvertently disabled C702 checking for procedure entities. Fix. Differential Revision: https://reviews.llvm.org/D139043 --- diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp index 11367c4..22588ce 100644 --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -88,6 +88,7 @@ private: 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_); } @@ -494,15 +495,7 @@ void CheckHelper::CheckAssumedTypeEntity( // C709 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()); @@ -801,6 +794,7 @@ void CheckHelper::CheckArraySpec( 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) || @@ -2337,6 +2331,18 @@ void CheckHelper::CheckDefinedIoProc(const Symbol &symbol, } } +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()}; diff --git a/flang/test/Semantics/resolve69.f90 b/flang/test/Semantics/resolve69.f90 index 0edc91a..4db277d 100644 --- a/flang/test/Semantics/resolve69.f90 +++ b/flang/test/Semantics/resolve69.f90 @@ -26,6 +26,16 @@ subroutine s1() 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 @@ function f4 implicit character(:)(f) end function +!Not errors. + Program d5 Type string(maxlen) Integer,Kind :: maxlen @@ -85,7 +97,6 @@ Program d5 Print *,Trim(line%value) End Program -!Not errors. subroutine outer integer n contains