@@ -974,36 +974,40 @@ void OmpStructureChecker::CheckDistLinear(
974
974
}
975
975
976
976
void 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 )} ;
978
978
const auto &clauseList{std::get<parser::OmpClauseList>(beginLoopDir.t )};
979
979
for (const auto &clause : clauseList.v ) {
980
980
if (const auto *reductionClause{
981
981
std::get_if<parser::OmpClause::Reduction>(&clause.u )}) {
982
- using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
983
982
const auto &maybeModifier{
984
983
std::get<std::optional<ReductionModifier>>(reductionClause->v .t )};
985
984
if (maybeModifier && *maybeModifier == ReductionModifier::Inscan) {
986
985
987
986
const auto &objectList{
988
987
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
+ };
989
1001
for (const auto &ompObj : objectList.v ) {
990
1002
common::visit (
991
1003
common::visitors{
992
1004
[&](const parser::Designator &designator) {
993
1005
if (const auto *name{semantics::getDesignatorNameIfDataRef (
994
1006
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);
1004
1008
}
1005
1009
},
1006
- [&](const auto &name) {},
1010
+ [&](const auto &name) { checkReductionSymbolInScan (&name); },
1007
1011
},
1008
1012
ompObj.u );
1009
1013
}
@@ -2831,24 +2835,23 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Reduction &x) {
2831
2835
if (CheckReductionOperators (x)) {
2832
2836
CheckReductionTypeList (x);
2833
2837
}
2834
- using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
2835
2838
if (const auto &maybeModifier{
2836
2839
std::get<std::optional<ReductionModifier>>(x.v .t )}) {
2837
- ReductionModifier modifier{*maybeModifier};
2840
+ const ReductionModifier modifier{*maybeModifier};
2838
2841
const auto &ompObjectList{std::get<parser::OmpObjectList>(x.v .t )};
2839
- addModifiertoMap (ompObjectList, modifier);
2842
+ AddModifierToMap (ompObjectList, modifier);
2840
2843
CheckReductionModifier (modifier);
2841
2844
}
2842
2845
}
2843
2846
2844
2847
void OmpStructureChecker::Enter (const parser::OmpClause::Inclusive &x) {
2845
2848
CheckAllowed (llvm::omp::Clause::OMPC_inclusive);
2846
- checkAndAddSymbolsToUsedInScanList (x.v );
2849
+ CheckAndAddSymbolsToUsedInScanList (x.v );
2847
2850
}
2848
2851
2849
2852
void OmpStructureChecker::Enter (const parser::OmpClause::Exclusive &x) {
2850
2853
CheckAllowed (llvm::omp::Clause::OMPC_exclusive);
2851
- checkAndAddSymbolsToUsedInScanList (x.v );
2854
+ CheckAndAddSymbolsToUsedInScanList (x.v );
2852
2855
}
2853
2856
2854
2857
bool OmpStructureChecker::CheckReductionOperators (
@@ -2892,8 +2895,8 @@ bool OmpStructureChecker::CheckReductionOperators(
2892
2895
return ok;
2893
2896
}
2894
2897
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) {
2897
2900
for (const auto &ompObject : x.v ) {
2898
2901
if (const auto *name{parser::Unwrap<parser::Name>(ompObject)}) {
2899
2902
if (const auto *symbol{name->symbol }) {
@@ -2903,32 +2906,35 @@ void OmpStructureChecker::addModifiertoMap(const parser::OmpObjectList &x,
2903
2906
}
2904
2907
}
2905
2908
2906
- void OmpStructureChecker::checkAndAddSymbolsToUsedInScanList (
2909
+ void OmpStructureChecker::CheckAndAddSymbolsToUsedInScanList (
2907
2910
const parser::OmpObjectList &x) {
2908
2911
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
+ };
2909
2929
common::visit (
2910
2930
common::visitors{
2911
2931
[&](const parser::Designator &designator) {
2912
2932
if (const auto *name{
2913
2933
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);
2929
2935
}
2930
2936
},
2931
- [&](const auto &name) {},
2937
+ [&](const auto &name) { checkScanSymbolInReduction (&name); },
2932
2938
},
2933
2939
ompObj.u );
2934
2940
}
@@ -3068,10 +3074,9 @@ void OmpStructureChecker::CheckReductionTypeList(
3068
3074
}
3069
3075
3070
3076
void OmpStructureChecker::CheckReductionModifier (
3071
- const parser::OmpReductionClause::ReductionModifier &modifier) {
3072
- using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
3077
+ const ReductionModifier &modifier) {
3073
3078
if (modifier == ReductionModifier::Default) {
3074
- // the default one is always ok.
3079
+ // The default one is always ok.
3075
3080
return ;
3076
3081
}
3077
3082
const DirectiveContext &dirCtx{GetContext ()};
0 commit comments