@@ -974,36 +974,40 @@ void OmpStructureChecker::CheckDistLinear(
974974}
975975
976976void OmpStructureChecker::Leave (const parser::OpenMPLoopConstruct &x) {
977- const auto &beginLoopDir = std::get<parser::OmpBeginLoopDirective>(x.t );
977+ const auto &beginLoopDir{ std::get<parser::OmpBeginLoopDirective>(x.t )} ;
978978 const auto &clauseList{std::get<parser::OmpClauseList>(beginLoopDir.t )};
979979 for (const auto &clause : clauseList.v ) {
980980 if (const auto *reductionClause{
981981 std::get_if<parser::OmpClause::Reduction>(&clause.u )}) {
982- using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
983982 const auto &maybeModifier{
984983 std::get<std::optional<ReductionModifier>>(reductionClause->v .t )};
985984 if (maybeModifier && *maybeModifier == ReductionModifier::Inscan) {
986985
987986 const auto &objectList{
988987 std::get<parser::OmpObjectList>(reductionClause->v .t )};
988+ auto checkReductionSymbolInScan = [&](const parser::Name *name) {
989+ if (name->symbol ) {
990+ std::string nameStr = name->symbol ->name ().ToString ();
991+ if (GetContext ().usedInScanDirective .find (nameStr) ==
992+ GetContext ().usedInScanDirective .end ()) {
993+ context_.Say (name->source ,
994+ " List item %s must appear in 'inclusive' or "
995+ " 'exclusive' clause of an "
996+ " enclosed scan directive" _err_en_US,
997+ nameStr);
998+ }
999+ }
1000+ };
9891001 for (const auto &ompObj : objectList.v ) {
9901002 common::visit (
9911003 common::visitors{
9921004 [&](const parser::Designator &designator) {
9931005 if (const auto *name{semantics::getDesignatorNameIfDataRef (
9941006 designator)}) {
995- std::string nameStr = name->symbol ->name ().ToString ();
996- if (GetContext ().usedInScanDirective .find (nameStr) ==
997- GetContext ().usedInScanDirective .end ()) {
998- context_.Say (name->source ,
999- " List item %s must appear in 'inclusive' or "
1000- " 'exclusive' clause of an "
1001- " enclosed scan directive" _err_en_US,
1002- nameStr);
1003- }
1007+ checkReductionSymbolInScan (name);
10041008 }
10051009 },
1006- [&](const auto &name) {},
1010+ [&](const auto &name) { checkReductionSymbolInScan (&name); },
10071011 },
10081012 ompObj.u );
10091013 }
@@ -2831,24 +2835,23 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Reduction &x) {
28312835 if (CheckReductionOperators (x)) {
28322836 CheckReductionTypeList (x);
28332837 }
2834- using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
28352838 if (const auto &maybeModifier{
28362839 std::get<std::optional<ReductionModifier>>(x.v .t )}) {
2837- ReductionModifier modifier{*maybeModifier};
2840+ const ReductionModifier modifier{*maybeModifier};
28382841 const auto &ompObjectList{std::get<parser::OmpObjectList>(x.v .t )};
2839- addModifiertoMap (ompObjectList, modifier);
2842+ AddModifierToMap (ompObjectList, modifier);
28402843 CheckReductionModifier (modifier);
28412844 }
28422845}
28432846
28442847void OmpStructureChecker::Enter (const parser::OmpClause::Inclusive &x) {
28452848 CheckAllowed (llvm::omp::Clause::OMPC_inclusive);
2846- checkAndAddSymbolsToUsedInScanList (x.v );
2849+ CheckAndAddSymbolsToUsedInScanList (x.v );
28472850}
28482851
28492852void OmpStructureChecker::Enter (const parser::OmpClause::Exclusive &x) {
28502853 CheckAllowed (llvm::omp::Clause::OMPC_exclusive);
2851- checkAndAddSymbolsToUsedInScanList (x.v );
2854+ CheckAndAddSymbolsToUsedInScanList (x.v );
28522855}
28532856
28542857bool OmpStructureChecker::CheckReductionOperators (
@@ -2892,8 +2895,8 @@ bool OmpStructureChecker::CheckReductionOperators(
28922895 return ok;
28932896}
28942897
2895- void OmpStructureChecker::addModifiertoMap ( const parser::OmpObjectList &x,
2896- parser::OmpReductionClause:: ReductionModifier &modifier) {
2898+ void OmpStructureChecker::AddModifierToMap (
2899+ const parser::OmpObjectList &x, const ReductionModifier &modifier) {
28972900 for (const auto &ompObject : x.v ) {
28982901 if (const auto *name{parser::Unwrap<parser::Name>(ompObject)}) {
28992902 if (const auto *symbol{name->symbol }) {
@@ -2903,32 +2906,35 @@ void OmpStructureChecker::addModifiertoMap(const parser::OmpObjectList &x,
29032906 }
29042907}
29052908
2906- void OmpStructureChecker::checkAndAddSymbolsToUsedInScanList (
2909+ void OmpStructureChecker::CheckAndAddSymbolsToUsedInScanList (
29072910 const parser::OmpObjectList &x) {
29082911 for (const auto &ompObj : x.v ) {
2912+ auto checkScanSymbolInReduction = [&](const parser::Name *name) {
2913+ if (name->symbol ) {
2914+ if (CurrentDirectiveIsNested ()) {
2915+ std::string nameStr = name->symbol ->name ().ToString ();
2916+ if (GetContextParent ().reductionMod .find (nameStr) ==
2917+ GetContextParent ().reductionMod .end ()) {
2918+
2919+ context_.Say (name->source ,
2920+ " List item %s must appear in 'reduction' clause "
2921+ " with the 'inscan' modifier of the parent "
2922+ " directive" _err_en_US,
2923+ nameStr);
2924+ }
2925+ GetContextParent ().usedInScanDirective .insert (nameStr);
2926+ }
2927+ }
2928+ };
29092929 common::visit (
29102930 common::visitors{
29112931 [&](const parser::Designator &designator) {
29122932 if (const auto *name{
29132933 semantics::getDesignatorNameIfDataRef (designator)}) {
2914- if (name->symbol ) {
2915- if (CurrentDirectiveIsNested ()) {
2916- std::string nameStr = name->symbol ->name ().ToString ();
2917- if (GetContextParent ().reductionMod .find (nameStr) ==
2918- GetContextParent ().reductionMod .end ()) {
2919-
2920- context_.Say (name->source ,
2921- " List item %s must appear in 'reduction' clause "
2922- " with the 'inscan' modifier of the parent "
2923- " directive" _err_en_US,
2924- nameStr);
2925- }
2926- GetContextParent ().usedInScanDirective .insert (nameStr);
2927- }
2928- }
2934+ checkScanSymbolInReduction (name);
29292935 }
29302936 },
2931- [&](const auto &name) {},
2937+ [&](const auto &name) { checkScanSymbolInReduction (&name); },
29322938 },
29332939 ompObj.u );
29342940 }
@@ -3068,10 +3074,9 @@ void OmpStructureChecker::CheckReductionTypeList(
30683074}
30693075
30703076void OmpStructureChecker::CheckReductionModifier (
3071- const parser::OmpReductionClause::ReductionModifier &modifier) {
3072- using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
3077+ const ReductionModifier &modifier) {
30733078 if (modifier == ReductionModifier::Default) {
3074- // the default one is always ok.
3079+ // The default one is always ok.
30753080 return ;
30763081 }
30773082 const DirectiveContext &dirCtx{GetContext ()};
0 commit comments