2020-02-25 15:11:52 +00:00
//===-- lib/Semantics/tools.cpp -------------------------------------------===//
2019-03-04 10:13:12 -08:00
//
2019-12-20 12:52:07 -08:00
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2019-03-04 10:13:12 -08:00
//
2020-01-10 12:12:03 -08:00
//===----------------------------------------------------------------------===//
2019-03-04 10:13:12 -08:00
2020-02-25 15:11:52 +00:00
# include "flang/Parser/tools.h"
# include "flang/Common/Fortran.h"
# include "flang/Common/indirection.h"
# include "flang/Parser/dump-parse-tree.h"
# include "flang/Parser/message.h"
# include "flang/Parser/parse-tree.h"
# include "flang/Semantics/scope.h"
# include "flang/Semantics/semantics.h"
# include "flang/Semantics/symbol.h"
# include "flang/Semantics/tools.h"
# include "flang/Semantics/type.h"
2020-02-28 15:11:03 +00:00
# include "llvm/Support/raw_ostream.h"
2019-03-04 10:13:12 -08:00
# include <algorithm>
# include <set>
# include <variant>
namespace Fortran : : semantics {
2020-03-02 16:43:01 -08:00
// Find this or containing scope that matches predicate
static const Scope * FindScopeContaining (
const Scope & start , std : : function < bool ( const Scope & ) > predicate ) {
for ( const Scope * scope { & start } ; ; scope = & scope - > parent ( ) ) {
if ( predicate ( * scope ) ) {
return scope ;
}
2022-01-26 09:54:58 -08:00
if ( scope - > IsTopLevel ( ) ) {
2020-03-02 16:43:01 -08:00
return nullptr ;
}
}
}
2020-12-02 10:28:48 -08:00
const Scope & GetTopLevelUnitContaining ( const Scope & start ) {
2022-01-26 09:54:58 -08:00
CHECK ( ! start . IsTopLevel ( ) ) ;
2020-12-02 10:28:48 -08:00
return DEREF ( FindScopeContaining (
2022-01-26 09:54:58 -08:00
start , [ ] ( const Scope & scope ) { return scope . parent ( ) . IsTopLevel ( ) ; } ) ) ;
2020-12-02 10:28:48 -08:00
}
const Scope & GetTopLevelUnitContaining ( const Symbol & symbol ) {
return GetTopLevelUnitContaining ( symbol . owner ( ) ) ;
}
2020-03-02 16:43:01 -08:00
const Scope * FindModuleContaining ( const Scope & start ) {
return FindScopeContaining (
start , [ ] ( const Scope & scope ) { return scope . IsModule ( ) ; } ) ;
}
2021-01-15 11:52:10 -08:00
const Scope * FindModuleFileContaining ( const Scope & start ) {
return FindScopeContaining (
start , [ ] ( const Scope & scope ) { return scope . IsModuleFile ( ) ; } ) ;
}
2020-12-02 10:28:48 -08:00
const Scope & GetProgramUnitContaining ( const Scope & start ) {
2022-01-26 09:54:58 -08:00
CHECK ( ! start . IsTopLevel ( ) ) ;
2020-12-02 10:28:48 -08:00
return DEREF ( FindScopeContaining ( start , [ ] ( const Scope & scope ) {
2020-03-02 16:43:01 -08:00
switch ( scope . kind ( ) ) {
2019-03-04 10:13:12 -08:00
case Scope : : Kind : : Module :
case Scope : : Kind : : MainProgram :
2020-01-09 17:12:46 -08:00
case Scope : : Kind : : Subprogram :
2020-03-27 14:17:25 -07:00
case Scope : : Kind : : BlockData :
return true ;
default :
return false ;
2019-03-04 10:13:12 -08:00
}
2020-12-02 10:28:48 -08:00
} ) ) ;
2019-03-04 10:13:12 -08:00
}
2020-12-02 10:28:48 -08:00
const Scope & GetProgramUnitContaining ( const Symbol & symbol ) {
return GetProgramUnitContaining ( symbol . owner ( ) ) ;
2019-03-04 10:13:12 -08:00
}
2022-07-22 11:51:20 -07:00
const Scope & GetProgramUnitOrBlockConstructContaining ( const Scope & start ) {
CHECK ( ! start . IsTopLevel ( ) ) ;
return DEREF ( FindScopeContaining ( start , [ ] ( const Scope & scope ) {
switch ( scope . kind ( ) ) {
case Scope : : Kind : : Module :
case Scope : : Kind : : MainProgram :
case Scope : : Kind : : Subprogram :
case Scope : : Kind : : BlockData :
case Scope : : Kind : : BlockConstruct :
return true ;
default :
return false ;
}
} ) ) ;
}
const Scope & GetProgramUnitOrBlockConstructContaining ( const Symbol & symbol ) {
return GetProgramUnitOrBlockConstructContaining ( symbol . owner ( ) ) ;
}
2019-11-19 19:10:02 -08:00
const Scope * FindPureProcedureContaining ( const Scope & start ) {
// N.B. We only need to examine the innermost containing program unit
2019-12-23 17:12:53 -08:00
// because an internal subprogram of a pure subprogram must also
// be pure (C1592).
2022-01-26 09:54:58 -08:00
if ( start . IsTopLevel ( ) ) {
2021-06-02 16:54:42 -07:00
return nullptr ;
} else {
const Scope & scope { GetProgramUnitContaining ( start ) } ;
return IsPureProcedure ( scope ) ? & scope : nullptr ;
}
2019-03-04 10:13:12 -08:00
}
2023-11-30 10:58:51 -08:00
const Scope * FindOpenACCConstructContaining ( const Scope * scope ) {
return scope ? FindScopeContaining ( * scope ,
[ ] ( const Scope & s ) {
return s . kind ( ) = = Scope : : Kind : : OpenACCConstruct ;
} )
: nullptr ;
}
2022-01-10 15:59:12 -08:00
// 7.5.2.4 "same derived type" test -- rely on IsTkCompatibleWith() and its
// infrastructure to detect and handle comparisons on distinct (but "same")
// sequence/bind(C) derived types
static bool MightBeSameDerivedType (
2021-04-20 10:11:03 -07:00
const std : : optional < evaluate : : DynamicType > & lhsType ,
const std : : optional < evaluate : : DynamicType > & rhsType ) {
2022-05-03 13:57:14 -07:00
return lhsType & & rhsType & & lhsType - > IsTkCompatibleWith ( * rhsType ) ;
2021-04-20 10:11:03 -07:00
}
2019-11-22 16:46:11 -08:00
Tristate IsDefinedAssignment (
const std : : optional < evaluate : : DynamicType > & lhsType , int lhsRank ,
const std : : optional < evaluate : : DynamicType > & rhsType , int rhsRank ) {
if ( ! lhsType | | ! rhsType ) {
2020-03-27 14:17:25 -07:00
return Tristate : : No ; // error or rhs is untyped
2019-11-22 16:46:11 -08:00
}
2022-05-19 16:30:04 -07:00
if ( lhsType - > IsUnlimitedPolymorphic ( ) ) {
2022-03-23 16:02:59 -07:00
return Tristate : : No ;
}
2022-05-19 16:30:04 -07:00
if ( rhsType - > IsUnlimitedPolymorphic ( ) ) {
return Tristate : : Maybe ;
}
2019-11-22 16:46:11 -08:00
TypeCategory lhsCat { lhsType - > category ( ) } ;
TypeCategory rhsCat { rhsType - > category ( ) } ;
if ( rhsRank > 0 & & lhsRank ! = rhsRank ) {
return Tristate : : Yes ;
} else if ( lhsCat ! = TypeCategory : : Derived ) {
return ToTristate ( lhsCat ! = rhsCat & &
( ! IsNumericTypeCategory ( lhsCat ) | | ! IsNumericTypeCategory ( rhsCat ) ) ) ;
2022-01-10 15:59:12 -08:00
} else if ( MightBeSameDerivedType ( lhsType , rhsType ) ) {
2021-04-20 10:11:03 -07:00
return Tristate : : Maybe ; // TYPE(t) = TYPE(t) can be defined or intrinsic
2019-11-22 16:46:11 -08:00
} else {
2021-04-20 10:11:03 -07:00
return Tristate : : Yes ;
2019-11-22 16:46:11 -08:00
}
}
2019-12-02 08:55:44 -08:00
bool IsIntrinsicRelational ( common : : RelationalOperator opr ,
const evaluate : : DynamicType & type0 , int rank0 ,
const evaluate : : DynamicType & type1 , int rank1 ) {
if ( ! evaluate : : AreConformable ( rank0 , rank1 ) ) {
return false ;
} else {
auto cat0 { type0 . category ( ) } ;
auto cat1 { type1 . category ( ) } ;
if ( IsNumericTypeCategory ( cat0 ) & & IsNumericTypeCategory ( cat1 ) ) {
// numeric types: EQ/NE always ok, others ok for non-complex
return opr = = common : : RelationalOperator : : EQ | |
opr = = common : : RelationalOperator : : NE | |
( cat0 ! = TypeCategory : : Complex & & cat1 ! = TypeCategory : : Complex ) ;
} else {
// not both numeric: only Character is ok
return cat0 = = TypeCategory : : Character & & cat1 = = TypeCategory : : Character ;
}
}
}
bool IsIntrinsicNumeric ( const evaluate : : DynamicType & type0 ) {
return IsNumericTypeCategory ( type0 . category ( ) ) ;
}
bool IsIntrinsicNumeric ( const evaluate : : DynamicType & type0 , int rank0 ,
const evaluate : : DynamicType & type1 , int rank1 ) {
return evaluate : : AreConformable ( rank0 , rank1 ) & &
IsNumericTypeCategory ( type0 . category ( ) ) & &
IsNumericTypeCategory ( type1 . category ( ) ) ;
}
bool IsIntrinsicLogical ( const evaluate : : DynamicType & type0 ) {
return type0 . category ( ) = = TypeCategory : : Logical ;
}
bool IsIntrinsicLogical ( const evaluate : : DynamicType & type0 , int rank0 ,
const evaluate : : DynamicType & type1 , int rank1 ) {
return evaluate : : AreConformable ( rank0 , rank1 ) & &
type0 . category ( ) = = TypeCategory : : Logical & &
type1 . category ( ) = = TypeCategory : : Logical ;
}
bool IsIntrinsicConcat ( const evaluate : : DynamicType & type0 , int rank0 ,
const evaluate : : DynamicType & type1 , int rank1 ) {
return evaluate : : AreConformable ( rank0 , rank1 ) & &
type0 . category ( ) = = TypeCategory : : Character & &
type1 . category ( ) = = TypeCategory : : Character & &
type0 . kind ( ) = = type1 . kind ( ) ;
}
2019-10-22 09:31:33 -07:00
bool IsGenericDefinedOp ( const Symbol & symbol ) {
2020-01-02 09:55:03 -08:00
const Symbol & ultimate { symbol . GetUltimate ( ) } ;
if ( const auto * generic { ultimate . detailsIf < GenericDetails > ( ) } ) {
return generic - > kind ( ) . IsDefinedOperator ( ) ;
} else if ( const auto * misc { ultimate . detailsIf < MiscDetails > ( ) } ) {
return misc - > kind ( ) = = MiscDetails : : Kind : : TypeBoundDefinedOp ;
} else {
return false ;
}
2019-10-22 09:31:33 -07:00
}
2020-09-10 07:22:52 -07:00
bool IsDefinedOperator ( SourceName name ) {
const char * begin { name . begin ( ) } ;
const char * end { name . end ( ) } ;
return begin ! = end & & begin [ 0 ] = = ' . ' & & end [ - 1 ] = = ' . ' ;
}
std : : string MakeOpName ( SourceName name ) {
std : : string result { name . ToString ( ) } ;
return IsDefinedOperator ( name ) ? " OPERATOR( " + result + " ) "
: result . find ( " operator( " , 0 ) = = 0 ? parser : : ToUpperCaseLetters ( result )
: result ;
}
2019-03-04 10:13:12 -08:00
bool IsCommonBlockContaining ( const Symbol & block , const Symbol & object ) {
const auto & objects { block . get < CommonBlockDetails > ( ) . objects ( ) } ;
2022-08-20 21:18:27 -07:00
return llvm : : is_contained ( objects , object ) ;
2019-03-04 10:13:12 -08:00
}
bool IsUseAssociated ( const Symbol & symbol , const Scope & scope ) {
2022-10-17 12:51:00 -07:00
const Scope & owner { GetTopLevelUnitContaining ( symbol . GetUltimate ( ) . owner ( ) ) } ;
2020-12-02 10:28:48 -08:00
return owner . kind ( ) = = Scope : : Kind : : Module & &
2022-10-17 12:51:00 -07:00
owner ! = GetTopLevelUnitContaining ( scope ) ;
2019-03-04 10:13:12 -08:00
}
2019-03-26 00:33:03 -07:00
bool DoesScopeContain (
const Scope * maybeAncestor , const Scope & maybeDescendent ) {
2022-01-26 09:54:58 -08:00
return maybeAncestor & & ! maybeDescendent . IsTopLevel ( ) & &
2020-03-02 16:43:01 -08:00
FindScopeContaining ( maybeDescendent . parent ( ) ,
[ & ] ( const Scope & scope ) { return & scope = = maybeAncestor ; } ) ;
2019-03-04 10:13:12 -08:00
}
2019-03-05 13:11:57 -08:00
bool DoesScopeContain ( const Scope * maybeAncestor , const Symbol & symbol ) {
return DoesScopeContain ( maybeAncestor , symbol . owner ( ) ) ;
}
2020-07-30 07:12:24 -07:00
static const Symbol & FollowHostAssoc ( const Symbol & symbol ) {
for ( const Symbol * s { & symbol } ; ; ) {
const auto * details { s - > detailsIf < HostAssocDetails > ( ) } ;
if ( ! details ) {
return * s ;
}
s = & details - > symbol ( ) ;
}
}
2019-03-04 10:13:12 -08:00
bool IsHostAssociated ( const Symbol & symbol , const Scope & scope ) {
2020-12-02 10:28:48 -08:00
return DoesScopeContain (
2022-07-22 11:51:20 -07:00
& GetProgramUnitOrBlockConstructContaining ( FollowHostAssoc ( symbol ) ) ,
GetProgramUnitOrBlockConstructContaining ( scope ) ) ;
2019-03-04 10:13:12 -08:00
}
2022-07-25 18:03:40 -07:00
bool IsHostAssociatedIntoSubprogram ( const Symbol & symbol , const Scope & scope ) {
return DoesScopeContain (
& GetProgramUnitOrBlockConstructContaining ( FollowHostAssoc ( symbol ) ) ,
GetProgramUnitContaining ( scope ) ) ;
}
2020-02-26 20:19:48 -08:00
bool IsInStmtFunction ( const Symbol & symbol ) {
if ( const Symbol * function { symbol . owner ( ) . symbol ( ) } ) {
return IsStmtFunction ( * function ) ;
}
return false ;
}
bool IsStmtFunctionDummy ( const Symbol & symbol ) {
return IsDummy ( symbol ) & & IsInStmtFunction ( symbol ) ;
}
bool IsStmtFunctionResult ( const Symbol & symbol ) {
return IsFunctionResult ( symbol ) & & IsInStmtFunction ( symbol ) ;
}
2019-03-04 10:13:12 -08:00
bool IsPointerDummy ( const Symbol & symbol ) {
2019-04-07 11:29:48 -07:00
return IsPointer ( symbol ) & & IsDummy ( symbol ) ;
}
2023-03-01 08:42:22 -08:00
bool IsBindCProcedure ( const Symbol & original ) {
const Symbol & symbol { original . GetUltimate ( ) } ;
2019-10-29 12:46:25 -07:00
if ( const auto * procDetails { symbol . detailsIf < ProcEntityDetails > ( ) } ) {
2022-12-16 09:54:55 -08:00
if ( procDetails - > procInterface ( ) ) {
2019-10-29 12:46:25 -07:00
// procedure component with a BIND(C) interface
2022-12-16 09:54:55 -08:00
return IsBindCProcedure ( * procDetails - > procInterface ( ) ) ;
2019-10-29 12:46:25 -07:00
}
}
return symbol . attrs ( ) . test ( Attr : : BIND_C ) & & IsProcedure ( symbol ) ;
}
bool IsBindCProcedure ( const Scope & scope ) {
if ( const Symbol * symbol { scope . GetSymbol ( ) } ) {
return IsBindCProcedure ( * symbol ) ;
} else {
return false ;
}
}
2019-03-04 16:28:35 -08:00
static const Symbol * FindPointerComponent (
2019-03-04 10:13:12 -08:00
const Scope & scope , std : : set < const Scope * > & visited ) {
2019-07-11 09:27:25 -07:00
if ( ! scope . IsDerivedType ( ) ) {
2019-03-04 16:28:35 -08:00
return nullptr ;
2019-03-04 10:13:12 -08:00
}
if ( ! visited . insert ( & scope ) . second ) {
2019-03-04 16:28:35 -08:00
return nullptr ;
2019-03-04 10:13:12 -08:00
}
2019-03-04 16:28:35 -08:00
// If there's a top-level pointer component, return it for clearer error
// messaging.
2019-03-04 10:13:12 -08:00
for ( const auto & pair : scope ) {
const Symbol & symbol { * pair . second } ;
2019-04-18 15:07:40 -07:00
if ( IsPointer ( symbol ) ) {
2019-03-04 16:28:35 -08:00
return & symbol ;
2019-03-04 10:13:12 -08:00
}
2019-03-04 16:28:35 -08:00
}
for ( const auto & pair : scope ) {
const Symbol & symbol { * pair . second } ;
2019-03-04 10:13:12 -08:00
if ( const auto * details { symbol . detailsIf < ObjectEntityDetails > ( ) } ) {
if ( const DeclTypeSpec * type { details - > type ( ) } ) {
if ( const DerivedTypeSpec * derived { type - > AsDerived ( ) } ) {
if ( const Scope * nested { derived - > scope ( ) } ) {
2019-03-04 16:28:35 -08:00
if ( const Symbol *
pointer { FindPointerComponent ( * nested , visited ) } ) {
return pointer ;
2019-03-04 10:13:12 -08:00
}
}
}
}
}
}
2019-03-04 16:28:35 -08:00
return nullptr ;
2019-03-04 10:13:12 -08:00
}
2019-03-04 16:28:35 -08:00
const Symbol * FindPointerComponent ( const Scope & scope ) {
2019-03-04 10:13:12 -08:00
std : : set < const Scope * > visited ;
2019-03-04 16:28:35 -08:00
return FindPointerComponent ( scope , visited ) ;
2019-03-04 10:13:12 -08:00
}
2019-03-04 16:28:35 -08:00
const Symbol * FindPointerComponent ( const DerivedTypeSpec & derived ) {
2019-03-04 10:13:12 -08:00
if ( const Scope * scope { derived . scope ( ) } ) {
2019-03-04 16:28:35 -08:00
return FindPointerComponent ( * scope ) ;
2019-03-04 10:13:12 -08:00
} else {
2019-03-04 16:28:35 -08:00
return nullptr ;
2019-03-04 10:13:12 -08:00
}
}
2019-03-04 16:28:35 -08:00
const Symbol * FindPointerComponent ( const DeclTypeSpec & type ) {
2019-03-04 10:13:12 -08:00
if ( const DerivedTypeSpec * derived { type . AsDerived ( ) } ) {
2019-03-04 16:28:35 -08:00
return FindPointerComponent ( * derived ) ;
2019-03-04 10:13:12 -08:00
} else {
2019-03-04 16:28:35 -08:00
return nullptr ;
2019-03-04 10:13:12 -08:00
}
}
2019-03-04 16:28:35 -08:00
const Symbol * FindPointerComponent ( const DeclTypeSpec * type ) {
return type ? FindPointerComponent ( * type ) : nullptr ;
2019-03-04 10:13:12 -08:00
}
2019-03-04 16:28:35 -08:00
const Symbol * FindPointerComponent ( const Symbol & symbol ) {
2019-04-18 15:07:40 -07:00
return IsPointer ( symbol ) ? & symbol : FindPointerComponent ( symbol . GetType ( ) ) ;
2019-03-04 10:13:12 -08:00
}
// C1594 specifies several ways by which an object might be globally visible.
2019-03-04 16:28:35 -08:00
const Symbol * FindExternallyVisibleObject (
2022-10-17 12:51:00 -07:00
const Symbol & object , const Scope & scope , bool isPointerDefinition ) {
2019-03-04 16:28:35 -08:00
// TODO: Storage association with any object for which this predicate holds,
// once EQUIVALENCE is supported.
2021-01-19 17:14:41 -08:00
const Symbol & ultimate { GetAssociationRoot ( object ) } ;
if ( IsDummy ( ultimate ) ) {
if ( IsIntentIn ( ultimate ) ) {
return & ultimate ;
}
2022-10-17 12:51:00 -07:00
if ( ! isPointerDefinition & & IsPointer ( ultimate ) & &
IsPureProcedure ( ultimate . owner ( ) ) & & IsFunction ( ultimate . owner ( ) ) ) {
2021-01-19 17:14:41 -08:00
return & ultimate ;
}
2022-10-17 12:51:00 -07:00
} else if ( ultimate . owner ( ) . IsDerivedType ( ) ) {
return nullptr ;
2021-01-19 17:14:41 -08:00
} else if ( & GetProgramUnitContaining ( ultimate ) ! =
& GetProgramUnitContaining ( scope ) ) {
2019-03-04 16:28:35 -08:00
return & object ;
2021-01-19 17:14:41 -08:00
} else if ( const Symbol * block { FindCommonBlockContaining ( ultimate ) } ) {
2019-03-04 16:28:35 -08:00
return block ;
}
2021-01-19 17:14:41 -08:00
return nullptr ;
2019-03-04 10:13:12 -08:00
}
2019-03-26 00:33:03 -07:00
2021-06-25 10:35:03 -07:00
const Symbol & BypassGeneric ( const Symbol & symbol ) {
const Symbol & ultimate { symbol . GetUltimate ( ) } ;
if ( const auto * generic { ultimate . detailsIf < GenericDetails > ( ) } ) {
if ( const Symbol * specific { generic - > specific ( ) } ) {
return * specific ;
}
}
return symbol ;
}
2019-04-19 08:22:28 -07:00
bool ExprHasTypeCategory (
const SomeExpr & expr , const common : : TypeCategory & type ) {
auto dynamicType { expr . GetType ( ) } ;
2019-11-09 09:29:31 -08:00
return dynamicType & & dynamicType - > category ( ) = = type ;
2019-03-26 00:33:03 -07:00
}
2019-03-18 16:19:41 +00:00
2019-04-11 21:25:45 +01:00
bool ExprTypeKindIsDefault (
2019-04-19 08:22:28 -07:00
const SomeExpr & expr , const SemanticsContext & context ) {
auto dynamicType { expr . GetType ( ) } ;
2019-11-09 09:29:31 -08:00
return dynamicType & &
2019-05-13 09:33:18 -07:00
dynamicType - > category ( ) ! = common : : TypeCategory : : Derived & &
2019-06-11 18:26:48 -07:00
dynamicType - > kind ( ) = = context . GetDefaultKind ( dynamicType - > category ( ) ) ;
2019-04-11 21:25:45 +01:00
}
2019-04-18 15:07:40 -07:00
2020-01-14 17:39:29 -08:00
// If an analyzed expr or assignment is missing, dump the node and die.
2020-03-27 14:17:25 -07:00
template < typename T >
2022-04-15 13:23:16 -07:00
static void CheckMissingAnalysis (
bool crash , SemanticsContext * context , const T & x ) {
if ( crash & & ! ( context & & context - > AnyFatalError ( ) ) ) {
2020-02-28 15:11:03 +00:00
std : : string buf ;
llvm : : raw_string_ostream ss { buf } ;
2020-01-14 17:39:29 -08:00
ss < < " node has not been analyzed: \n " ;
parser : : DumpTree ( ss , x ) ;
common : : die ( ss . str ( ) . c_str ( ) ) ;
}
}
2021-03-16 09:47:35 +01:00
const SomeExpr * GetExprHelper : : Get ( const parser : : Expr & x ) {
2022-04-15 13:23:16 -07:00
CheckMissingAnalysis ( crashIfNoExpr_ & & ! x . typedExpr , context_ , x ) ;
return x . typedExpr ? common : : GetPtrFromOptional ( x . typedExpr - > v ) : nullptr ;
2021-03-16 09:47:35 +01:00
}
2020-01-14 17:39:29 -08:00
const SomeExpr * GetExprHelper : : Get ( const parser : : Variable & x ) {
2022-04-15 13:23:16 -07:00
CheckMissingAnalysis ( crashIfNoExpr_ & & ! x . typedExpr , context_ , x ) ;
return x . typedExpr ? common : : GetPtrFromOptional ( x . typedExpr - > v ) : nullptr ;
2020-01-14 17:39:29 -08:00
}
2020-06-18 17:17:04 -07:00
const SomeExpr * GetExprHelper : : Get ( const parser : : DataStmtConstant & x ) {
2022-04-15 13:23:16 -07:00
CheckMissingAnalysis ( crashIfNoExpr_ & & ! x . typedExpr , context_ , x ) ;
return x . typedExpr ? common : : GetPtrFromOptional ( x . typedExpr - > v ) : nullptr ;
2021-03-16 09:47:35 +01:00
}
const SomeExpr * GetExprHelper : : Get ( const parser : : AllocateObject & x ) {
2022-04-15 13:23:16 -07:00
CheckMissingAnalysis ( crashIfNoExpr_ & & ! x . typedExpr , context_ , x ) ;
return x . typedExpr ? common : : GetPtrFromOptional ( x . typedExpr - > v ) : nullptr ;
2021-03-16 09:47:35 +01:00
}
const SomeExpr * GetExprHelper : : Get ( const parser : : PointerObject & x ) {
2022-04-15 13:23:16 -07:00
CheckMissingAnalysis ( crashIfNoExpr_ & & ! x . typedExpr , context_ , x ) ;
return x . typedExpr ? common : : GetPtrFromOptional ( x . typedExpr - > v ) : nullptr ;
2020-06-18 17:17:04 -07:00
}
2020-01-14 17:39:29 -08:00
2019-11-22 16:04:56 -08:00
const evaluate : : Assignment * GetAssignment ( const parser : : AssignmentStmt & x ) {
2022-04-15 13:23:16 -07:00
return x . typedAssignment ? common : : GetPtrFromOptional ( x . typedAssignment - > v )
: nullptr ;
2019-11-22 16:04:56 -08:00
}
2020-01-03 10:38:51 -08:00
const evaluate : : Assignment * GetAssignment (
const parser : : PointerAssignmentStmt & x ) {
2022-04-15 13:23:16 -07:00
return x . typedAssignment ? common : : GetPtrFromOptional ( x . typedAssignment - > v )
: nullptr ;
2020-01-03 10:38:51 -08:00
}
2019-11-22 16:04:56 -08:00
2019-07-16 14:37:56 -07:00
const Symbol * FindInterface ( const Symbol & symbol ) {
2022-03-23 14:05:50 -07:00
return common : : visit (
2019-07-16 14:37:56 -07:00
common : : visitors {
[ ] ( const ProcEntityDetails & details ) {
2022-12-16 09:54:55 -08:00
const Symbol * interface {
details . procInterface ( )
} ;
2022-08-09 09:01:50 -07:00
return interface ? FindInterface ( * interface ) : nullptr ;
} ,
[ ] ( const ProcBindingDetails & details ) {
return FindInterface ( details . symbol ( ) ) ;
} ,
[ & ] ( const SubprogramDetails & ) { return & symbol ; } ,
[ ] ( const UseDetails & details ) {
return FindInterface ( details . symbol ( ) ) ;
} ,
[ ] ( const HostAssocDetails & details ) {
return FindInterface ( details . symbol ( ) ) ;
} ,
[ ] ( const GenericDetails & details ) {
return details . specific ( ) ? FindInterface ( * details . specific ( ) )
: nullptr ;
2019-07-16 14:37:56 -07:00
} ,
[ ] ( const auto & ) - > const Symbol * { return nullptr ; } ,
} ,
symbol . details ( ) ) ;
}
const Symbol * FindSubprogram ( const Symbol & symbol ) {
2022-03-23 14:05:50 -07:00
return common : : visit (
2019-07-16 14:37:56 -07:00
common : : visitors {
[ & ] ( const ProcEntityDetails & details ) - > const Symbol * {
2022-12-16 09:54:55 -08:00
if ( details . procInterface ( ) ) {
return FindSubprogram ( * details . procInterface ( ) ) ;
2019-07-16 14:37:56 -07:00
} else {
return & symbol ;
}
} ,
[ ] ( const ProcBindingDetails & details ) {
return FindSubprogram ( details . symbol ( ) ) ;
} ,
[ & ] ( const SubprogramDetails & ) { return & symbol ; } ,
[ ] ( const UseDetails & details ) {
return FindSubprogram ( details . symbol ( ) ) ;
} ,
[ ] ( const HostAssocDetails & details ) {
return FindSubprogram ( details . symbol ( ) ) ;
} ,
2022-08-09 09:01:50 -07:00
[ ] ( const GenericDetails & details ) {
return details . specific ( ) ? FindSubprogram ( * details . specific ( ) )
: nullptr ;
} ,
2019-07-16 14:37:56 -07:00
[ ] ( const auto & ) - > const Symbol * { return nullptr ; } ,
} ,
symbol . details ( ) ) ;
}
2019-11-15 14:26:10 -08:00
const Symbol * FindOverriddenBinding ( const Symbol & symbol ) {
if ( symbol . has < ProcBindingDetails > ( ) ) {
if ( const DeclTypeSpec * parentType { FindParentTypeSpec ( symbol . owner ( ) ) } ) {
if ( const DerivedTypeSpec * parentDerived { parentType - > AsDerived ( ) } ) {
if ( const Scope * parentScope { parentDerived - > typeSymbol ( ) . scope ( ) } ) {
2023-05-16 12:33:29 -07:00
if ( const Symbol *
overridden { parentScope - > FindComponent ( symbol . name ( ) ) } ) {
// 7.5.7.3 p1: only accessible bindings are overridden
if ( ! overridden - > attrs ( ) . test ( Attr : : PRIVATE ) | |
( FindModuleContaining ( overridden - > owner ( ) ) = =
FindModuleContaining ( symbol . owner ( ) ) ) ) {
return overridden ;
}
}
2019-11-15 14:26:10 -08:00
}
}
}
}
return nullptr ;
}
2022-11-30 16:11:20 -08:00
const Symbol * FindGlobal ( const Symbol & original ) {
const Symbol & ultimate { original . GetUltimate ( ) } ;
if ( ultimate . owner ( ) . IsGlobal ( ) ) {
return & ultimate ;
}
bool isLocal { false } ;
if ( IsDummy ( ultimate ) ) {
} else if ( IsPointer ( ultimate ) ) {
} else if ( ultimate . has < ProcEntityDetails > ( ) ) {
isLocal = IsExternal ( ultimate ) ;
} else if ( const auto * subp { ultimate . detailsIf < SubprogramDetails > ( ) } ) {
isLocal = subp - > isInterface ( ) ;
}
if ( isLocal ) {
const std : : string * bind { ultimate . GetBindName ( ) } ;
if ( ! bind | | ultimate . name ( ) = = * bind ) {
const Scope & globalScope { ultimate . owner ( ) . context ( ) . globalScope ( ) } ;
if ( auto iter { globalScope . find ( ultimate . name ( ) ) } ;
iter ! = globalScope . end ( ) ) {
const Symbol & global { * iter - > second } ;
const std : : string * globalBind { global . GetBindName ( ) } ;
if ( ! globalBind | | global . name ( ) = = * globalBind ) {
return & global ;
}
}
}
}
return nullptr ;
}
2019-11-15 14:26:10 -08:00
const DeclTypeSpec * FindParentTypeSpec ( const DerivedTypeSpec & derived ) {
return FindParentTypeSpec ( derived . typeSymbol ( ) ) ;
}
const DeclTypeSpec * FindParentTypeSpec ( const DeclTypeSpec & decl ) {
if ( const DerivedTypeSpec * derived { decl . AsDerived ( ) } ) {
return FindParentTypeSpec ( * derived ) ;
} else {
return nullptr ;
}
}
const DeclTypeSpec * FindParentTypeSpec ( const Scope & scope ) {
if ( scope . kind ( ) = = Scope : : Kind : : DerivedType ) {
if ( const auto * symbol { scope . symbol ( ) } ) {
return FindParentTypeSpec ( * symbol ) ;
}
}
return nullptr ;
}
const DeclTypeSpec * FindParentTypeSpec ( const Symbol & symbol ) {
if ( const Scope * scope { symbol . scope ( ) } ) {
if ( const auto * details { symbol . detailsIf < DerivedTypeDetails > ( ) } ) {
if ( const Symbol * parent { details - > GetParentComponent ( * scope ) } ) {
return parent - > GetType ( ) ;
}
}
}
return nullptr ;
}
2021-08-10 10:22:39 -07:00
const EquivalenceSet * FindEquivalenceSet ( const Symbol & symbol ) {
const Symbol & ultimate { symbol . GetUltimate ( ) } ;
for ( const EquivalenceSet & set : ultimate . owner ( ) . equivalenceSets ( ) ) {
for ( const EquivalenceObject & object : set ) {
if ( object . symbol = = ultimate ) {
return & set ;
}
}
}
return nullptr ;
}
[flang] Fix classification of shape inquiries in specification exprs
In some contexts, including the motivating case of determining whether
the expressions that define the shape of a variable are "constant expressions"
in the sense of the Fortran standard, expression rewriting via Fold()
is not necessary, and should not be required. The inquiry intrinsics LBOUND,
UBOUND, and SIZE work correctly now in specification expressions and are
classified correctly as being constant expressions (or not). Getting this right
led to a fair amount of API clean-up as a consequence, including the
folding of shapes and TypeAndShape objects, and new APIs for shapes
that do not fold for those cases where folding isn't needed. Further,
the symbol-testing predicate APIs in Evaluate/tools.h now all resolve any
associations of their symbols and work transparently on use-, host-, and
construct-association symbols; the tools used to resolve those associations have
been defined and documented more precisely, and their clients adjusted as needed.
Differential Revision: https://reviews.llvm.org/D94561
2021-01-12 15:36:45 -08:00
bool IsOrContainsEventOrLockComponent ( const Symbol & original ) {
const Symbol & symbol { ResolveAssociations ( original ) } ;
if ( const auto * details { symbol . detailsIf < ObjectEntityDetails > ( ) } ) {
if ( const DeclTypeSpec * type { details - > type ( ) } ) {
if ( const DerivedTypeSpec * derived { type - > AsDerived ( ) } ) {
return IsEventTypeOrLockType ( derived ) | |
FindEventOrLockPotentialComponent ( * derived ) ;
2019-07-19 15:17:14 -07:00
}
}
}
return false ;
}
2019-08-08 15:06:51 -07:00
// Check this symbol suitable as a type-bound procedure - C769
2023-03-06 17:32:12 -08:00
bool CanBeTypeBoundProc ( const Symbol & symbol ) {
if ( IsDummy ( symbol ) | | IsProcedurePointer ( symbol ) ) {
2019-08-08 15:06:51 -07:00
return false ;
2023-03-06 17:32:12 -08:00
} else if ( symbol . has < SubprogramNameDetails > ( ) ) {
return symbol . owner ( ) . kind ( ) = = Scope : : Kind : : Module ;
} else if ( auto * details { symbol . detailsIf < SubprogramDetails > ( ) } ) {
if ( details - > isInterface ( ) ) {
return ! symbol . attrs ( ) . test ( Attr : : ABSTRACT ) ;
} else {
return symbol . owner ( ) . kind ( ) = = Scope : : Kind : : Module ;
}
} else if ( const auto * proc { symbol . detailsIf < ProcEntityDetails > ( ) } ) {
return ! symbol . attrs ( ) . test ( Attr : : INTRINSIC ) & &
2019-08-08 15:06:51 -07:00
proc - > HasExplicitInterface ( ) ;
} else {
return false ;
}
}
2021-08-10 10:22:39 -07:00
bool HasDeclarationInitializer ( const Symbol & symbol ) {
if ( IsNamedConstant ( symbol ) ) {
2020-01-09 17:12:46 -08:00
return false ;
} else if ( const auto * object { symbol . detailsIf < ObjectEntityDetails > ( ) } ) {
[flang] Fix classification of shape inquiries in specification exprs
In some contexts, including the motivating case of determining whether
the expressions that define the shape of a variable are "constant expressions"
in the sense of the Fortran standard, expression rewriting via Fold()
is not necessary, and should not be required. The inquiry intrinsics LBOUND,
UBOUND, and SIZE work correctly now in specification expressions and are
classified correctly as being constant expressions (or not). Getting this right
led to a fair amount of API clean-up as a consequence, including the
folding of shapes and TypeAndShape objects, and new APIs for shapes
that do not fold for those cases where folding isn't needed. Further,
the symbol-testing predicate APIs in Evaluate/tools.h now all resolve any
associations of their symbols and work transparently on use-, host-, and
construct-association symbols; the tools used to resolve those associations have
been defined and documented more precisely, and their clients adjusted as needed.
Differential Revision: https://reviews.llvm.org/D94561
2021-01-12 15:36:45 -08:00
return object - > init ( ) . has_value ( ) ;
2020-01-09 17:12:46 -08:00
} else if ( const auto * proc { symbol . detailsIf < ProcEntityDetails > ( ) } ) {
return proc - > init ( ) . has_value ( ) ;
2021-08-10 10:22:39 -07:00
} else {
return false ;
2020-01-09 17:12:46 -08:00
}
}
2023-04-19 11:59:43 -07:00
bool IsInitialized ( const Symbol & symbol , bool ignoreDataStatements ,
bool ignoreAllocatable , bool ignorePointer ) {
2022-02-07 08:44:50 -08:00
if ( ! ignoreAllocatable & & IsAllocatable ( symbol ) ) {
return true ;
} else if ( ! ignoreDataStatements & & symbol . test ( Symbol : : Flag : : InDataStmt ) ) {
return true ;
} else if ( HasDeclarationInitializer ( symbol ) ) {
[flang] Fix classification of shape inquiries in specification exprs
In some contexts, including the motivating case of determining whether
the expressions that define the shape of a variable are "constant expressions"
in the sense of the Fortran standard, expression rewriting via Fold()
is not necessary, and should not be required. The inquiry intrinsics LBOUND,
UBOUND, and SIZE work correctly now in specification expressions and are
classified correctly as being constant expressions (or not). Getting this right
led to a fair amount of API clean-up as a consequence, including the
folding of shapes and TypeAndShape objects, and new APIs for shapes
that do not fold for those cases where folding isn't needed. Further,
the symbol-testing predicate APIs in Evaluate/tools.h now all resolve any
associations of their symbols and work transparently on use-, host-, and
construct-association symbols; the tools used to resolve those associations have
been defined and documented more precisely, and their clients adjusted as needed.
Differential Revision: https://reviews.llvm.org/D94561
2021-01-12 15:36:45 -08:00
return true ;
2023-04-19 11:59:43 -07:00
} else if ( IsPointer ( symbol ) ) {
return ! ignorePointer ;
} else if ( IsNamedConstant ( symbol ) | | IsFunctionResult ( symbol ) ) {
[flang] Fix classification of shape inquiries in specification exprs
In some contexts, including the motivating case of determining whether
the expressions that define the shape of a variable are "constant expressions"
in the sense of the Fortran standard, expression rewriting via Fold()
is not necessary, and should not be required. The inquiry intrinsics LBOUND,
UBOUND, and SIZE work correctly now in specification expressions and are
classified correctly as being constant expressions (or not). Getting this right
led to a fair amount of API clean-up as a consequence, including the
folding of shapes and TypeAndShape objects, and new APIs for shapes
that do not fold for those cases where folding isn't needed. Further,
the symbol-testing predicate APIs in Evaluate/tools.h now all resolve any
associations of their symbols and work transparently on use-, host-, and
construct-association symbols; the tools used to resolve those associations have
been defined and documented more precisely, and their clients adjusted as needed.
Differential Revision: https://reviews.llvm.org/D94561
2021-01-12 15:36:45 -08:00
return false ;
} else if ( const auto * object { symbol . detailsIf < ObjectEntityDetails > ( ) } ) {
if ( ! object - > isDummy ( ) & & object - > type ( ) ) {
2021-08-10 10:22:39 -07:00
if ( const auto * derived { object - > type ( ) - > AsDerived ( ) } ) {
2023-04-19 11:59:43 -07:00
return derived - > HasDefaultInitialization (
ignoreAllocatable , ignorePointer ) ;
2021-08-10 10:22:39 -07:00
}
[flang] Fix classification of shape inquiries in specification exprs
In some contexts, including the motivating case of determining whether
the expressions that define the shape of a variable are "constant expressions"
in the sense of the Fortran standard, expression rewriting via Fold()
is not necessary, and should not be required. The inquiry intrinsics LBOUND,
UBOUND, and SIZE work correctly now in specification expressions and are
classified correctly as being constant expressions (or not). Getting this right
led to a fair amount of API clean-up as a consequence, including the
folding of shapes and TypeAndShape objects, and new APIs for shapes
that do not fold for those cases where folding isn't needed. Further,
the symbol-testing predicate APIs in Evaluate/tools.h now all resolve any
associations of their symbols and work transparently on use-, host-, and
construct-association symbols; the tools used to resolve those associations have
been defined and documented more precisely, and their clients adjusted as needed.
Differential Revision: https://reviews.llvm.org/D94561
2021-01-12 15:36:45 -08:00
}
}
return false ;
}
2021-07-19 11:53:20 -07:00
bool IsDestructible ( const Symbol & symbol , const Symbol * derivedTypeSymbol ) {
if ( IsAllocatable ( symbol ) | | IsAutomatic ( symbol ) ) {
return true ;
} else if ( IsNamedConstant ( symbol ) | | IsFunctionResult ( symbol ) | |
IsPointer ( symbol ) ) {
return false ;
} else if ( const auto * object { symbol . detailsIf < ObjectEntityDetails > ( ) } ) {
if ( ! object - > isDummy ( ) & & object - > type ( ) ) {
if ( const auto * derived { object - > type ( ) - > AsDerived ( ) } ) {
return & derived - > typeSymbol ( ) ! = derivedTypeSymbol & &
derived - > HasDestruction ( ) ;
}
}
}
return false ;
}
2020-03-19 20:07:01 -07:00
bool HasIntrinsicTypeName ( const Symbol & symbol ) {
std : : string name { symbol . name ( ) . ToString ( ) } ;
if ( name = = " doubleprecision " ) {
return true ;
} else if ( name = = " derived " ) {
return false ;
} else {
for ( int i { 0 } ; i ! = common : : TypeCategory_enumSize ; + + i ) {
if ( name = = parser : : ToLowerCaseLetters ( EnumToString ( TypeCategory { i } ) ) ) {
return true ;
}
}
return false ;
}
}
2020-03-19 16:31:10 -07:00
bool IsSeparateModuleProcedureInterface ( const Symbol * symbol ) {
if ( symbol & & symbol - > attrs ( ) . test ( Attr : : MODULE ) ) {
if ( auto * details { symbol - > detailsIf < SubprogramDetails > ( ) } ) {
return details - > isInterface ( ) ;
}
}
return false ;
}
2023-03-02 08:15:51 -08:00
SymbolVector FinalsForDerivedTypeInstantiation ( const DerivedTypeSpec & spec ) {
SymbolVector result ;
const Symbol & typeSymbol { spec . typeSymbol ( ) } ;
if ( const auto * derived { typeSymbol . detailsIf < DerivedTypeDetails > ( ) } ) {
for ( const auto & pair : derived - > finals ( ) ) {
const Symbol & subr { * pair . second } ;
// Errors in FINAL subroutines are caught in CheckFinal
// in check-declarations.cpp.
if ( const auto * subprog { subr . detailsIf < SubprogramDetails > ( ) } ;
subprog & & subprog - > dummyArgs ( ) . size ( ) = = 1 ) {
if ( const Symbol * arg { subprog - > dummyArgs ( ) [ 0 ] } ) {
if ( const DeclTypeSpec * type { arg - > GetType ( ) } ) {
if ( type - > category ( ) = = DeclTypeSpec : : TypeDerived & &
evaluate : : AreSameDerivedType ( spec , type - > derivedTypeSpec ( ) ) ) {
result . emplace_back ( subr ) ;
}
}
}
}
}
}
return result ;
}
2023-03-30 10:26:16 -07:00
const Symbol * IsFinalizable ( const Symbol & symbol ,
std : : set < const DerivedTypeSpec * > * inProgress , bool withImpureFinalizer ) {
if ( IsPointer ( symbol ) | | evaluate : : IsAssumedRank ( symbol ) ) {
return nullptr ;
2020-12-07 14:46:24 -08:00
}
if ( const auto * object { symbol . detailsIf < ObjectEntityDetails > ( ) } ) {
if ( object - > isDummy ( ) & & ! IsIntentOut ( symbol ) ) {
2023-03-30 10:26:16 -07:00
return nullptr ;
2019-07-02 12:10:09 -07:00
}
2020-12-07 14:46:24 -08:00
const DeclTypeSpec * type { object - > type ( ) } ;
2023-03-30 10:26:16 -07:00
if ( const DerivedTypeSpec * typeSpec { type ? type - > AsDerived ( ) : nullptr } ) {
return IsFinalizable (
* typeSpec , inProgress , withImpureFinalizer , symbol . Rank ( ) ) ;
}
2019-07-02 12:10:09 -07:00
}
2023-03-30 10:26:16 -07:00
return nullptr ;
2019-07-02 12:10:09 -07:00
}
2023-03-30 10:26:16 -07:00
const Symbol * IsFinalizable ( const DerivedTypeSpec & derived ,
std : : set < const DerivedTypeSpec * > * inProgress , bool withImpureFinalizer ,
std : : optional < int > rank ) {
const Symbol * elemental { nullptr } ;
for ( auto ref : FinalsForDerivedTypeInstantiation ( derived ) ) {
const Symbol * symbol { & ref - > GetUltimate ( ) } ;
if ( const auto * binding { symbol - > detailsIf < ProcBindingDetails > ( ) } ) {
symbol = & binding - > symbol ( ) ;
}
if ( const auto * proc { symbol - > detailsIf < ProcEntityDetails > ( ) } ) {
symbol = proc - > procInterface ( ) ;
}
if ( ! symbol ) {
} else if ( IsElementalProcedure ( * symbol ) ) {
elemental = symbol ;
} else {
if ( rank ) {
if ( const SubprogramDetails *
subp { symbol - > detailsIf < SubprogramDetails > ( ) } ) {
if ( const auto & args { subp - > dummyArgs ( ) } ; ! args . empty ( ) & &
args . at ( 0 ) & & ! evaluate : : IsAssumedRank ( * args . at ( 0 ) ) & &
args . at ( 0 ) - > Rank ( ) ! = * rank ) {
continue ; // not a finalizer for this rank
}
}
}
if ( ! withImpureFinalizer | | ! IsPureProcedure ( * symbol ) ) {
return symbol ;
}
// Found non-elemental pure finalizer of matching rank, but still
// need to check components for an impure finalizer.
elemental = nullptr ;
break ;
}
2020-09-30 13:34:23 -07:00
}
2023-03-30 10:26:16 -07:00
if ( elemental & & ( ! withImpureFinalizer | | ! IsPureProcedure ( * elemental ) ) ) {
return elemental ;
}
// Check components (including ancestors)
2021-07-29 12:02:45 -07:00
std : : set < const DerivedTypeSpec * > basis ;
if ( inProgress ) {
if ( inProgress - > find ( & derived ) ! = inProgress - > end ( ) ) {
2023-03-30 10:26:16 -07:00
return nullptr ; // don't loop on recursive type
2021-07-29 12:02:45 -07:00
}
} else {
inProgress = & basis ;
}
auto iterator { inProgress - > insert ( & derived ) . first } ;
2023-03-30 10:26:16 -07:00
const Symbol * result { nullptr } ;
for ( const Symbol & component : PotentialComponentIterator { derived } ) {
result = IsFinalizable ( component , inProgress , withImpureFinalizer ) ;
if ( result ) {
break ;
}
}
2021-07-29 12:02:45 -07:00
inProgress - > erase ( iterator ) ;
return result ;
2019-11-12 15:43:09 -08:00
}
2023-03-30 10:26:16 -07:00
static const Symbol * HasImpureFinal (
const DerivedTypeSpec & derived , std : : optional < int > rank ) {
return IsFinalizable ( derived , nullptr , /*withImpureFinalizer=*/ true , rank ) ;
}
const Symbol * HasImpureFinal ( const Symbol & original ) {
const Symbol & symbol { ResolveAssociations ( original ) } ;
if ( symbol . has < ObjectEntityDetails > ( ) ) {
if ( const DeclTypeSpec * symType { symbol . GetType ( ) } ) {
if ( const DerivedTypeSpec * derived { symType - > AsDerived ( ) } ) {
// finalizable assumed-rank not allowed (C839)
return evaluate : : IsAssumedRank ( symbol )
? nullptr
: HasImpureFinal ( * derived , symbol . Rank ( ) ) ;
}
2023-03-02 08:15:51 -08:00
}
2020-09-30 13:34:23 -07:00
}
2023-03-30 10:26:16 -07:00
return nullptr ;
2019-11-12 15:43:09 -08:00
}
2023-09-25 18:53:36 +02:00
bool MayRequireFinalization ( const DerivedTypeSpec & derived ) {
return IsFinalizable ( derived ) | |
FindPolymorphicAllocatableUltimateComponent ( derived ) ;
}
2023-10-03 13:10:26 -07:00
bool HasAllocatableDirectComponent ( const DerivedTypeSpec & derived ) {
DirectComponentIterator directs { derived } ;
return std : : any_of ( directs . begin ( ) , directs . end ( ) , IsAllocatable ) ;
}
2019-09-09 17:01:06 -07:00
bool IsAssumedLengthCharacter ( const Symbol & symbol ) {
if ( const DeclTypeSpec * type { symbol . GetType ( ) } ) {
return type - > category ( ) = = DeclTypeSpec : : Character & &
type - > characterTypeSpec ( ) . length ( ) . isAssumed ( ) ;
} else {
return false ;
}
}
2020-06-03 10:26:10 +05:30
bool IsInBlankCommon ( const Symbol & symbol ) {
2020-06-18 17:17:04 -07:00
const Symbol * block { FindCommonBlockContaining ( symbol ) } ;
return block & & block - > name ( ) . empty ( ) ;
2020-06-03 10:26:10 +05:30
}
2020-02-26 20:19:48 -08:00
// C722 and C723: For a function to be assumed length, it must be external and
// of CHARACTER type
2020-03-19 16:31:10 -07:00
bool IsExternal ( const Symbol & symbol ) {
2020-09-30 13:34:23 -07:00
return ClassifyProcedure ( symbol ) = = ProcedureDefinitionClass : : External ;
2019-09-09 17:01:06 -07:00
}
2021-08-10 10:22:39 -07:00
// Most scopes have no EQUIVALENCE, and this function is a fast no-op for them.
std : : list < std : : list < SymbolRef > > GetStorageAssociations ( const Scope & scope ) {
UnorderedSymbolSet distinct ;
for ( const EquivalenceSet & set : scope . equivalenceSets ( ) ) {
for ( const EquivalenceObject & object : set ) {
distinct . emplace ( object . symbol ) ;
}
}
// This set is ordered by ascending offsets, with ties broken by greatest
// size. A multiset is used here because multiple symbols may have the
// same offset and size; the symbols in the set, however, are distinct.
std : : multiset < SymbolRef , SymbolOffsetCompare > associated ;
for ( SymbolRef ref : distinct ) {
associated . emplace ( * ref ) ;
}
std : : list < std : : list < SymbolRef > > result ;
std : : size_t limit { 0 } ;
const Symbol * currentCommon { nullptr } ;
for ( const Symbol & symbol : associated ) {
const Symbol * thisCommon { FindCommonBlockContaining ( symbol ) } ;
if ( result . empty ( ) | | symbol . offset ( ) > = limit | |
thisCommon ! = currentCommon ) {
// Start a new group
result . emplace_back ( std : : list < SymbolRef > { } ) ;
limit = 0 ;
currentCommon = thisCommon ;
}
result . back ( ) . emplace_back ( symbol ) ;
limit = std : : max ( limit , symbol . offset ( ) + symbol . size ( ) ) ;
}
return result ;
}
2020-09-30 13:34:23 -07:00
bool IsModuleProcedure ( const Symbol & symbol ) {
return ClassifyProcedure ( symbol ) = = ProcedureDefinitionClass : : Module ;
}
2019-07-19 15:17:14 -07:00
2019-11-12 15:43:09 -08:00
class ImageControlStmtHelper {
2022-06-12 10:16:46 -07:00
using ImageControlStmts =
std : : variant < parser : : ChangeTeamConstruct , parser : : CriticalConstruct ,
parser : : EventPostStmt , parser : : EventWaitStmt , parser : : FormTeamStmt ,
parser : : LockStmt , parser : : SyncAllStmt , parser : : SyncImagesStmt ,
parser : : SyncMemoryStmt , parser : : SyncTeamStmt , parser : : UnlockStmt > ;
2019-11-12 15:43:09 -08:00
public :
2020-03-27 14:17:25 -07:00
template < typename T > bool operator ( ) ( const T & ) {
2019-10-11 14:39:33 -07:00
return common : : HasMember < T , ImageControlStmts > ;
}
2020-03-27 14:17:25 -07:00
template < typename T > bool operator ( ) ( const common : : Indirection < T > & x ) {
2019-10-11 14:39:33 -07:00
return ( * this ) ( x . value ( ) ) ;
}
2023-03-17 15:26:25 -07:00
template < typename A > bool operator ( ) ( const parser : : Statement < A > & x ) {
return ( * this ) ( x . statement ) ;
}
2019-10-11 14:39:33 -07:00
bool operator ( ) ( const parser : : AllocateStmt & stmt ) {
const auto & allocationList { std : : get < std : : list < parser : : Allocation > > ( stmt . t ) } ;
for ( const auto & allocation : allocationList ) {
const auto & allocateObject {
std : : get < parser : : AllocateObject > ( allocation . t ) } ;
if ( IsCoarrayObject ( allocateObject ) ) {
return true ;
}
}
return false ;
}
bool operator ( ) ( const parser : : DeallocateStmt & stmt ) {
const auto & allocateObjectList {
std : : get < std : : list < parser : : AllocateObject > > ( stmt . t ) } ;
for ( const auto & allocateObject : allocateObjectList ) {
if ( IsCoarrayObject ( allocateObject ) ) {
return true ;
}
}
return false ;
}
bool operator ( ) ( const parser : : CallStmt & stmt ) {
const auto & procedureDesignator {
2023-05-06 15:03:39 -07:00
std : : get < parser : : ProcedureDesignator > ( stmt . call . t ) } ;
2019-10-11 14:39:33 -07:00
if ( auto * name { std : : get_if < parser : : Name > ( & procedureDesignator . u ) } ) {
// TODO: also ensure that the procedure is, in fact, an intrinsic
if ( name - > source = = " move_alloc " ) {
2023-05-06 15:03:39 -07:00
const auto & args {
std : : get < std : : list < parser : : ActualArgSpec > > ( stmt . call . t ) } ;
2019-10-11 14:39:33 -07:00
if ( ! args . empty ( ) ) {
const parser : : ActualArg & actualArg {
std : : get < parser : : ActualArg > ( args . front ( ) . t ) } ;
if ( const auto * argExpr {
std : : get_if < common : : Indirection < parser : : Expr > > (
& actualArg . u ) } ) {
return HasCoarray ( argExpr - > value ( ) ) ;
}
}
}
}
return false ;
}
2022-06-12 10:16:46 -07:00
bool operator ( ) ( const parser : : StopStmt & stmt ) {
// STOP is an image control statement; ERROR STOP is not
return std : : get < parser : : StopStmt : : Kind > ( stmt . t ) = =
parser : : StopStmt : : Kind : : Stop ;
}
2023-03-17 15:26:25 -07:00
bool operator ( ) ( const parser : : IfStmt & stmt ) {
return ( * this ) (
std : : get < parser : : UnlabeledStatement < parser : : ActionStmt > > ( stmt . t )
. statement ) ;
}
bool operator ( ) ( const parser : : ActionStmt & stmt ) {
return common : : visit ( * this , stmt . u ) ;
2019-10-11 14:39:33 -07:00
}
2019-11-12 15:43:09 -08:00
private :
bool IsCoarrayObject ( const parser : : AllocateObject & allocateObject ) {
const parser : : Name & name { GetLastName ( allocateObject ) } ;
2021-11-18 11:48:42 -08:00
return name . symbol & & evaluate : : IsCoarray ( * name . symbol ) ;
2019-11-12 15:43:09 -08:00
}
2019-10-11 14:39:33 -07:00
} ;
bool IsImageControlStmt ( const parser : : ExecutableConstruct & construct ) {
2022-03-23 14:05:50 -07:00
return common : : visit ( ImageControlStmtHelper { } , construct . u ) ;
2019-10-11 14:39:33 -07:00
}
std : : optional < parser : : MessageFixedText > GetImageControlStmtCoarrayMsg (
const parser : : ExecutableConstruct & construct ) {
if ( const auto * actionStmt {
std : : get_if < parser : : Statement < parser : : ActionStmt > > ( & construct . u ) } ) {
2022-03-23 14:05:50 -07:00
return common : : visit (
2019-10-11 14:39:33 -07:00
common : : visitors {
[ ] ( const common : : Indirection < parser : : AllocateStmt > & )
- > std : : optional < parser : : MessageFixedText > {
return " ALLOCATE of a coarray is an image control "
" statement " _en_US ;
} ,
[ ] ( const common : : Indirection < parser : : DeallocateStmt > & )
- > std : : optional < parser : : MessageFixedText > {
return " DEALLOCATE of a coarray is an image control "
" statement " _en_US ;
} ,
[ ] ( const common : : Indirection < parser : : CallStmt > & )
- > std : : optional < parser : : MessageFixedText > {
return " MOVE_ALLOC of a coarray is an image control "
" statement " _en_US ;
} ,
[ ] ( const auto & ) - > std : : optional < parser : : MessageFixedText > {
return std : : nullopt ;
} ,
} ,
actionStmt - > statement . u ) ;
}
return std : : nullopt ;
}
2019-11-12 15:43:09 -08:00
parser : : CharBlock GetImageControlStmtLocation (
2019-10-11 14:39:33 -07:00
const parser : : ExecutableConstruct & executableConstruct ) {
2022-03-23 14:05:50 -07:00
return common : : visit (
2019-10-11 14:39:33 -07:00
common : : visitors {
[ ] ( const common : : Indirection < parser : : ChangeTeamConstruct >
& construct ) {
return std : : get < parser : : Statement < parser : : ChangeTeamStmt > > (
construct . value ( ) . t )
. source ;
} ,
[ ] ( const common : : Indirection < parser : : CriticalConstruct > & construct ) {
return std : : get < parser : : Statement < parser : : CriticalStmt > > (
construct . value ( ) . t )
. source ;
} ,
[ ] ( const parser : : Statement < parser : : ActionStmt > & actionStmt ) {
return actionStmt . source ;
} ,
[ ] ( const auto & ) { return parser : : CharBlock { } ; } ,
} ,
executableConstruct . u ) ;
}
bool HasCoarray ( const parser : : Expr & expression ) {
2022-04-15 13:23:16 -07:00
if ( const auto * expr { GetExpr ( nullptr , expression ) } ) {
2019-10-22 16:53:29 -07:00
for ( const Symbol & symbol : evaluate : : CollectSymbols ( * expr ) ) {
2021-11-18 11:48:42 -08:00
if ( evaluate : : IsCoarray ( symbol ) ) {
[flang] Fix classification of shape inquiries in specification exprs
In some contexts, including the motivating case of determining whether
the expressions that define the shape of a variable are "constant expressions"
in the sense of the Fortran standard, expression rewriting via Fold()
is not necessary, and should not be required. The inquiry intrinsics LBOUND,
UBOUND, and SIZE work correctly now in specification expressions and are
classified correctly as being constant expressions (or not). Getting this right
led to a fair amount of API clean-up as a consequence, including the
folding of shapes and TypeAndShape objects, and new APIs for shapes
that do not fold for those cases where folding isn't needed. Further,
the symbol-testing predicate APIs in Evaluate/tools.h now all resolve any
associations of their symbols and work transparently on use-, host-, and
construct-association symbols; the tools used to resolve those associations have
been defined and documented more precisely, and their clients adjusted as needed.
Differential Revision: https://reviews.llvm.org/D94561
2021-01-12 15:36:45 -08:00
return true ;
2019-10-11 14:39:33 -07:00
}
}
}
return false ;
}
2022-10-04 21:29:28 +02:00
bool IsAssumedType ( const Symbol & symbol ) {
if ( const DeclTypeSpec * type { symbol . GetType ( ) } ) {
return type - > IsAssumedType ( ) ;
}
return false ;
}
[flang] Changes to check for constraint C1140
This constraint prohibits deallocation of polymorphic entities in a DO
CONCURRENT.
Section 9.7.3.2 specifies the situations that might cause deallocation
of a polymorphic entity. The ones that are applicable to a DO CONCURRENT
are exiting from a block that declares such variables, intrinsic
assignment, and an actual DEALLOCATE statement. This section also
specifies (paragraph 8) that deallocation of a derived type causes
deallocation of all of its allocatable subobjects.
Section 10.2.1.3 specifies what happens during intrinsic assignment.
Paragraph 3 states If the variable is an allocated allocatable variable,
it is deallocated if expr is an array of different shape, any
corresponding length type parameter values of the variable and expr
differ, or the variable is polymorphic and the dynamic type or any
corresponding kind type parameter values of the variable and expr
differ." Thus, an allocatable polymorphic variable on the left hand side
of an assignment statement gets deallocated. Paragraph 13 states that
"For a noncoarray allocatable component the following sequence of
operations is applied.
(1) If the component of the variable is allocated, it is deallocated."
Thus, a variable on the left-hand side of an assignment statement might have noncorray allocatable components. Such components will be deallocated.
Deallocation can be caused by exiting from a block where the entity is
declared, from an assignment, and from direct deallocation.
Original-commit: flang-compiler/f18@7d1932d344308d8266503268a7534532cebe6087
Reviewed-on: https://github.com/flang-compiler/f18/pull/814
2019-11-05 10:18:33 -08:00
bool IsPolymorphic ( const Symbol & symbol ) {
if ( const DeclTypeSpec * type { symbol . GetType ( ) } ) {
return type - > IsPolymorphic ( ) ;
2019-11-12 15:43:09 -08:00
}
return false ;
}
2023-01-31 13:46:12 +01:00
bool IsUnlimitedPolymorphic ( const Symbol & symbol ) {
if ( const DeclTypeSpec * type { symbol . GetType ( ) } ) {
return type - > IsUnlimitedPolymorphic ( ) ;
}
return false ;
}
[flang] Changes to check for constraint C1140
This constraint prohibits deallocation of polymorphic entities in a DO
CONCURRENT.
Section 9.7.3.2 specifies the situations that might cause deallocation
of a polymorphic entity. The ones that are applicable to a DO CONCURRENT
are exiting from a block that declares such variables, intrinsic
assignment, and an actual DEALLOCATE statement. This section also
specifies (paragraph 8) that deallocation of a derived type causes
deallocation of all of its allocatable subobjects.
Section 10.2.1.3 specifies what happens during intrinsic assignment.
Paragraph 3 states If the variable is an allocated allocatable variable,
it is deallocated if expr is an array of different shape, any
corresponding length type parameter values of the variable and expr
differ, or the variable is polymorphic and the dynamic type or any
corresponding kind type parameter values of the variable and expr
differ." Thus, an allocatable polymorphic variable on the left hand side
of an assignment statement gets deallocated. Paragraph 13 states that
"For a noncoarray allocatable component the following sequence of
operations is applied.
(1) If the component of the variable is allocated, it is deallocated."
Thus, a variable on the left-hand side of an assignment statement might have noncorray allocatable components. Such components will be deallocated.
Deallocation can be caused by exiting from a block where the entity is
declared, from an assignment, and from direct deallocation.
Original-commit: flang-compiler/f18@7d1932d344308d8266503268a7534532cebe6087
Reviewed-on: https://github.com/flang-compiler/f18/pull/814
2019-11-05 10:18:33 -08:00
bool IsPolymorphicAllocatable ( const Symbol & symbol ) {
return IsAllocatable ( symbol ) & & IsPolymorphic ( symbol ) ;
}
2023-05-06 15:03:39 -07:00
const Scope * FindCUDADeviceContext ( const Scope * scope ) {
return ! scope ? nullptr : FindScopeContaining ( * scope , [ ] ( const Scope & s ) {
return IsCUDADeviceContext ( & s ) ;
} ) ;
}
std : : optional < common : : CUDADataAttr > GetCUDADataAttr ( const Symbol * symbol ) {
const auto * object {
symbol ? symbol - > detailsIf < ObjectEntityDetails > ( ) : nullptr } ;
return object ? object - > cudaDataAttr ( ) : std : : nullopt ;
}
2022-11-30 17:40:48 -08:00
std : : optional < parser : : MessageFormattedText > CheckAccessibleSymbol (
2020-03-02 16:43:01 -08:00
const Scope & scope , const Symbol & symbol ) {
if ( symbol . attrs ( ) . test ( Attr : : PRIVATE ) ) {
2021-01-15 11:52:10 -08:00
if ( FindModuleFileContaining ( scope ) ) {
// Don't enforce component accessibility checks in module files;
// there may be forward-substituted named constants of derived type
// whose structure constructors reference private components.
} else if ( const Scope *
moduleScope { FindModuleContaining ( symbol . owner ( ) ) } ) {
2020-03-10 15:31:02 -07:00
if ( ! moduleScope - > Contains ( scope ) ) {
2020-03-02 16:43:01 -08:00
return parser : : MessageFormattedText {
2022-11-30 17:40:48 -08:00
" PRIVATE name '%s' is only accessible within module '%s' " _err_en_US ,
2020-03-02 16:43:01 -08:00
symbol . name ( ) , moduleScope - > GetName ( ) . value ( ) } ;
}
}
}
return std : : nullopt ;
}
2019-07-11 06:29:31 -07:00
std : : list < SourceName > OrderParameterNames ( const Symbol & typeSymbol ) {
std : : list < SourceName > result ;
if ( const DerivedTypeSpec * spec { typeSymbol . GetParentTypeSpec ( ) } ) {
result = OrderParameterNames ( spec - > typeSymbol ( ) ) ;
}
const auto & paramNames { typeSymbol . get < DerivedTypeDetails > ( ) . paramNames ( ) } ;
result . insert ( result . end ( ) , paramNames . begin ( ) , paramNames . end ( ) ) ;
return result ;
}
SymbolVector OrderParameterDeclarations ( const Symbol & typeSymbol ) {
SymbolVector result ;
if ( const DerivedTypeSpec * spec { typeSymbol . GetParentTypeSpec ( ) } ) {
result = OrderParameterDeclarations ( spec - > typeSymbol ( ) ) ;
}
const auto & paramDecls { typeSymbol . get < DerivedTypeDetails > ( ) . paramDecls ( ) } ;
result . insert ( result . end ( ) , paramDecls . begin ( ) , paramDecls . end ( ) ) ;
return result ;
}
2021-04-07 13:17:39 -07:00
const DeclTypeSpec & FindOrInstantiateDerivedType (
Scope & scope , DerivedTypeSpec & & spec , DeclTypeSpec : : Category category ) {
spec . EvaluateParameters ( scope . context ( ) ) ;
2019-07-10 18:20:27 -07:00
if ( const DeclTypeSpec *
2019-11-22 08:15:02 -08:00
type { scope . FindInstantiatedDerivedType ( spec , category ) } ) {
2019-07-10 18:20:27 -07:00
return * type ;
}
// Create a new instantiation of this parameterized derived type
// for this particular distinct set of actual parameter values.
2019-09-11 18:21:07 -07:00
DeclTypeSpec & type { scope . MakeDerivedType ( category , std : : move ( spec ) ) } ;
2021-04-07 13:17:39 -07:00
type . derivedTypeSpec ( ) . Instantiate ( scope ) ;
2019-07-10 18:20:27 -07:00
return type ;
}
2020-03-19 16:31:10 -07:00
const Symbol * FindSeparateModuleSubprogramInterface ( const Symbol * proc ) {
if ( proc ) {
2022-02-18 14:58:12 -08:00
if ( const auto * subprogram { proc - > detailsIf < SubprogramDetails > ( ) } ) {
if ( const Symbol * iface { subprogram - > moduleInterface ( ) } ) {
return iface ;
2020-03-19 16:31:10 -07:00
}
}
}
return nullptr ;
}
2020-09-30 13:34:23 -07:00
ProcedureDefinitionClass ClassifyProcedure ( const Symbol & symbol ) { // 15.2.2
const Symbol & ultimate { symbol . GetUltimate ( ) } ;
2022-06-15 09:18:25 -07:00
if ( ! IsProcedure ( ultimate ) ) {
return ProcedureDefinitionClass : : None ;
} else if ( ultimate . attrs ( ) . test ( Attr : : INTRINSIC ) ) {
2020-09-30 13:34:23 -07:00
return ProcedureDefinitionClass : : Intrinsic ;
2023-01-06 17:49:15 -08:00
} else if ( IsDummy ( ultimate ) ) {
return ProcedureDefinitionClass : : Dummy ;
} else if ( IsProcedurePointer ( symbol ) ) {
return ProcedureDefinitionClass : : Pointer ;
2020-09-30 13:34:23 -07:00
} else if ( ultimate . attrs ( ) . test ( Attr : : EXTERNAL ) ) {
return ProcedureDefinitionClass : : External ;
2022-09-01 10:14:24 -07:00
} else if ( const auto * nameDetails {
ultimate . detailsIf < SubprogramNameDetails > ( ) } ) {
switch ( nameDetails - > kind ( ) ) {
case SubprogramKind : : Module :
return ProcedureDefinitionClass : : Module ;
case SubprogramKind : : Internal :
return ProcedureDefinitionClass : : Internal ;
}
2020-09-30 13:34:23 -07:00
} else if ( const Symbol * subp { FindSubprogram ( symbol ) } ) {
if ( const auto * subpDetails { subp - > detailsIf < SubprogramDetails > ( ) } ) {
if ( subpDetails - > stmtFunction ( ) ) {
return ProcedureDefinitionClass : : StatementFunction ;
}
}
switch ( ultimate . owner ( ) . kind ( ) ) {
case Scope : : Kind : : Global :
2022-01-26 09:54:58 -08:00
case Scope : : Kind : : IntrinsicModules :
2020-09-30 13:34:23 -07:00
return ProcedureDefinitionClass : : External ;
case Scope : : Kind : : Module :
return ProcedureDefinitionClass : : Module ;
case Scope : : Kind : : MainProgram :
case Scope : : Kind : : Subprogram :
return ProcedureDefinitionClass : : Internal ;
default :
break ;
}
}
return ProcedureDefinitionClass : : None ;
}
2019-07-31 07:19:22 -07:00
// ComponentIterator implementation
2020-03-27 14:17:25 -07:00
template < ComponentKind componentKind >
2019-07-31 07:19:22 -07:00
typename ComponentIterator < componentKind > : : const_iterator
ComponentIterator < componentKind > : : const_iterator : : Create (
const DerivedTypeSpec & derived ) {
const_iterator it { } ;
2019-10-22 16:53:29 -07:00
it . componentPath_ . emplace_back ( derived ) ;
2020-03-27 14:17:25 -07:00
it . Increment ( ) ; // cue up first relevant component, if any
2019-10-22 16:53:29 -07:00
return it ;
2019-07-31 07:19:22 -07:00
}
2019-07-26 06:33:48 -07:00
2020-03-27 14:17:25 -07:00
template < ComponentKind componentKind >
2019-10-22 16:53:29 -07:00
const DerivedTypeSpec *
ComponentIterator < componentKind > : : const_iterator : : PlanComponentTraversal (
const Symbol & component ) const {
2019-07-31 07:19:22 -07:00
if ( const auto * details { component . detailsIf < ObjectEntityDetails > ( ) } ) {
2019-10-22 16:53:29 -07:00
if ( const DeclTypeSpec * type { details - > type ( ) } ) {
if ( const auto * derived { type - > AsDerived ( ) } ) {
bool traverse { false } ;
if constexpr ( componentKind = = ComponentKind : : Ordered ) {
// Order Component (only visit parents)
traverse = component . test ( Symbol : : Flag : : ParentComp ) ;
} else if constexpr ( componentKind = = ComponentKind : : Direct ) {
2023-08-21 12:21:49 -07:00
traverse = ! IsAllocatableOrObjectPointer ( & component ) ;
2019-10-22 16:53:29 -07:00
} else if constexpr ( componentKind = = ComponentKind : : Ultimate ) {
2023-08-21 12:21:49 -07:00
traverse = ! IsAllocatableOrObjectPointer ( & component ) ;
2019-10-22 16:53:29 -07:00
} else if constexpr ( componentKind = = ComponentKind : : Potential ) {
traverse = ! IsPointer ( component ) ;
2019-11-12 15:43:09 -08:00
} else if constexpr ( componentKind = = ComponentKind : : Scope ) {
2023-08-21 12:21:49 -07:00
traverse = ! IsAllocatableOrObjectPointer ( & component ) ;
2022-11-17 16:30:49 -08:00
} else if constexpr ( componentKind = =
ComponentKind : : PotentialAndPointer ) {
traverse = ! IsPointer ( component ) ;
2019-10-22 16:53:29 -07:00
}
if ( traverse ) {
const Symbol & newTypeSymbol { derived - > typeSymbol ( ) } ;
// Avoid infinite loop if the type is already part of the types
// being visited. It is possible to have "loops in type" because
// C744 does not forbid to use not yet declared type for
// ALLOCATABLE or POINTER components.
for ( const auto & node : componentPath_ ) {
if ( & newTypeSymbol = = & node . GetTypeSymbol ( ) ) {
return nullptr ;
}
2019-07-31 07:19:22 -07:00
}
2019-10-22 16:53:29 -07:00
return derived ;
2019-07-31 07:19:22 -07:00
}
}
2020-03-27 14:17:25 -07:00
} // intrinsic & unlimited polymorphic not traversable
2019-07-26 06:33:48 -07:00
}
2019-10-22 16:53:29 -07:00
return nullptr ;
2019-07-31 07:19:22 -07:00
}
2019-07-26 06:33:48 -07:00
2020-03-27 14:17:25 -07:00
template < ComponentKind componentKind >
2019-07-31 07:19:22 -07:00
static bool StopAtComponentPre ( const Symbol & component ) {
if constexpr ( componentKind = = ComponentKind : : Ordered ) {
// Parent components need to be iterated upon after their
// sub-components in structure constructor analysis.
return ! component . test ( Symbol : : Flag : : ParentComp ) ;
} else if constexpr ( componentKind = = ComponentKind : : Direct ) {
return true ;
} else if constexpr ( componentKind = = ComponentKind : : Ultimate ) {
return component . has < ProcEntityDetails > ( ) | |
2023-08-21 12:21:49 -07:00
IsAllocatableOrObjectPointer ( & component ) | |
2023-09-25 18:53:36 +02:00
( component . has < ObjectEntityDetails > ( ) & &
component . get < ObjectEntityDetails > ( ) . type ( ) & &
2019-07-31 07:19:22 -07:00
component . get < ObjectEntityDetails > ( ) . type ( ) - > AsIntrinsic ( ) ) ;
} else if constexpr ( componentKind = = ComponentKind : : Potential ) {
return ! IsPointer ( component ) ;
2022-11-17 16:30:49 -08:00
} else if constexpr ( componentKind = = ComponentKind : : PotentialAndPointer ) {
return true ;
2019-07-31 07:19:22 -07:00
}
}
2020-03-27 14:17:25 -07:00
template < ComponentKind componentKind >
2019-07-31 07:19:22 -07:00
static bool StopAtComponentPost ( const Symbol & component ) {
2019-10-22 16:53:29 -07:00
return componentKind = = ComponentKind : : Ordered & &
component . test ( Symbol : : Flag : : ParentComp ) ;
2019-07-31 07:19:22 -07:00
}
2019-07-26 06:33:48 -07:00
2020-03-27 14:17:25 -07:00
template < ComponentKind componentKind >
2019-07-31 07:19:22 -07:00
void ComponentIterator < componentKind > : : const_iterator : : Increment ( ) {
2019-10-22 16:53:29 -07:00
while ( ! componentPath_ . empty ( ) ) {
ComponentPathNode & deepest { componentPath_ . back ( ) } ;
if ( deepest . component ( ) ) {
if ( ! deepest . descended ( ) ) {
deepest . set_descended ( true ) ;
if ( const DerivedTypeSpec *
derived { PlanComponentTraversal ( * deepest . component ( ) ) } ) {
componentPath_ . emplace_back ( * derived ) ;
continue ;
2019-07-26 06:33:48 -07:00
}
2019-10-22 16:53:29 -07:00
} else if ( ! deepest . visited ( ) ) {
deepest . set_visited ( true ) ;
2020-03-27 14:17:25 -07:00
return ; // this is the next component to visit, after descending
2019-07-31 07:19:22 -07:00
}
}
2019-10-22 16:53:29 -07:00
auto & nameIterator { deepest . nameIterator ( ) } ;
if ( nameIterator = = deepest . nameEnd ( ) ) {
2019-07-31 07:19:22 -07:00
componentPath_ . pop_back ( ) ;
2019-11-12 15:43:09 -08:00
} else if constexpr ( componentKind = = ComponentKind : : Scope ) {
deepest . set_component ( * nameIterator + + - > second ) ;
deepest . set_descended ( false ) ;
deepest . set_visited ( true ) ;
2020-03-27 14:17:25 -07:00
return ; // this is the next component to visit, before descending
2019-10-22 16:53:29 -07:00
} else {
const Scope & scope { deepest . GetScope ( ) } ;
auto scopeIter { scope . find ( * nameIterator + + ) } ;
if ( scopeIter ! = scope . cend ( ) ) {
const Symbol & component { * scopeIter - > second } ;
deepest . set_component ( component ) ;
deepest . set_descended ( false ) ;
if ( StopAtComponentPre < componentKind > ( component ) ) {
deepest . set_visited ( true ) ;
2020-03-27 14:17:25 -07:00
return ; // this is the next component to visit, before descending
2019-10-22 16:53:29 -07:00
} else {
deepest . set_visited ( ! StopAtComponentPost < componentKind > ( component ) ) ;
}
}
2019-07-31 07:19:22 -07:00
}
}
2019-07-26 06:33:48 -07:00
}
2020-03-27 14:17:25 -07:00
template < ComponentKind componentKind >
2019-07-31 07:19:22 -07:00
std : : string
ComponentIterator < componentKind > : : const_iterator : : BuildResultDesignatorName ( )
const {
2022-08-14 12:52:01 -07:00
std : : string designator ;
2019-07-31 07:19:22 -07:00
for ( const auto & node : componentPath_ ) {
2019-10-22 16:53:29 -07:00
designator + = " % " + DEREF ( node . component ( ) ) . name ( ) . ToString ( ) ;
2019-07-31 07:19:22 -07:00
}
return designator ;
2019-07-26 06:33:48 -07:00
}
2019-07-31 07:19:22 -07:00
template class ComponentIterator < ComponentKind : : Ordered > ;
template class ComponentIterator < ComponentKind : : Direct > ;
template class ComponentIterator < ComponentKind : : Ultimate > ;
template class ComponentIterator < ComponentKind : : Potential > ;
2019-11-12 15:43:09 -08:00
template class ComponentIterator < ComponentKind : : Scope > ;
2022-11-17 16:30:49 -08:00
template class ComponentIterator < ComponentKind : : PotentialAndPointer > ;
2019-07-26 06:33:48 -07:00
2019-07-31 07:19:22 -07:00
UltimateComponentIterator : : const_iterator FindCoarrayUltimateComponent (
2019-07-26 08:11:59 -07:00
const DerivedTypeSpec & derived ) {
2019-07-31 07:19:22 -07:00
UltimateComponentIterator ultimates { derived } ;
2021-11-18 11:48:42 -08:00
return std : : find_if ( ultimates . begin ( ) , ultimates . end ( ) ,
[ ] ( const Symbol & symbol ) { return evaluate : : IsCoarray ( symbol ) ; } ) ;
2019-07-26 08:11:59 -07:00
}
2019-09-13 12:32:43 -07:00
UltimateComponentIterator : : const_iterator FindPointerUltimateComponent (
const DerivedTypeSpec & derived ) {
UltimateComponentIterator ultimates { derived } ;
2019-11-12 15:43:09 -08:00
return std : : find_if ( ultimates . begin ( ) , ultimates . end ( ) , IsPointer ) ;
2019-09-13 12:32:43 -07:00
}
2019-07-31 07:19:22 -07:00
PotentialComponentIterator : : const_iterator FindEventOrLockPotentialComponent (
const DerivedTypeSpec & derived ) {
PotentialComponentIterator potentials { derived } ;
return std : : find_if (
2019-10-22 16:53:29 -07:00
potentials . begin ( ) , potentials . end ( ) , [ ] ( const Symbol & component ) {
if ( const auto * details { component . detailsIf < ObjectEntityDetails > ( ) } ) {
2019-07-31 07:19:22 -07:00
const DeclTypeSpec * type { details - > type ( ) } ;
return type & & IsEventTypeOrLockType ( type - > AsDerived ( ) ) ;
}
return false ;
} ) ;
2019-07-26 06:33:48 -07:00
}
2019-11-12 15:43:09 -08:00
UltimateComponentIterator : : const_iterator FindAllocatableUltimateComponent (
const DerivedTypeSpec & derived ) {
UltimateComponentIterator ultimates { derived } ;
return std : : find_if ( ultimates . begin ( ) , ultimates . end ( ) , IsAllocatable ) ;
}
2022-02-11 09:44:47 -08:00
DirectComponentIterator : : const_iterator FindAllocatableOrPointerDirectComponent (
const DerivedTypeSpec & derived ) {
DirectComponentIterator directs { derived } ;
return std : : find_if ( directs . begin ( ) , directs . end ( ) , IsAllocatableOrPointer ) ;
}
2019-11-12 15:43:09 -08:00
UltimateComponentIterator : : const_iterator
FindPolymorphicAllocatableUltimateComponent ( const DerivedTypeSpec & derived ) {
UltimateComponentIterator ultimates { derived } ;
return std : : find_if (
ultimates . begin ( ) , ultimates . end ( ) , IsPolymorphicAllocatable ) ;
}
2019-07-26 08:11:59 -07:00
const Symbol * FindUltimateComponent ( const DerivedTypeSpec & derived ,
2019-10-17 16:15:20 -07:00
const std : : function < bool ( const Symbol & ) > & predicate ) {
2019-07-31 07:19:22 -07:00
UltimateComponentIterator ultimates { derived } ;
if ( auto it { std : : find_if ( ultimates . begin ( ) , ultimates . end ( ) ,
2019-10-22 16:53:29 -07:00
[ & predicate ] ( const Symbol & component ) - > bool {
return predicate ( component ) ;
2019-07-31 07:19:22 -07:00
} ) } ) {
2019-10-22 16:53:29 -07:00
return & * it ;
2019-07-31 07:19:22 -07:00
}
return nullptr ;
2019-07-26 08:11:59 -07:00
}
2019-10-17 16:15:20 -07:00
const Symbol * FindUltimateComponent ( const Symbol & symbol ,
const std : : function < bool ( const Symbol & ) > & predicate ) {
if ( predicate ( symbol ) ) {
return & symbol ;
} else if ( const auto * object { symbol . detailsIf < ObjectEntityDetails > ( ) } ) {
if ( const auto * type { object - > type ( ) } ) {
if ( const auto * derived { type - > AsDerived ( ) } ) {
return FindUltimateComponent ( * derived , predicate ) ;
}
}
}
return nullptr ;
}
2019-10-17 15:29:26 -07:00
const Symbol * FindImmediateComponent ( const DerivedTypeSpec & type ,
const std : : function < bool ( const Symbol & ) > & predicate ) {
if ( const Scope * scope { type . scope ( ) } ) {
const Symbol * parent { nullptr } ;
for ( const auto & pair : * scope ) {
2019-10-22 16:53:29 -07:00
const Symbol * symbol { & * pair . second } ;
if ( predicate ( * symbol ) ) {
return symbol ;
}
if ( symbol - > test ( Symbol : : Flag : : ParentComp ) ) {
parent = symbol ;
2019-10-17 15:29:26 -07:00
}
}
2019-11-09 09:29:31 -08:00
if ( parent ) {
2019-10-17 15:29:26 -07:00
if ( const auto * object { parent - > detailsIf < ObjectEntityDetails > ( ) } ) {
if ( const auto * type { object - > type ( ) } ) {
if ( const auto * derived { type - > AsDerived ( ) } ) {
return FindImmediateComponent ( * derived , predicate ) ;
}
}
}
}
}
return nullptr ;
}
2022-01-08 13:08:08 -08:00
const Symbol * IsFunctionResultWithSameNameAsFunction ( const Symbol & symbol ) {
2019-08-08 03:46:14 -07:00
if ( IsFunctionResult ( symbol ) ) {
2019-08-07 03:51:13 -07:00
if ( const Symbol * function { symbol . owner ( ) . symbol ( ) } ) {
2022-01-08 13:08:08 -08:00
if ( symbol . name ( ) = = function - > name ( ) ) {
return function ;
}
2019-08-07 03:51:13 -07:00
}
2022-05-16 18:10:27 -07:00
// Check ENTRY result symbols too
const Scope & outer { symbol . owner ( ) . parent ( ) } ;
auto iter { outer . find ( symbol . name ( ) ) } ;
if ( iter ! = outer . end ( ) ) {
const Symbol & outerSym { * iter - > second } ;
if ( const auto * subp { outerSym . detailsIf < SubprogramDetails > ( ) } ) {
if ( subp - > entryScope ( ) = = & symbol . owner ( ) & &
symbol . name ( ) = = outerSym . name ( ) ) {
return & outerSym ;
}
}
}
2019-08-07 03:51:13 -07:00
}
2022-01-08 13:08:08 -08:00
return nullptr ;
2019-08-07 03:51:13 -07:00
}
2019-12-26 05:18:47 +00:00
void LabelEnforce : : Post ( const parser : : GotoStmt & gotoStmt ) {
checkLabelUse ( gotoStmt . v ) ;
}
void LabelEnforce : : Post ( const parser : : ComputedGotoStmt & computedGotoStmt ) {
for ( auto & i : std : : get < std : : list < parser : : Label > > ( computedGotoStmt . t ) ) {
checkLabelUse ( i ) ;
}
}
void LabelEnforce : : Post ( const parser : : ArithmeticIfStmt & arithmeticIfStmt ) {
checkLabelUse ( std : : get < 1 > ( arithmeticIfStmt . t ) ) ;
checkLabelUse ( std : : get < 2 > ( arithmeticIfStmt . t ) ) ;
checkLabelUse ( std : : get < 3 > ( arithmeticIfStmt . t ) ) ;
}
void LabelEnforce : : Post ( const parser : : AssignStmt & assignStmt ) {
checkLabelUse ( std : : get < parser : : Label > ( assignStmt . t ) ) ;
}
void LabelEnforce : : Post ( const parser : : AssignedGotoStmt & assignedGotoStmt ) {
for ( auto & i : std : : get < std : : list < parser : : Label > > ( assignedGotoStmt . t ) ) {
checkLabelUse ( i ) ;
}
}
void LabelEnforce : : Post ( const parser : : AltReturnSpec & altReturnSpec ) {
checkLabelUse ( altReturnSpec . v ) ;
}
void LabelEnforce : : Post ( const parser : : ErrLabel & errLabel ) {
checkLabelUse ( errLabel . v ) ;
}
void LabelEnforce : : Post ( const parser : : EndLabel & endLabel ) {
checkLabelUse ( endLabel . v ) ;
}
void LabelEnforce : : Post ( const parser : : EorLabel & eorLabel ) {
checkLabelUse ( eorLabel . v ) ;
}
void LabelEnforce : : checkLabelUse ( const parser : : Label & labelUsed ) {
if ( labels_ . find ( labelUsed ) = = labels_ . end ( ) ) {
SayWithConstruct ( context_ , currentStatementSourcePosition_ ,
parser : : MessageFormattedText {
" Control flow escapes from %s " _err_en_US , construct_ } ,
constructSourcePosition_ ) ;
}
}
parser : : MessageFormattedText LabelEnforce : : GetEnclosingConstructMsg ( ) {
return { " Enclosing %s statement " _en_US , construct_ } ;
}
void LabelEnforce : : SayWithConstruct ( SemanticsContext & context ,
parser : : CharBlock stmtLocation , parser : : MessageFormattedText & & message ,
parser : : CharBlock constructLocation ) {
context . Say ( stmtLocation , message )
. Attach ( constructLocation , GetEnclosingConstructMsg ( ) ) ;
}
[flang] New implementation for checks for constraints C741 through C750
Summary:
Most of these checks were already implemented, and I just added references to
them to the code and tests. Also, much of this code was already
reviewed in the old flang/f18 GitHub repository, but I didn't get to
merge it before we switched repositories.
I implemented the check for C747 to not allow coarray components in derived
types that are of type C_PTR, C_FUNPTR, or type TEAM_TYPE.
I implemented the check for C748 that requires a data component whose type has
a coarray ultimate component to be a nonpointer, nonallocatable scalar and not
be a coarray.
I implemented the check for C750 that adds additional restrictions to the
bounds expressions of a derived type component that's an array.
These bounds expressions are sepcification expressions as defined in
10.1.11. There was already code in lib/Evaluate/check-expression.cpp to
check semantics for specification expressions, but it did not check for
the extra requirements of C750.
C750 prohibits specification functions, the intrinsic functions
ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF, PRESENT, and SAME_TYPE_AS. It
also requires every specification inquiry reference to be a constant
expression, and requires that the value of the bound not depend on the
value of a variable.
To implement these additional checks, I added code to the intrinsic proc
table to get the intrinsic class of a procedure. I also added an
enumeration to distinguish between specification expressions for
derived type component bounds versus for type parameters. I then
changed the code to pass an enumeration value to
"CheckSpecificationExpr()" to indicate that the expression was a bounds
expression and used this value to determine whether to emit an error
message when violations of C750 are found.
I changed the implementation of IsPureProcedure() to handle statement
functions and changed some references in the code that tested for the
PURE attribute to call IsPureProcedure().
I also fixed some unrelated tests that got new errors when I implemented these
new checks.
Reviewers: tskeith, DavidTruby, sscalpone
Subscribers: jfb, llvm-commits
Tags: #llvm, #flang
Differential Revision: https://reviews.llvm.org/D79263
2020-05-01 13:00:28 -07:00
2020-07-01 17:28:00 -07:00
bool HasAlternateReturns ( const Symbol & subprogram ) {
for ( const auto * dummyArg : subprogram . get < SubprogramDetails > ( ) . dummyArgs ( ) ) {
if ( ! dummyArg ) {
return true ;
}
}
return false ;
}
2023-03-30 10:26:16 -07:00
bool IsAutomaticallyDestroyed ( const Symbol & symbol ) {
return symbol . has < ObjectEntityDetails > ( ) & &
( symbol . owner ( ) . kind ( ) = = Scope : : Kind : : Subprogram | |
symbol . owner ( ) . kind ( ) = = Scope : : Kind : : BlockConstruct ) & &
( ! IsDummy ( symbol ) | | IsIntentOut ( symbol ) ) & & ! IsPointer ( symbol ) & &
! IsSaved ( symbol ) & & ! FindCommonBlockContaining ( symbol ) ;
}
2020-10-06 10:21:06 +05:30
const std : : optional < parser : : Name > & MaybeGetNodeName (
const ConstructNode & construct ) {
2022-03-23 14:05:50 -07:00
return common : : visit (
2020-10-06 10:21:06 +05:30
common : : visitors {
[ & ] ( const parser : : BlockConstruct * blockConstruct )
- > const std : : optional < parser : : Name > & {
return std : : get < 0 > ( blockConstruct - > t ) . statement . v ;
} ,
[ & ] ( const auto * a ) - > const std : : optional < parser : : Name > & {
return std : : get < 0 > ( std : : get < 0 > ( a - > t ) . statement . t ) ;
} ,
} ,
construct ) ;
}
2021-01-29 13:34:22 -08:00
std : : optional < ArraySpec > ToArraySpec (
evaluate : : FoldingContext & context , const evaluate : : Shape & shape ) {
if ( auto extents { evaluate : : AsConstantExtents ( context , shape ) } ) {
ArraySpec result ;
for ( const auto & extent : * extents ) {
result . emplace_back ( ShapeSpec : : MakeExplicit ( Bound { extent } ) ) ;
}
return { std : : move ( result ) } ;
} else {
return std : : nullopt ;
}
}
std : : optional < ArraySpec > ToArraySpec ( evaluate : : FoldingContext & context ,
const std : : optional < evaluate : : Shape > & shape ) {
return shape ? ToArraySpec ( context , * shape ) : std : : nullopt ;
}
2023-03-10 15:06:01 -08:00
static const DeclTypeSpec * GetDtvArgTypeSpec ( const Symbol & proc ) {
if ( const auto * subp { proc . detailsIf < SubprogramDetails > ( ) } ;
subp & & ! subp - > dummyArgs ( ) . empty ( ) ) {
if ( const auto * arg { subp - > dummyArgs ( ) [ 0 ] } ) {
return arg - > GetType ( ) ;
}
}
return nullptr ;
}
const DerivedTypeSpec * GetDtvArgDerivedType ( const Symbol & proc ) {
if ( const auto * type { GetDtvArgTypeSpec ( proc ) } ) {
return type - > AsDerived ( ) ;
} else {
return nullptr ;
}
}
2023-04-13 10:28:19 -07:00
bool HasDefinedIo ( common : : DefinedIo which , const DerivedTypeSpec & derived ,
2022-02-11 09:44:47 -08:00
const Scope * scope ) {
if ( const Scope * dtScope { derived . scope ( ) } ) {
for ( const auto & pair : * dtScope ) {
const Symbol & symbol { * pair . second } ;
if ( const auto * generic { symbol . detailsIf < GenericDetails > ( ) } ) {
GenericKind kind { generic - > kind ( ) } ;
2023-04-13 10:28:19 -07:00
if ( const auto * io { std : : get_if < common : : DefinedIo > ( & kind . u ) } ) {
2022-02-11 09:44:47 -08:00
if ( * io = = which ) {
return true ; // type-bound GENERIC exists
}
}
}
}
}
if ( scope ) {
SourceName name { GenericKind : : AsFortran ( which ) } ;
evaluate : : DynamicType dyDerived { derived } ;
for ( ; scope & & ! scope - > IsGlobal ( ) ; scope = & scope - > parent ( ) ) {
auto iter { scope - > find ( name ) } ;
if ( iter ! = scope - > end ( ) ) {
const auto & generic { iter - > second - > GetUltimate ( ) . get < GenericDetails > ( ) } ;
for ( auto ref : generic . specificProcs ( ) ) {
const Symbol & procSym { ref - > GetUltimate ( ) } ;
2023-03-10 15:06:01 -08:00
if ( const DeclTypeSpec * dtSpec { GetDtvArgTypeSpec ( procSym ) } ) {
if ( auto dyDummy { evaluate : : DynamicType : : From ( * dtSpec ) } ) {
if ( dyDummy - > IsTkCompatibleWith ( dyDerived ) ) {
return true ; // GENERIC or INTERFACE not in type
2022-02-11 09:44:47 -08:00
}
}
}
}
}
}
}
return false ;
}
2023-06-29 17:32:00 -07:00
void WarnOnDeferredLengthCharacterScalar ( SemanticsContext & context ,
const SomeExpr * expr , parser : : CharBlock at , const char * what ) {
if ( context . languageFeatures ( ) . ShouldWarn (
common : : UsageWarning : : F202XAllocatableBreakingChange ) ) {
if ( const Symbol *
symbol { evaluate : : UnwrapWholeSymbolOrComponentDataRef ( expr ) } ) {
const Symbol & ultimate { ResolveAssociations ( * symbol ) } ;
if ( const DeclTypeSpec * type { ultimate . GetType ( ) } ; type & &
type - > category ( ) = = DeclTypeSpec : : Category : : Character & &
type - > characterTypeSpec ( ) . length ( ) . isDeferred ( ) & &
IsAllocatable ( ultimate ) & & ultimate . Rank ( ) = = 0 ) {
context . Say ( at ,
" The deferred length allocatable character scalar variable '%s' may be reallocated to a different length under the new Fortran 202X standard semantics for %s " _port_en_US ,
symbol - > name ( ) , what ) ;
}
}
}
}
2023-07-17 09:38:55 -07:00
bool CouldBeDataPointerValuedFunction ( const Symbol * original ) {
if ( original ) {
const Symbol & ultimate { original - > GetUltimate ( ) } ;
if ( const Symbol * result { FindFunctionResult ( ultimate ) } ) {
return IsPointer ( * result ) & & ! IsProcedure ( * result ) ;
}
if ( const auto * generic { ultimate . detailsIf < GenericDetails > ( ) } ) {
for ( const SymbolRef & ref : generic - > specificProcs ( ) ) {
if ( CouldBeDataPointerValuedFunction ( & * ref ) ) {
return true ;
}
}
}
}
return false ;
}
2023-08-16 12:08:28 -07:00
std : : string GetModuleOrSubmoduleName ( const Symbol & symbol ) {
const auto & details { symbol . get < ModuleDetails > ( ) } ;
std : : string result { symbol . name ( ) . ToString ( ) } ;
if ( details . ancestor ( ) & & details . ancestor ( ) - > symbol ( ) ) {
result = details . ancestor ( ) - > symbol ( ) - > name ( ) . ToString ( ) + ' : ' + result ;
}
return result ;
}
2023-09-08 10:43:55 +02:00
std : : string GetCommonBlockObjectName ( const Symbol & common , bool underscoring ) {
if ( const std : : string * bind { common . GetBindName ( ) } ) {
return * bind ;
}
if ( common . name ( ) . empty ( ) ) {
return Fortran : : common : : blankCommonObjectName ;
}
return underscoring ? common . name ( ) . ToString ( ) + " _ " s
: common . name ( ) . ToString ( ) ;
}
2024-01-25 16:51:30 -08:00
bool HadUseError (
SemanticsContext & context , SourceName at , const Symbol * symbol ) {
if ( const auto * details {
symbol ? symbol - > detailsIf < UseErrorDetails > ( ) : nullptr } ) {
auto & msg { context . Say (
at , " Reference to '%s' is ambiguous " _err_en_US , symbol - > name ( ) ) } ;
for ( const auto & [ location , module ] : details - > occurrences ( ) ) {
msg . Attach ( location , " '%s' was use-associated from module '%s' " _en_US , at ,
module - > GetName ( ) . value ( ) ) ;
}
context . SetError ( * symbol ) ;
return true ;
} else {
return false ;
}
}
2020-03-27 14:17:25 -07:00
} // namespace Fortran::semantics