Skip to content

Commit a929e62

Browse files
committed
move SetImplicitCUDADevice call after symbols inside block construct are converted to object
1 parent 082251b commit a929e62

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ using MessageFormattedText = parser::MessageFormattedText;
5858
class ResolveNamesVisitor;
5959
class ScopeHandler;
6060

61+
void SetImplicitCUDADevice(bool inDeviceSubprogram, Symbol &symbol);
62+
6163
// ImplicitRules maps initial character of identifier to the DeclTypeSpec
6264
// representing the implicit type; std::nullopt if none.
6365
// It also records the presence of IMPLICIT NONE statements.
@@ -2867,8 +2869,31 @@ void ScopeHandler::PopScope() {
28672869
// Entities that are not yet classified as objects or procedures are now
28682870
// assumed to be objects.
28692871
// TODO: Statement functions
2872+
bool inDeviceSubprogram{false};
2873+
Symbol *scopeSym{currScope().symbol()};
2874+
if (currScope().kind() == Scope::Kind::BlockConstruct) {
2875+
scopeSym = currScope().parent().symbol();
2876+
}
2877+
if (scopeSym) {
2878+
if (auto *details{scopeSym->detailsIf<SubprogramDetails>()}) {
2879+
// Check the current procedure is a device procedure to apply implicit
2880+
// attribute at the end.
2881+
if (auto attrs{details->cudaSubprogramAttrs()}) {
2882+
if (*attrs == common::CUDASubprogramAttrs::Device ||
2883+
*attrs == common::CUDASubprogramAttrs::Global ||
2884+
*attrs == common::CUDASubprogramAttrs::Grid_Global) {
2885+
inDeviceSubprogram = true;
2886+
}
2887+
}
2888+
}
2889+
}
28702890
for (auto &pair : currScope()) {
28712891
ConvertToObjectEntity(*pair.second);
2892+
if (currScope_->kind() == Scope::Kind::BlockConstruct) {
2893+
// Only look for specification in BlockConstruct. Other cases are done in
2894+
// ResolveSpecificationParts.
2895+
SetImplicitCUDADevice(inDeviceSubprogram, *pair.second);
2896+
}
28722897
}
28732898
funcResultStack_.Pop();
28742899
// If popping back into a global scope, pop back to the top scope.
@@ -9555,7 +9580,7 @@ void ResolveNamesVisitor::CreateGeneric(const parser::GenericSpec &x) {
95559580
info.Resolve(&MakeSymbol(symbolName, Attrs{}, std::move(genericDetails)));
95569581
}
95579582

9558-
static void SetImplicitCUDADevice(bool inDeviceSubprogram, Symbol &symbol) {
9583+
void SetImplicitCUDADevice(bool inDeviceSubprogram, Symbol &symbol) {
95599584
if (inDeviceSubprogram && symbol.has<ObjectEntityDetails>()) {
95609585
auto *object{symbol.detailsIf<ObjectEntityDetails>()};
95619586
if (!object->cudaDataAttr() && !IsValue(symbol) &&
@@ -9571,24 +9596,6 @@ void ResolveNamesVisitor::FinishSpecificationPart(
95719596
misparsedStmtFuncFound_ = false;
95729597
funcResultStack().CompleteFunctionResultType();
95739598
CheckImports();
9574-
bool inDeviceSubprogram{false};
9575-
Symbol *scopeSym{currScope().symbol()};
9576-
if (currScope().kind() == Scope::Kind::BlockConstruct) {
9577-
scopeSym = currScope().parent().symbol();
9578-
}
9579-
if (scopeSym) {
9580-
if (auto *details{scopeSym->detailsIf<SubprogramDetails>()}) {
9581-
// Check the current procedure is a device procedure to apply implicit
9582-
// attribute at the end.
9583-
if (auto attrs{details->cudaSubprogramAttrs()}) {
9584-
if (*attrs == common::CUDASubprogramAttrs::Device ||
9585-
*attrs == common::CUDASubprogramAttrs::Global ||
9586-
*attrs == common::CUDASubprogramAttrs::Grid_Global) {
9587-
inDeviceSubprogram = true;
9588-
}
9589-
}
9590-
}
9591-
}
95929599
for (auto &pair : currScope()) {
95939600
auto &symbol{*pair.second};
95949601
if (inInterfaceBlock()) {
@@ -9623,11 +9630,6 @@ void ResolveNamesVisitor::FinishSpecificationPart(
96239630
SetBindNameOn(symbol);
96249631
}
96259632
}
9626-
if (currScope().kind() == Scope::Kind::BlockConstruct) {
9627-
// Only look for specification in BlockConstruct. Other cases are done in
9628-
// ResolveSpecificationParts.
9629-
SetImplicitCUDADevice(inDeviceSubprogram, symbol);
9630-
}
96319633
}
96329634
currScope().InstantiateDerivedTypes();
96339635
for (const auto &decl : decls) {

0 commit comments

Comments
 (0)