@@ -61,6 +61,9 @@ template <typename T> class DirectiveAttributeVisitor {
61
61
? std::nullopt
62
62
: std::make_optional<DirContext>(dirContext_.back ());
63
63
}
64
+ void PushContext (const parser::CharBlock &source, T dir, Scope &scope) {
65
+ dirContext_.emplace_back (source, dir, scope);
66
+ }
64
67
void PushContext (const parser::CharBlock &source, T dir) {
65
68
dirContext_.emplace_back (source, dir, context_.FindScope (source));
66
69
}
@@ -115,8 +118,8 @@ template <typename T> class DirectiveAttributeVisitor {
115
118
116
119
class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
117
120
public:
118
- explicit AccAttributeVisitor (SemanticsContext &context)
119
- : DirectiveAttributeVisitor(context) {}
121
+ explicit AccAttributeVisitor (SemanticsContext &context, Scope *topScope )
122
+ : DirectiveAttributeVisitor(context), topScope_(topScope) {}
120
123
121
124
template <typename A> void Walk (const A &x) { parser::Walk (x, *this ); }
122
125
template <typename A> bool Pre (const A &) { return true ; }
@@ -281,6 +284,7 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
281
284
const llvm::acc::Clause clause, const parser::AccObjectList &objectList);
282
285
void AddRoutineInfoToSymbol (
283
286
Symbol &, const parser::OpenACCRoutineConstruct &);
287
+ Scope *topScope_;
284
288
};
285
289
286
290
// Data-sharing and Data-mapping attributes for data-refs in OpenMP construct
@@ -802,10 +806,6 @@ bool AccAttributeVisitor::Pre(const parser::OpenACCDeclarativeConstruct &x) {
802
806
const auto &declDir{
803
807
std::get<parser::AccDeclarativeDirective>(declConstruct->t )};
804
808
PushContext (declDir.source , llvm::acc::Directive::ACCD_declare);
805
- } else if (const auto *routineConstruct{
806
- std::get_if<parser::OpenACCRoutineConstruct>(&x.u )}) {
807
- const auto &verbatim{std::get<parser::Verbatim>(routineConstruct->t )};
808
- PushContext (verbatim.source , llvm::acc::Directive::ACCD_routine);
809
809
}
810
810
ClearDataSharingAttributeObjects ();
811
811
return true ;
@@ -994,6 +994,13 @@ void AccAttributeVisitor::AddRoutineInfoToSymbol(
994
994
}
995
995
996
996
bool AccAttributeVisitor::Pre (const parser::OpenACCRoutineConstruct &x) {
997
+ const auto &verbatim{std::get<parser::Verbatim>(x.t )};
998
+ if (topScope_) {
999
+ PushContext (
1000
+ verbatim.source , llvm::acc::Directive::ACCD_routine, *topScope_);
1001
+ } else {
1002
+ PushContext (verbatim.source , llvm::acc::Directive::ACCD_routine);
1003
+ }
997
1004
const auto &optName{std::get<std::optional<parser::Name>>(x.t )};
998
1005
if (optName) {
999
1006
if (Symbol *sym = ResolveFctName (*optName)) {
@@ -1005,7 +1012,9 @@ bool AccAttributeVisitor::Pre(const parser::OpenACCRoutineConstruct &x) {
1005
1012
(*optName).source );
1006
1013
}
1007
1014
} else {
1008
- AddRoutineInfoToSymbol (*currScope ().symbol (), x);
1015
+ if (currScope ().symbol ()) {
1016
+ AddRoutineInfoToSymbol (*currScope ().symbol (), x);
1017
+ }
1009
1018
}
1010
1019
return true ;
1011
1020
}
@@ -2190,10 +2199,10 @@ void OmpAttributeVisitor::CheckMultipleAppearances(
2190
2199
}
2191
2200
}
2192
2201
2193
- void ResolveAccParts (
2194
- SemanticsContext &context, const parser::ProgramUnit &node ) {
2202
+ void ResolveAccParts (SemanticsContext &context, const parser::ProgramUnit &node,
2203
+ Scope *topScope ) {
2195
2204
if (context.IsEnabled (common::LanguageFeature::OpenACC)) {
2196
- AccAttributeVisitor{context}.Walk (node);
2205
+ AccAttributeVisitor{context, topScope }.Walk (node);
2197
2206
}
2198
2207
}
2199
2208
0 commit comments