File tree Expand file tree Collapse file tree 7 files changed +54
-5
lines changed
Expand file tree Collapse file tree 7 files changed +54
-5
lines changed Original file line number Diff line number Diff line change @@ -1110,6 +1110,9 @@ bool IsArraySection(const Expr<SomeType> &expr);
11101110// Predicate: does an expression contain constant?
11111111bool HasConstant (const Expr<SomeType> &);
11121112
1113+ // Predicate: Does an expression contain a component
1114+ bool HasStructureComponent (const Expr<SomeType> &expr);
1115+
11131116// Utilities for attaching the location of the declaration of a symbol
11141117// of interest to a message. Handles the case of USE association gracefully.
11151118parser::Message *AttachDeclaration (parser::Message &, const Symbol &);
Original file line number Diff line number Diff line change @@ -1210,6 +1210,27 @@ bool HasConstant(const Expr<SomeType> &expr) {
12101210 return HasConstantHelper{}(expr);
12111211}
12121212
1213+ // HasStructureComponent()
1214+ struct HasStructureComponentHelper : public AnyTraverse <HasStructureComponentHelper, bool , false > {
1215+ using Base = AnyTraverse<HasStructureComponentHelper, bool , false >;
1216+ HasStructureComponentHelper () : Base(*this ) {}
1217+ using Base::operator ();
1218+
1219+ bool operator ()(const DataRef &dataRef) const {
1220+ return std::holds_alternative<Component>(dataRef.u );
1221+ }
1222+ bool operator ()(const NamedEntity &NamedEntity) const {
1223+ return NamedEntity.UnwrapComponent () != nullptr ;
1224+ }
1225+ bool operator ()(const Component &) const {
1226+ return true ;
1227+ }
1228+ };
1229+
1230+ bool HasStructureComponent (const Expr<SomeType> &expr) {
1231+ return HasStructureComponentHelper{}(expr);
1232+ }
1233+
12131234parser::Message *AttachDeclaration (
12141235 parser::Message &message, const Symbol &symbol) {
12151236 const Symbol *unhosted{&symbol};
Original file line number Diff line number Diff line change @@ -4673,12 +4673,13 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Copyin &x) {
46734673void OmpStructureChecker::CheckStructureComponent (
46744674 const parser::OmpObjectList &objects, llvm::omp::Clause clauseId) {
46754675 auto CheckComponent{[&](const parser::Designator &designator) {
4676- if (auto *dataRef{std::get_if<parser::DataRef>(&designator.u )}) {
4676+ if (const parser::DataRef *dataRef{std::get_if<parser::DataRef>(&designator.u )}) {
46774677 if (!IsDataRefTypeParamInquiry (dataRef)) {
4678- if (auto *comp{parser::Unwrap<parser::StructureComponent>(*dataRef)}) {
4679- context_.Say (comp->component .source ,
4680- " A variable that is part of another variable cannot appear on the %s clause" _err_en_US,
4681- parser::ToUpperCaseLetters (getClauseName (clauseId).str ()));
4678+ const auto expr = AnalyzeExpr (context_, designator);
4679+ if (expr.has_value () && evaluate::HasStructureComponent (expr.value ())) {
4680+ context_.Say (designator.source ,
4681+ " A variable that is part of another variable cannot appear on the %s clause" _err_en_US,
4682+ parser::ToUpperCaseLetters (getClauseName (clauseId).str ()));
46824683 }
46834684 }
46844685 }
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ subroutine f06
4747 integer :: a(10 )
4848 end type
4949 type (t) :: x
50+ ! ERROR: A variable that is part of another variable cannot appear on the IN_REDUCTION clause
5051! ERROR: The base expression of an array element or section in IN_REDUCTION clause must be an identifier
5152! $omp target in_reduction(+: x%a(2))
5253! $omp end target
@@ -57,6 +58,7 @@ subroutine f07
5758 integer :: a(10 )
5859 end type
5960 type (t) :: x
61+ ! ERROR: A variable that is part of another variable cannot appear on the IN_REDUCTION clause
6062! ERROR: The base expression of an array element or section in IN_REDUCTION clause must be an identifier
6163! $omp target in_reduction(+: x%a(1:10))
6264! $omp end target
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module m
1313
1414 subroutine f00
1515 type (t) :: x
16+ ! ERROR: A variable that is part of another variable cannot appear on the REDUCTION clause
1617 ! ERROR: The base expression of an array element or section in REDUCTION clause must be an identifier
1718 ! $omp do reduction (+ : x%a(2))
1819 do i = 1 , 10
@@ -22,6 +23,7 @@ subroutine f00
2223
2324 subroutine f01
2425 type (t) :: x
26+ ! ERROR: A variable that is part of another variable cannot appear on the REDUCTION clause
2527 ! ERROR: The base expression of an array element or section in REDUCTION clause must be an identifier
2628 ! $omp do reduction (+ : x%a(1:10))
2729 do i = 1 , 10
Original file line number Diff line number Diff line change 1+ ! Test that Structure Component Array Elements are caught by Semantics and return an error
2+ ! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp -fopenmp-version=45
3+
4+ type test_type
5+ integer :: array(2 )
6+ end type
7+
8+ contains
9+ subroutine test
10+ type (test_type) :: x
11+
12+ ! ERROR: A variable that is part of another variable cannot appear on the REDUCTION clause
13+ ! $omp do reduction(+: x%array(2))
14+ do i= 1 , 2
15+ end do
16+ ! $omp end do
17+ end subroutine
18+ end
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ subroutine f06
4747 integer :: a(10 )
4848 end type
4949 type (t) :: x
50+ ! ERROR: A variable that is part of another variable cannot appear on the TASK_REDUCTION clause
5051! ERROR: The base expression of an array element or section in TASK_REDUCTION clause must be an identifier
5152! $omp taskgroup task_reduction(+: x%a(2))
5253! $omp end taskgroup
@@ -57,6 +58,7 @@ subroutine f07
5758 integer :: a(10 )
5859 end type
5960 type (t) :: x
61+ ! ERROR: A variable that is part of another variable cannot appear on the TASK_REDUCTION clause
6062! ERROR: The base expression of an array element or section in TASK_REDUCTION clause must be an identifier
6163! $omp taskgroup task_reduction(+: x%a(1:10))
6264! $omp end taskgroup
You can’t perform that action at this time.
0 commit comments