Skip to content

Commit a941777

Browse files
committed
Address reviewer comments. Add test to check declare mapper export to .mod file.
1 parent 0298b81 commit a941777

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
@@ -4271,6 +4271,14 @@ void Fortran::lower::materializeOpenMPDeclareMappers(
42714271
if (!root.IsModule())
42724272
return;
42734273

4274+
// Only materialize for modules coming from mod files to avoid duplicates.
4275+
if (const semantics::Symbol *modSym = root.symbol()) {
4276+
if (!modSym->test(semantics::Symbol::Flag::ModFile))
4277+
return;
4278+
} else {
4279+
return;
4280+
}
4281+
42744282
// Scan symbols in this module scope for MapperDetails.
42754283
for (auto &it : root) {
42764284
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
@@ -2384,7 +2384,7 @@ void AttrsVisitor::SetBindNameOn(Symbol &symbol) {
23842384
}
23852385
symbol.SetBindName(std::move(*label));
23862386
if (!oldBindName.empty()) {
2387-
if (const std::string *newBindName{symbol.GetBindName()}) {
2387+
if (const std::string * newBindName{symbol.GetBindName()}) {
23882388
if (oldBindName != *newBindName) {
23892389
Say(symbol.name(),
23902390
"The entity '%s' has multiple BIND names ('%s' and '%s')"_err_en_US,
@@ -2510,15 +2510,15 @@ void DeclTypeSpecVisitor::Post(const parser::TypeSpec &typeSpec) {
25102510
// expression semantics if the DeclTypeSpec is a valid TypeSpec.
25112511
// The grammar ensures that it's an intrinsic or derived type spec,
25122512
// not TYPE(*) or CLASS(*) or CLASS(T).
2513-
if (const DeclTypeSpec *spec{state_.declTypeSpec}) {
2513+
if (const DeclTypeSpec * spec{state_.declTypeSpec}) {
25142514
switch (spec->category()) {
25152515
case DeclTypeSpec::Numeric:
25162516
case DeclTypeSpec::Logical:
25172517
case DeclTypeSpec::Character:
25182518
typeSpec.declTypeSpec = spec;
25192519
break;
25202520
case DeclTypeSpec::TypeDerived:
2521-
if (const DerivedTypeSpec *derived{spec->AsDerived()}) {
2521+
if (const DerivedTypeSpec * derived{spec->AsDerived()}) {
25222522
CheckForAbstractType(derived->typeSymbol()); // C703
25232523
typeSpec.declTypeSpec = spec;
25242524
}
@@ -3109,8 +3109,8 @@ Symbol &ScopeHandler::MakeSymbol(const parser::Name &name, Attrs attrs) {
31093109
Symbol &ScopeHandler::MakeHostAssocSymbol(
31103110
const parser::Name &name, const Symbol &hostSymbol) {
31113111
Symbol &symbol{*NonDerivedTypeScope()
3112-
.try_emplace(name.source, HostAssocDetails{hostSymbol})
3113-
.first->second};
3112+
.try_emplace(name.source, HostAssocDetails{hostSymbol})
3113+
.first->second};
31143114
name.symbol = &symbol;
31153115
symbol.attrs() = hostSymbol.attrs(); // TODO: except PRIVATE, PUBLIC?
31163116
// These attributes can be redundantly reapplied without error
@@ -3198,7 +3198,7 @@ void ScopeHandler::ApplyImplicitRules(
31983198
if (context().HasError(symbol) || !NeedsType(symbol)) {
31993199
return;
32003200
}
3201-
if (const DeclTypeSpec *type{GetImplicitType(symbol)}) {
3201+
if (const DeclTypeSpec * type{GetImplicitType(symbol)}) {
32023202
if (!skipImplicitTyping_) {
32033203
symbol.set(Symbol::Flag::Implicit);
32043204
symbol.SetType(*type);
@@ -3298,7 +3298,7 @@ const DeclTypeSpec *ScopeHandler::GetImplicitType(
32983298
const auto *type{implicitRulesMap_->at(scope).GetType(
32993299
symbol.name(), respectImplicitNoneType)};
33003300
if (type) {
3301-
if (const DerivedTypeSpec *derived{type->AsDerived()}) {
3301+
if (const DerivedTypeSpec * derived{type->AsDerived()}) {
33023302
// Resolve any forward-referenced derived type; a quick no-op else.
33033303
auto &instantiatable{*const_cast<DerivedTypeSpec *>(derived)};
33043304
instantiatable.Instantiate(currScope());
@@ -4309,7 +4309,7 @@ Scope *ModuleVisitor::FindModule(const parser::Name &name,
43094309
if (scope) {
43104310
if (DoesScopeContain(scope, currScope())) { // 14.2.2(1)
43114311
std::optional<SourceName> submoduleName;
4312-
if (const Scope *container{FindModuleOrSubmoduleContaining(currScope())};
4312+
if (const Scope * container{FindModuleOrSubmoduleContaining(currScope())};
43134313
container && container->IsSubmodule()) {
43144314
submoduleName = container->GetName();
43154315
}
@@ -4414,7 +4414,7 @@ bool InterfaceVisitor::isAbstract() const {
44144414

44154415
void InterfaceVisitor::AddSpecificProcs(
44164416
const std::list<parser::Name> &names, ProcedureKind kind) {
4417-
if (Symbol *symbol{GetGenericInfo().symbol};
4417+
if (Symbol * symbol{GetGenericInfo().symbol};
44184418
symbol && symbol->has<GenericDetails>()) {
44194419
for (const auto &name : names) {
44204420
specificsForGenericProcs_.emplace(symbol, std::make_pair(&name, kind));
@@ -4514,7 +4514,7 @@ void GenericHandler::DeclaredPossibleSpecificProc(Symbol &proc) {
45144514
}
45154515

45164516
void InterfaceVisitor::ResolveNewSpecifics() {
4517-
if (Symbol *generic{genericInfo_.top().symbol};
4517+
if (Symbol * generic{genericInfo_.top().symbol};
45184518
generic && generic->has<GenericDetails>()) {
45194519
ResolveSpecificsInGeneric(*generic, false);
45204520
}
@@ -4599,7 +4599,7 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
45994599
name.source);
46004600
MakeSymbol(name, Attrs{}, UnknownDetails{});
46014601
} else if (auto *entity{ultimate.detailsIf<EntityDetails>()};
4602-
entity && !ultimate.has<ProcEntityDetails>()) {
4602+
entity && !ultimate.has<ProcEntityDetails>()) {
46034603
resultType = entity->type();
46044604
ultimate.details() = UnknownDetails{}; // will be replaced below
46054605
} else {
@@ -4658,7 +4658,7 @@ bool SubprogramVisitor::Pre(const parser::Suffix &suffix) {
46584658
} else {
46594659
Message &msg{Say(*suffix.resultName,
46604660
"RESULT(%s) may appear only in a function"_err_en_US)};
4661-
if (const Symbol *subprogram{InclusiveScope().symbol()}) {
4661+
if (const Symbol * subprogram{InclusiveScope().symbol()}) {
46624662
msg.Attach(subprogram->name(), "Containing subprogram"_en_US);
46634663
}
46644664
}
@@ -5174,7 +5174,7 @@ Symbol *ScopeHandler::FindSeparateModuleProcedureInterface(
51745174
symbol = generic->specific();
51755175
}
51765176
}
5177-
if (const Symbol *defnIface{FindSeparateModuleSubprogramInterface(symbol)}) {
5177+
if (const Symbol * defnIface{FindSeparateModuleSubprogramInterface(symbol)}) {
51785178
// Error recovery in case of multiple definitions
51795179
symbol = const_cast<Symbol *>(defnIface);
51805180
}
@@ -5313,8 +5313,8 @@ bool SubprogramVisitor::HandlePreviousCalls(
53135313
return generic->specific() &&
53145314
HandlePreviousCalls(name, *generic->specific(), subpFlag);
53155315
} else if (const auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
5316-
!proc->isDummy() &&
5317-
!symbol.attrs().HasAny(Attrs{Attr::INTRINSIC, Attr::POINTER})) {
5316+
!proc->isDummy() &&
5317+
!symbol.attrs().HasAny(Attrs{Attr::INTRINSIC, Attr::POINTER})) {
53185318
// There's a symbol created for previous calls to this subprogram or
53195319
// ENTRY's name. We have to replace that symbol in situ to avoid the
53205320
// obligation to rewrite symbol pointers in the parse tree.
@@ -5356,7 +5356,7 @@ const Symbol *SubprogramVisitor::CheckExtantProc(
53565356
if (prev) {
53575357
if (IsDummy(*prev)) {
53585358
} else if (auto *entity{prev->detailsIf<EntityDetails>()};
5359-
IsPointer(*prev) && entity && !entity->type()) {
5359+
IsPointer(*prev) && entity && !entity->type()) {
53605360
// POINTER attribute set before interface
53615361
} else if (inInterfaceBlock() && currScope() != prev->owner()) {
53625362
// Procedures in an INTERFACE block do not resolve to symbols
@@ -5428,7 +5428,7 @@ Symbol *SubprogramVisitor::PushSubprogramScope(const parser::Name &name,
54285428
}
54295429
set_inheritFromParent(false); // interfaces don't inherit, even if MODULE
54305430
}
5431-
if (Symbol *found{FindSymbol(name)};
5431+
if (Symbol * found{FindSymbol(name)};
54325432
found && found->has<HostAssocDetails>()) {
54335433
found->set(subpFlag); // PushScope() created symbol
54345434
}
@@ -6276,9 +6276,9 @@ void DeclarationVisitor::Post(const parser::VectorTypeSpec &x) {
62766276
vectorDerivedType.CookParameters(GetFoldingContext());
62776277
}
62786278

6279-
if (const DeclTypeSpec *extant{
6280-
ppcBuiltinTypesScope->FindInstantiatedDerivedType(
6281-
vectorDerivedType, DeclTypeSpec::Category::TypeDerived)}) {
6279+
if (const DeclTypeSpec *
6280+
extant{ppcBuiltinTypesScope->FindInstantiatedDerivedType(
6281+
vectorDerivedType, DeclTypeSpec::Category::TypeDerived)}) {
62826282
// This derived type and parameter expressions (if any) are already present
62836283
// in the __ppc_intrinsics scope.
62846284
SetDeclTypeSpec(*extant);
@@ -6300,7 +6300,7 @@ bool DeclarationVisitor::Pre(const parser::DeclarationTypeSpec::Type &) {
63006300

63016301
void DeclarationVisitor::Post(const parser::DeclarationTypeSpec::Type &type) {
63026302
const parser::Name &derivedName{std::get<parser::Name>(type.derived.t)};
6303-
if (const Symbol *derivedSymbol{derivedName.symbol}) {
6303+
if (const Symbol * derivedSymbol{derivedName.symbol}) {
63046304
CheckForAbstractType(*derivedSymbol); // C706
63056305
}
63066306
}
@@ -6369,8 +6369,8 @@ void DeclarationVisitor::Post(const parser::DerivedTypeSpec &x) {
63696369
if (!spec->MightBeParameterized()) {
63706370
spec->EvaluateParameters(context());
63716371
}
6372-
if (const DeclTypeSpec *extant{
6373-
currScope().FindInstantiatedDerivedType(*spec, category)}) {
6372+
if (const DeclTypeSpec *
6373+
extant{currScope().FindInstantiatedDerivedType(*spec, category)}) {
63746374
// This derived type and parameter expressions (if any) are already present
63756375
// in this scope.
63766376
SetDeclTypeSpec(*extant);
@@ -6401,7 +6401,8 @@ void DeclarationVisitor::Post(const parser::DeclarationTypeSpec::Record &rec) {
64016401
if (auto spec{ResolveDerivedType(typeName)}) {
64026402
spec->CookParameters(GetFoldingContext());
64036403
spec->EvaluateParameters(context());
6404-
if (const DeclTypeSpec *extant{currScope().FindInstantiatedDerivedType(
6404+
if (const DeclTypeSpec *
6405+
extant{currScope().FindInstantiatedDerivedType(
64056406
*spec, DeclTypeSpec::TypeDerived)}) {
64066407
SetDeclTypeSpec(*extant);
64076408
} else {
@@ -7412,7 +7413,7 @@ bool DeclarationVisitor::PassesLocalityChecks(
74127413
"Coarray '%s' not allowed in a %s locality-spec"_err_en_US, specName);
74137414
return false;
74147415
}
7415-
if (const DeclTypeSpec *type{symbol.GetType()}) {
7416+
if (const DeclTypeSpec * type{symbol.GetType()}) {
74167417
if (type->IsPolymorphic() && IsDummy(symbol) && !IsPointer(symbol) &&
74177418
!isReduce) { // F'2023 C1130
74187419
SayWithDecl(name, symbol,
@@ -7639,7 +7640,7 @@ Symbol *DeclarationVisitor::NoteInterfaceName(const parser::Name &name) {
76397640
}
76407641

76417642
void DeclarationVisitor::CheckExplicitInterface(const parser::Name &name) {
7642-
if (const Symbol *symbol{name.symbol}) {
7643+
if (const Symbol * symbol{name.symbol}) {
76437644
const Symbol &ultimate{symbol->GetUltimate()};
76447645
if (!context().HasError(*symbol) && !context().HasError(ultimate) &&
76457646
!BypassGeneric(ultimate).HasExplicitInterface()) {
@@ -7957,7 +7958,7 @@ bool ConstructVisitor::Pre(const parser::DataStmtValue &x) {
79577958
auto &mutableData{const_cast<parser::DataStmtConstant &>(data)};
79587959
if (auto *elem{parser::Unwrap<parser::ArrayElement>(mutableData)}) {
79597960
if (const auto *name{std::get_if<parser::Name>(&elem->base.u)}) {
7960-
if (const Symbol *symbol{FindSymbol(*name)};
7961+
if (const Symbol * symbol{FindSymbol(*name)};
79617962
symbol && symbol->GetUltimate().has<DerivedTypeDetails>()) {
79627963
mutableData.u = elem->ConvertToStructureConstructor(
79637964
DerivedTypeSpec{name->source, *symbol});
@@ -8103,15 +8104,15 @@ void ConstructVisitor::Post(const parser::SelectTypeStmt &x) {
81038104
}
81048105
}
81058106
} else {
8106-
if (const Symbol *whole{
8107-
UnwrapWholeSymbolDataRef(association.selector.expr)}) {
8107+
if (const Symbol *
8108+
whole{UnwrapWholeSymbolDataRef(association.selector.expr)}) {
81088109
ConvertToObjectEntity(const_cast<Symbol &>(*whole));
81098110
if (!IsVariableName(*whole)) {
81108111
Say(association.selector.source, // C901
81118112
"Selector is not a variable"_err_en_US);
81128113
association = {};
81138114
}
8114-
if (const DeclTypeSpec *type{whole->GetType()}) {
8115+
if (const DeclTypeSpec * type{whole->GetType()}) {
81158116
if (!type->IsPolymorphic()) { // C1159
81168117
Say(association.selector.source,
81178118
"Selector '%s' in SELECT TYPE statement must be "
@@ -8251,8 +8252,8 @@ Symbol *ConstructVisitor::MakeAssocEntity() {
82518252
"The associate name '%s' is already used in this associate statement"_err_en_US);
82528253
return nullptr;
82538254
}
8254-
} else if (const Symbol *whole{
8255-
UnwrapWholeSymbolDataRef(association.selector.expr)}) {
8255+
} else if (const Symbol *
8256+
whole{UnwrapWholeSymbolDataRef(association.selector.expr)}) {
82568257
symbol = &MakeSymbol(whole->name());
82578258
} else {
82588259
return nullptr;
@@ -8873,7 +8874,7 @@ bool DeclarationVisitor::CheckForHostAssociatedImplicit(
88738874
if (name.symbol) {
88748875
ApplyImplicitRules(*name.symbol, true);
88758876
}
8876-
if (Scope *host{GetHostProcedure()}; host && !isImplicitNoneType(*host)) {
8877+
if (Scope * host{GetHostProcedure()}; host && !isImplicitNoneType(*host)) {
88778878
Symbol *hostSymbol{nullptr};
88788879
if (!name.symbol) {
88798880
if (currScope().CanImport(name.source)) {
@@ -8944,7 +8945,7 @@ const parser::Name *DeclarationVisitor::FindComponent(
89448945
if (!type) {
89458946
return nullptr; // should have already reported error
89468947
}
8947-
if (const IntrinsicTypeSpec *intrinsic{type->AsIntrinsic()}) {
8948+
if (const IntrinsicTypeSpec * intrinsic{type->AsIntrinsic()}) {
89488949
auto category{intrinsic->category()};
89498950
MiscDetails::Kind miscKind{MiscDetails::Kind::None};
89508951
if (component.source == "kind") {
@@ -8966,7 +8967,7 @@ const parser::Name *DeclarationVisitor::FindComponent(
89668967
}
89678968
} else if (DerivedTypeSpec * derived{type->AsDerived()}) {
89688969
derived->Instantiate(currScope()); // in case of forward referenced type
8969-
if (const Scope *scope{derived->scope()}) {
8970+
if (const Scope * scope{derived->scope()}) {
89708971
if (Resolve(component, scope->FindComponent(component.source))) {
89718972
if (auto msg{CheckAccessibleSymbol(currScope(), *component.symbol)}) {
89728973
context().Say(component.source, *msg);
@@ -9117,8 +9118,8 @@ void DeclarationVisitor::PointerInitialization(
91179118
if (evaluate::IsNullProcedurePointer(&*expr)) {
91189119
CHECK(!details->init());
91199120
details->set_init(nullptr);
9120-
} else if (const Symbol *targetSymbol{
9121-
evaluate::UnwrapWholeSymbolDataRef(*expr)}) {
9121+
} else if (const Symbol *
9122+
targetSymbol{evaluate::UnwrapWholeSymbolDataRef(*expr)}) {
91229123
CHECK(!details->init());
91239124
details->set_init(*targetSymbol);
91249125
} else {
@@ -9686,7 +9687,7 @@ void ResolveNamesVisitor::EarlyDummyTypeDeclaration(
96869687
for (const auto &ent : entities) {
96879688
const auto &objName{std::get<parser::ObjectName>(ent.t)};
96889689
Resolve(objName, FindInScope(currScope(), objName));
9689-
if (Symbol *symbol{objName.symbol};
9690+
if (Symbol * symbol{objName.symbol};
96909691
symbol && IsDummy(*symbol) && NeedsType(*symbol)) {
96919692
if (!type) {
96929693
type = ProcessTypeSpec(declTypeSpec);
@@ -9825,7 +9826,7 @@ void ResolveNamesVisitor::FinishSpecificationPart(
98259826
if (auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
98269827
!proc->isDummy() && !IsPointer(symbol) &&
98279828
!symbol.attrs().test(Attr::BIND_C)) {
9828-
if (const Symbol *iface{proc->procInterface()};
9829+
if (const Symbol * iface{proc->procInterface()};
98299830
iface && IsBindCProcedure(*iface)) {
98309831
SetImplicitAttr(symbol, Attr::BIND_C);
98319832
SetBindNameOn(symbol);
@@ -9958,7 +9959,7 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
99589959
Symbol *ptrSymbol{parser::GetLastName(dataRef).symbol};
99599960
Walk(bounds);
99609961
// Resolve unrestricted specific intrinsic procedures as in "p => cos".
9961-
if (const parser::Name *name{parser::Unwrap<parser::Name>(expr)}) {
9962+
if (const parser::Name * name{parser::Unwrap<parser::Name>(expr)}) {
99629963
if (NameIsKnownOrIntrinsic(*name)) {
99639964
if (Symbol * symbol{name->symbol}) {
99649965
if (IsProcedurePointer(ptrSymbol) &&
@@ -10399,8 +10400,8 @@ void ResolveNamesVisitor::ResolveSpecificationParts(ProgramTree &node) {
1039910400
// implied SAVE so that evaluate::IsSaved() will return true.
1040010401
if (node.scope()->kind() == Scope::Kind::MainProgram) {
1040110402
if (const auto *object{symbol.detailsIf<ObjectEntityDetails>()}) {
10402-
if (const DeclTypeSpec *type{object->type()}) {
10403-
if (const DerivedTypeSpec *derived{type->AsDerived()}) {
10403+
if (const DeclTypeSpec * type{object->type()}) {
10404+
if (const DerivedTypeSpec * derived{type->AsDerived()}) {
1040410405
if (!IsSaved(symbol) && FindCoarrayPotentialComponent(*derived)) {
1040510406
SetImplicitAttr(symbol, Attr::SAVE);
1040610407
}
@@ -10657,7 +10658,7 @@ void ResolveNamesVisitor::FinishDerivedTypeInstantiation(Scope &scope) {
1065710658
if (DerivedTypeSpec * spec{scope.derivedTypeSpec()}) {
1065810659
spec->Instantiate(currScope());
1065910660
const Symbol &origTypeSymbol{spec->typeSymbol()};
10660-
if (const Scope *origTypeScope{origTypeSymbol.scope()}) {
10661+
if (const Scope * origTypeScope{origTypeSymbol.scope()}) {
1066110662
CHECK(origTypeScope->IsDerivedType() &&
1066210663
origTypeScope->symbol() == &origTypeSymbol);
1066310664
auto &foldingContext{GetFoldingContext()};
@@ -10668,7 +10669,7 @@ void ResolveNamesVisitor::FinishDerivedTypeInstantiation(Scope &scope) {
1066810669
if (IsPointer(comp)) {
1066910670
if (auto *details{comp.detailsIf<ObjectEntityDetails>()}) {
1067010671
auto origDetails{origComp.get<ObjectEntityDetails>()};
10671-
if (const MaybeExpr &init{origDetails.init()}) {
10672+
if (const MaybeExpr & init{origDetails.init()}) {
1067210673
SomeExpr newInit{*init};
1067310674
MaybeExpr folded{FoldExpr(std::move(newInit))};
1067410675
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)