Skip to content

Commit 672eb0e

Browse files
committed
Address reviewer comments. Add test to check declare mapper export to .mod file.
1 parent 6e23352 commit 672eb0e

File tree

4 files changed

+76
-49
lines changed

4 files changed

+76
-49
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4261,6 +4261,14 @@ void Fortran::lower::materializeOpenMPDeclareMappers(
42614261
if (!root.IsModule())
42624262
return;
42634263

4264+
// Only materialize for modules coming from mod files to avoid duplicates.
4265+
if (const semantics::Symbol *modSym = root.symbol()) {
4266+
if (!modSym->test(semantics::Symbol::Flag::ModFile))
4267+
return;
4268+
} else {
4269+
return;
4270+
}
4271+
42644272
// Scan symbols in this module scope for MapperDetails.
42654273
for (auto &it : root) {
42664274
const semantics::Symbol &sym = *it.second;

flang/lib/Semantics/resolve-names.cpp

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,7 @@ void AttrsVisitor::SetBindNameOn(Symbol &symbol) {
23812381
}
23822382
symbol.SetBindName(std::move(*label));
23832383
if (!oldBindName.empty()) {
2384-
if (const std::string *newBindName{symbol.GetBindName()}) {
2384+
if (const std::string * newBindName{symbol.GetBindName()}) {
23852385
if (oldBindName != *newBindName) {
23862386
Say(symbol.name(),
23872387
"The entity '%s' has multiple BIND names ('%s' and '%s')"_err_en_US,
@@ -2507,15 +2507,15 @@ void DeclTypeSpecVisitor::Post(const parser::TypeSpec &typeSpec) {
25072507
// expression semantics if the DeclTypeSpec is a valid TypeSpec.
25082508
// The grammar ensures that it's an intrinsic or derived type spec,
25092509
// not TYPE(*) or CLASS(*) or CLASS(T).
2510-
if (const DeclTypeSpec *spec{state_.declTypeSpec}) {
2510+
if (const DeclTypeSpec * spec{state_.declTypeSpec}) {
25112511
switch (spec->category()) {
25122512
case DeclTypeSpec::Numeric:
25132513
case DeclTypeSpec::Logical:
25142514
case DeclTypeSpec::Character:
25152515
typeSpec.declTypeSpec = spec;
25162516
break;
25172517
case DeclTypeSpec::TypeDerived:
2518-
if (const DerivedTypeSpec *derived{spec->AsDerived()}) {
2518+
if (const DerivedTypeSpec * derived{spec->AsDerived()}) {
25192519
CheckForAbstractType(derived->typeSymbol()); // C703
25202520
typeSpec.declTypeSpec = spec;
25212521
}
@@ -3106,8 +3106,8 @@ Symbol &ScopeHandler::MakeSymbol(const parser::Name &name, Attrs attrs) {
31063106
Symbol &ScopeHandler::MakeHostAssocSymbol(
31073107
const parser::Name &name, const Symbol &hostSymbol) {
31083108
Symbol &symbol{*NonDerivedTypeScope()
3109-
.try_emplace(name.source, HostAssocDetails{hostSymbol})
3110-
.first->second};
3109+
.try_emplace(name.source, HostAssocDetails{hostSymbol})
3110+
.first->second};
31113111
name.symbol = &symbol;
31123112
symbol.attrs() = hostSymbol.attrs(); // TODO: except PRIVATE, PUBLIC?
31133113
// These attributes can be redundantly reapplied without error
@@ -3195,7 +3195,7 @@ void ScopeHandler::ApplyImplicitRules(
31953195
if (context().HasError(symbol) || !NeedsType(symbol)) {
31963196
return;
31973197
}
3198-
if (const DeclTypeSpec *type{GetImplicitType(symbol)}) {
3198+
if (const DeclTypeSpec * type{GetImplicitType(symbol)}) {
31993199
if (!skipImplicitTyping_) {
32003200
symbol.set(Symbol::Flag::Implicit);
32013201
symbol.SetType(*type);
@@ -3295,7 +3295,7 @@ const DeclTypeSpec *ScopeHandler::GetImplicitType(
32953295
const auto *type{implicitRulesMap_->at(scope).GetType(
32963296
symbol.name(), respectImplicitNoneType)};
32973297
if (type) {
3298-
if (const DerivedTypeSpec *derived{type->AsDerived()}) {
3298+
if (const DerivedTypeSpec * derived{type->AsDerived()}) {
32993299
// Resolve any forward-referenced derived type; a quick no-op else.
33003300
auto &instantiatable{*const_cast<DerivedTypeSpec *>(derived)};
33013301
instantiatable.Instantiate(currScope());
@@ -4320,7 +4320,7 @@ Scope *ModuleVisitor::FindModule(const parser::Name &name,
43204320
if (scope) {
43214321
if (DoesScopeContain(scope, currScope())) { // 14.2.2(1)
43224322
std::optional<SourceName> submoduleName;
4323-
if (const Scope *container{FindModuleOrSubmoduleContaining(currScope())};
4323+
if (const Scope * container{FindModuleOrSubmoduleContaining(currScope())};
43244324
container && container->IsSubmodule()) {
43254325
submoduleName = container->GetName();
43264326
}
@@ -4425,7 +4425,7 @@ bool InterfaceVisitor::isAbstract() const {
44254425

44264426
void InterfaceVisitor::AddSpecificProcs(
44274427
const std::list<parser::Name> &names, ProcedureKind kind) {
4428-
if (Symbol *symbol{GetGenericInfo().symbol};
4428+
if (Symbol * symbol{GetGenericInfo().symbol};
44294429
symbol && symbol->has<GenericDetails>()) {
44304430
for (const auto &name : names) {
44314431
specificsForGenericProcs_.emplace(symbol, std::make_pair(&name, kind));
@@ -4525,7 +4525,7 @@ void GenericHandler::DeclaredPossibleSpecificProc(Symbol &proc) {
45254525
}
45264526

45274527
void InterfaceVisitor::ResolveNewSpecifics() {
4528-
if (Symbol *generic{genericInfo_.top().symbol};
4528+
if (Symbol * generic{genericInfo_.top().symbol};
45294529
generic && generic->has<GenericDetails>()) {
45304530
ResolveSpecificsInGeneric(*generic, false);
45314531
}
@@ -4610,7 +4610,7 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
46104610
name.source);
46114611
MakeSymbol(name, Attrs{}, UnknownDetails{});
46124612
} else if (auto *entity{ultimate.detailsIf<EntityDetails>()};
4613-
entity && !ultimate.has<ProcEntityDetails>()) {
4613+
entity && !ultimate.has<ProcEntityDetails>()) {
46144614
resultType = entity->type();
46154615
ultimate.details() = UnknownDetails{}; // will be replaced below
46164616
} else {
@@ -4669,7 +4669,7 @@ bool SubprogramVisitor::Pre(const parser::Suffix &suffix) {
46694669
} else {
46704670
Message &msg{Say(*suffix.resultName,
46714671
"RESULT(%s) may appear only in a function"_err_en_US)};
4672-
if (const Symbol *subprogram{InclusiveScope().symbol()}) {
4672+
if (const Symbol * subprogram{InclusiveScope().symbol()}) {
46734673
msg.Attach(subprogram->name(), "Containing subprogram"_en_US);
46744674
}
46754675
}
@@ -5185,7 +5185,7 @@ Symbol *ScopeHandler::FindSeparateModuleProcedureInterface(
51855185
symbol = generic->specific();
51865186
}
51875187
}
5188-
if (const Symbol *defnIface{FindSeparateModuleSubprogramInterface(symbol)}) {
5188+
if (const Symbol * defnIface{FindSeparateModuleSubprogramInterface(symbol)}) {
51895189
// Error recovery in case of multiple definitions
51905190
symbol = const_cast<Symbol *>(defnIface);
51915191
}
@@ -5324,8 +5324,8 @@ bool SubprogramVisitor::HandlePreviousCalls(
53245324
return generic->specific() &&
53255325
HandlePreviousCalls(name, *generic->specific(), subpFlag);
53265326
} else if (const auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
5327-
!proc->isDummy() &&
5328-
!symbol.attrs().HasAny(Attrs{Attr::INTRINSIC, Attr::POINTER})) {
5327+
!proc->isDummy() &&
5328+
!symbol.attrs().HasAny(Attrs{Attr::INTRINSIC, Attr::POINTER})) {
53295329
// There's a symbol created for previous calls to this subprogram or
53305330
// ENTRY's name. We have to replace that symbol in situ to avoid the
53315331
// obligation to rewrite symbol pointers in the parse tree.
@@ -5367,7 +5367,7 @@ const Symbol *SubprogramVisitor::CheckExtantProc(
53675367
if (prev) {
53685368
if (IsDummy(*prev)) {
53695369
} else if (auto *entity{prev->detailsIf<EntityDetails>()};
5370-
IsPointer(*prev) && entity && !entity->type()) {
5370+
IsPointer(*prev) && entity && !entity->type()) {
53715371
// POINTER attribute set before interface
53725372
} else if (inInterfaceBlock() && currScope() != prev->owner()) {
53735373
// Procedures in an INTERFACE block do not resolve to symbols
@@ -5439,7 +5439,7 @@ Symbol *SubprogramVisitor::PushSubprogramScope(const parser::Name &name,
54395439
}
54405440
set_inheritFromParent(false); // interfaces don't inherit, even if MODULE
54415441
}
5442-
if (Symbol *found{FindSymbol(name)};
5442+
if (Symbol * found{FindSymbol(name)};
54435443
found && found->has<HostAssocDetails>()) {
54445444
found->set(subpFlag); // PushScope() created symbol
54455445
}
@@ -6290,9 +6290,9 @@ void DeclarationVisitor::Post(const parser::VectorTypeSpec &x) {
62906290
vectorDerivedType.CookParameters(GetFoldingContext());
62916291
}
62926292

6293-
if (const DeclTypeSpec *extant{
6294-
ppcBuiltinTypesScope->FindInstantiatedDerivedType(
6295-
vectorDerivedType, DeclTypeSpec::Category::TypeDerived)}) {
6293+
if (const DeclTypeSpec *
6294+
extant{ppcBuiltinTypesScope->FindInstantiatedDerivedType(
6295+
vectorDerivedType, DeclTypeSpec::Category::TypeDerived)}) {
62966296
// This derived type and parameter expressions (if any) are already present
62976297
// in the __ppc_intrinsics scope.
62986298
SetDeclTypeSpec(*extant);
@@ -6314,7 +6314,7 @@ bool DeclarationVisitor::Pre(const parser::DeclarationTypeSpec::Type &) {
63146314

63156315
void DeclarationVisitor::Post(const parser::DeclarationTypeSpec::Type &type) {
63166316
const parser::Name &derivedName{std::get<parser::Name>(type.derived.t)};
6317-
if (const Symbol *derivedSymbol{derivedName.symbol}) {
6317+
if (const Symbol * derivedSymbol{derivedName.symbol}) {
63186318
CheckForAbstractType(*derivedSymbol); // C706
63196319
}
63206320
}
@@ -6383,8 +6383,8 @@ void DeclarationVisitor::Post(const parser::DerivedTypeSpec &x) {
63836383
if (!spec->MightBeParameterized()) {
63846384
spec->EvaluateParameters(context());
63856385
}
6386-
if (const DeclTypeSpec *extant{
6387-
currScope().FindInstantiatedDerivedType(*spec, category)}) {
6386+
if (const DeclTypeSpec *
6387+
extant{currScope().FindInstantiatedDerivedType(*spec, category)}) {
63886388
// This derived type and parameter expressions (if any) are already present
63896389
// in this scope.
63906390
SetDeclTypeSpec(*extant);
@@ -6415,7 +6415,8 @@ void DeclarationVisitor::Post(const parser::DeclarationTypeSpec::Record &rec) {
64156415
if (auto spec{ResolveDerivedType(typeName)}) {
64166416
spec->CookParameters(GetFoldingContext());
64176417
spec->EvaluateParameters(context());
6418-
if (const DeclTypeSpec *extant{currScope().FindInstantiatedDerivedType(
6418+
if (const DeclTypeSpec *
6419+
extant{currScope().FindInstantiatedDerivedType(
64196420
*spec, DeclTypeSpec::TypeDerived)}) {
64206421
SetDeclTypeSpec(*extant);
64216422
} else {
@@ -7426,7 +7427,7 @@ bool DeclarationVisitor::PassesLocalityChecks(
74267427
"Coarray '%s' not allowed in a %s locality-spec"_err_en_US, specName);
74277428
return false;
74287429
}
7429-
if (const DeclTypeSpec *type{symbol.GetType()}) {
7430+
if (const DeclTypeSpec * type{symbol.GetType()}) {
74307431
if (type->IsPolymorphic() && IsDummy(symbol) && !IsPointer(symbol) &&
74317432
!isReduce) { // F'2023 C1130
74327433
SayWithDecl(name, symbol,
@@ -7653,7 +7654,7 @@ Symbol *DeclarationVisitor::NoteInterfaceName(const parser::Name &name) {
76537654
}
76547655

76557656
void DeclarationVisitor::CheckExplicitInterface(const parser::Name &name) {
7656-
if (const Symbol *symbol{name.symbol}) {
7657+
if (const Symbol * symbol{name.symbol}) {
76577658
const Symbol &ultimate{symbol->GetUltimate()};
76587659
if (!context().HasError(*symbol) && !context().HasError(ultimate) &&
76597660
!BypassGeneric(ultimate).HasExplicitInterface()) {
@@ -7972,7 +7973,7 @@ bool ConstructVisitor::Pre(const parser::DataStmtValue &x) {
79727973
auto &mutableData{const_cast<parser::DataStmtConstant &>(data)};
79737974
if (auto *elem{parser::Unwrap<parser::ArrayElement>(mutableData)}) {
79747975
if (const auto *name{std::get_if<parser::Name>(&elem->base.u)}) {
7975-
if (const Symbol *symbol{FindSymbol(*name)};
7976+
if (const Symbol * symbol{FindSymbol(*name)};
79767977
symbol && symbol->GetUltimate().has<DerivedTypeDetails>()) {
79777978
mutableData.u = elem->ConvertToStructureConstructor(
79787979
DerivedTypeSpec{name->source, *symbol});
@@ -8118,15 +8119,15 @@ void ConstructVisitor::Post(const parser::SelectTypeStmt &x) {
81188119
}
81198120
}
81208121
} else {
8121-
if (const Symbol *whole{
8122-
UnwrapWholeSymbolDataRef(association.selector.expr)}) {
8122+
if (const Symbol *
8123+
whole{UnwrapWholeSymbolDataRef(association.selector.expr)}) {
81238124
ConvertToObjectEntity(const_cast<Symbol &>(*whole));
81248125
if (!IsVariableName(*whole)) {
81258126
Say(association.selector.source, // C901
81268127
"Selector is not a variable"_err_en_US);
81278128
association = {};
81288129
}
8129-
if (const DeclTypeSpec *type{whole->GetType()}) {
8130+
if (const DeclTypeSpec * type{whole->GetType()}) {
81308131
if (!type->IsPolymorphic()) { // C1159
81318132
Say(association.selector.source,
81328133
"Selector '%s' in SELECT TYPE statement must be "
@@ -8266,8 +8267,8 @@ Symbol *ConstructVisitor::MakeAssocEntity() {
82668267
"The associate name '%s' is already used in this associate statement"_err_en_US);
82678268
return nullptr;
82688269
}
8269-
} else if (const Symbol *whole{
8270-
UnwrapWholeSymbolDataRef(association.selector.expr)}) {
8270+
} else if (const Symbol *
8271+
whole{UnwrapWholeSymbolDataRef(association.selector.expr)}) {
82718272
symbol = &MakeSymbol(whole->name());
82728273
} else {
82738274
return nullptr;
@@ -8887,7 +8888,7 @@ bool DeclarationVisitor::CheckForHostAssociatedImplicit(
88878888
if (name.symbol) {
88888889
ApplyImplicitRules(*name.symbol, true);
88898890
}
8890-
if (Scope *host{GetHostProcedure()}; host && !isImplicitNoneType(*host)) {
8891+
if (Scope * host{GetHostProcedure()}; host && !isImplicitNoneType(*host)) {
88918892
Symbol *hostSymbol{nullptr};
88928893
if (!name.symbol) {
88938894
if (currScope().CanImport(name.source)) {
@@ -8958,7 +8959,7 @@ const parser::Name *DeclarationVisitor::FindComponent(
89588959
if (!type) {
89598960
return nullptr; // should have already reported error
89608961
}
8961-
if (const IntrinsicTypeSpec *intrinsic{type->AsIntrinsic()}) {
8962+
if (const IntrinsicTypeSpec * intrinsic{type->AsIntrinsic()}) {
89628963
auto category{intrinsic->category()};
89638964
MiscDetails::Kind miscKind{MiscDetails::Kind::None};
89648965
if (component.source == "kind") {
@@ -8980,7 +8981,7 @@ const parser::Name *DeclarationVisitor::FindComponent(
89808981
}
89818982
} else if (DerivedTypeSpec * derived{type->AsDerived()}) {
89828983
derived->Instantiate(currScope()); // in case of forward referenced type
8983-
if (const Scope *scope{derived->scope()}) {
8984+
if (const Scope * scope{derived->scope()}) {
89848985
if (Resolve(component, scope->FindComponent(component.source))) {
89858986
if (auto msg{CheckAccessibleSymbol(currScope(), *component.symbol)}) {
89868987
context().Say(component.source, *msg);
@@ -9131,8 +9132,8 @@ void DeclarationVisitor::PointerInitialization(
91319132
if (evaluate::IsNullProcedurePointer(&*expr)) {
91329133
CHECK(!details->init());
91339134
details->set_init(nullptr);
9134-
} else if (const Symbol *targetSymbol{
9135-
evaluate::UnwrapWholeSymbolDataRef(*expr)}) {
9135+
} else if (const Symbol *
9136+
targetSymbol{evaluate::UnwrapWholeSymbolDataRef(*expr)}) {
91369137
CHECK(!details->init());
91379138
details->set_init(*targetSymbol);
91389139
} else {
@@ -9701,7 +9702,7 @@ void ResolveNamesVisitor::EarlyDummyTypeDeclaration(
97019702
for (const auto &ent : entities) {
97029703
const auto &objName{std::get<parser::ObjectName>(ent.t)};
97039704
Resolve(objName, FindInScope(currScope(), objName));
9704-
if (Symbol *symbol{objName.symbol};
9705+
if (Symbol * symbol{objName.symbol};
97059706
symbol && IsDummy(*symbol) && NeedsType(*symbol)) {
97069707
if (!type) {
97079708
type = ProcessTypeSpec(declTypeSpec);
@@ -9840,7 +9841,7 @@ void ResolveNamesVisitor::FinishSpecificationPart(
98409841
if (auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
98419842
!proc->isDummy() && !IsPointer(symbol) &&
98429843
!symbol.attrs().test(Attr::BIND_C)) {
9843-
if (const Symbol *iface{proc->procInterface()};
9844+
if (const Symbol * iface{proc->procInterface()};
98449845
iface && IsBindCProcedure(*iface)) {
98459846
SetImplicitAttr(symbol, Attr::BIND_C);
98469847
SetBindNameOn(symbol);
@@ -9973,7 +9974,7 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
99739974
Symbol *ptrSymbol{parser::GetLastName(dataRef).symbol};
99749975
Walk(bounds);
99759976
// Resolve unrestricted specific intrinsic procedures as in "p => cos".
9976-
if (const parser::Name *name{parser::Unwrap<parser::Name>(expr)}) {
9977+
if (const parser::Name * name{parser::Unwrap<parser::Name>(expr)}) {
99779978
if (NameIsKnownOrIntrinsic(*name)) {
99789979
if (Symbol * symbol{name->symbol}) {
99799980
if (IsProcedurePointer(ptrSymbol) &&
@@ -10420,8 +10421,8 @@ void ResolveNamesVisitor::ResolveSpecificationParts(ProgramTree &node) {
1042010421
// implied SAVE so that evaluate::IsSaved() will return true.
1042110422
if (node.scope()->kind() == Scope::Kind::MainProgram) {
1042210423
if (const auto *object{symbol.detailsIf<ObjectEntityDetails>()}) {
10423-
if (const DeclTypeSpec *type{object->type()}) {
10424-
if (const DerivedTypeSpec *derived{type->AsDerived()}) {
10424+
if (const DeclTypeSpec * type{object->type()}) {
10425+
if (const DerivedTypeSpec * derived{type->AsDerived()}) {
1042510426
if (!IsSaved(symbol) && FindCoarrayPotentialComponent(*derived)) {
1042610427
SetImplicitAttr(symbol, Attr::SAVE);
1042710428
}
@@ -10678,7 +10679,7 @@ void ResolveNamesVisitor::FinishDerivedTypeInstantiation(Scope &scope) {
1067810679
if (DerivedTypeSpec * spec{scope.derivedTypeSpec()}) {
1067910680
spec->Instantiate(currScope());
1068010681
const Symbol &origTypeSymbol{spec->typeSymbol()};
10681-
if (const Scope *origTypeScope{origTypeSymbol.scope()}) {
10682+
if (const Scope * origTypeScope{origTypeSymbol.scope()}) {
1068210683
CHECK(origTypeScope->IsDerivedType() &&
1068310684
origTypeScope->symbol() == &origTypeSymbol);
1068410685
auto &foldingContext{GetFoldingContext()};
@@ -10689,7 +10690,7 @@ void ResolveNamesVisitor::FinishDerivedTypeInstantiation(Scope &scope) {
1068910690
if (IsPointer(comp)) {
1069010691
if (auto *details{comp.detailsIf<ObjectEntityDetails>()}) {
1069110692
auto origDetails{origComp.get<ObjectEntityDetails>()};
10692-
if (const MaybeExpr &init{origDetails.init()}) {
10693+
if (const MaybeExpr & init{origDetails.init()}) {
1069310694
SomeExpr newInit{*init};
1069410695
MaybeExpr folded{FoldExpr(std::move(newInit))};
1069510696
details->set_init(std::move(folded));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
! RUN: split-file %s %t
2+
! RUN: %flang_fc1 -fsyntax-only -fopenmp -fopenmp-version=50 -module-dir %t %t/m.f90
3+
! RUN: cat %t/m.mod | FileCheck --ignore-case %s
4+
5+
!--- m.f90
6+
module m
7+
implicit none
8+
type :: t
9+
integer :: x
10+
end type t
11+
!$omp declare mapper(mymap : t :: v) map(v%x)
12+
end module m
13+
14+
!CHECK: !$OMP DECLARE MAPPER(mymap:t::v) MAP(v%x)

flang/test/Semantics/OpenMP/map-clause-symbols.f90

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
! RUN: not %flang_fc1 -fopenmp -fopenmp-version=50 %s 2>&1 | FileCheck %s
1+
! RUN: %flang_fc1 -fdebug-dump-symbols -fopenmp -fopenmp-version=50 %s | FileCheck %s
22
program main
3+
!CHECK-LABEL: MainProgram scope: MAIN
4+
type ty
5+
real(4) :: x
6+
end type ty
7+
!$omp declare mapper(xx : ty :: v) map(v)
38
integer, parameter :: n = 256
4-
real(8) :: a(256)
9+
type(ty) :: a(256)
510
!$omp target map(mapper(xx), from:a)
611
do i=1,n
7-
a(i) = 4.2
12+
a(i)%x = 4.2
813
end do
914
!$omp end target
15+
!CHECK: xx: MapperDetails
1016
end program main
11-
12-
! CHECK: error: '{{.*}}' not declared

0 commit comments

Comments
 (0)