Skip to content

Commit 3e563fd

Browse files
Add further tests, fix comments
1 parent 085454a commit 3e563fd

File tree

7 files changed

+71
-8
lines changed

7 files changed

+71
-8
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,6 @@ class OmpVisitor : public virtual DeclarationVisitor {
14701470
}
14711471

14721472
bool Pre(const parser::OpenMPDeclareMapperConstruct &);
1473-
void Post(const parser::OpenMPDeclareMapperConstruct &) { PopScope(); };
14741473

14751474
void Post(const parser::OmpBeginLoopDirective &) {
14761475
messageHandler().set_currStmtSource(std::nullopt);
@@ -1609,10 +1608,10 @@ void OmpVisitor::Post(const parser::OpenMPBlockConstruct &x) {
16091608
}
16101609
}
16111610

1612-
// This "manually" walks the tree of the cosntruct, because the order
1613-
// elements are resolved by the normal visitor will try to resolve
1614-
// the map clauses attached to the directive without having resolved
1615-
// the type, so the type is figured out using the implicit rules.
1611+
// This "manually" walks the tree of the construct, because we need
1612+
// to resolve the type before the map clauses are processed - when
1613+
// just following the natural flow, the map clauses gets processed before
1614+
// the type has been fully processed.
16161615
bool OmpVisitor::Pre(const parser::OpenMPDeclareMapperConstruct &x) {
16171616
AddOmpSourceRange(x.source);
16181617
BeginDeclTypeSpec();
@@ -1623,8 +1622,9 @@ bool OmpVisitor::Pre(const parser::OpenMPDeclareMapperConstruct &x) {
16231622
&MakeSymbol(*mapperName, MiscDetails{MiscDetails::Kind::ConstructName});
16241623
mapperName->symbol = mapperSym;
16251624
} else {
1625+
const parser::CharBlock defaultName{"default", 7};
16261626
mapperSym = &MakeSymbol(
1627-
"default", Attrs{}, MiscDetails{MiscDetails::Kind::ConstructName});
1627+
defaultName, Attrs{}, MiscDetails{MiscDetails::Kind::ConstructName});
16281628
}
16291629

16301630
PushScope(Scope::Kind::OtherConstruct, nullptr);
@@ -1635,6 +1635,7 @@ bool OmpVisitor::Pre(const parser::OpenMPDeclareMapperConstruct &x) {
16351635
Walk(std::get<parser::OmpClauseList>(x.t));
16361636

16371637
EndDeclTypeSpec();
1638+
PopScope();
16381639
return false;
16391640
}
16401641

flang/lib/Semantics/unparse-with-symbols.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ class SymbolDumpVisitor {
5353
void Post(const parser::OpenMPThreadprivate &) { currStmt_ = std::nullopt; }
5454
void Post(const parser::Name &name);
5555

56+
bool Pre(const parser::OpenMPDeclareMapperConstruct &x) {
57+
currStmt_ = x.source;
58+
return true;
59+
}
60+
void Post(const parser::OpenMPDeclareMapperConstruct &) {
61+
currStmt_ = std::nullopt;
62+
}
63+
5664
private:
5765
std::optional<SourceName> currStmt_; // current statement we are processing
5866
std::multimap<const char *, const Symbol *> symbols_; // location to symbol

flang/test/Parser/OpenMP/declare-mapper-unparse.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,19 @@ program main
2424
!PARSE-TREE: DataRef -> Name = 'mapped'
2525
!PARSE-TREE: Name = 'x'
2626

27+
!CHECK: !$OMP DECLARE MAPPER (ty::mapped) MAP(mapped,mapped%x)
28+
!$omp declare mapper(ty :: mapped) map(mapped, mapped%x)
29+
30+
!PARSE-TREE: OpenMPDeclareMapperConstruct
31+
!PARSE-TREE: OmpDeclareMapperSpecifier
32+
!PARSE-TREE: TypeSpec -> DerivedTypeSpec
33+
!PARSE-TREE: Name = 'ty'
34+
!PARSE-TREE: Name = 'mapped'
35+
!PARSE-TREE: OmpMapClause
36+
!PARSE-TREE: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'mapped'
37+
!PARSE-TREE: OmpObject -> Designator -> DataRef -> StructureComponent
38+
!PARSE-TREE: DataRef -> Name = 'mapped'
39+
!PARSE-TREE: Name = 'x'
40+
2741
end program main
2842
!CHECK-LABEL: end program main
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
! RUN: %flang_fc1 -fdebug-dump-symbols -fopenmp -fopenmp-version=50 %s | FileCheck %s
2+
3+
program main
4+
!CHECK-LABEL: MainProgram scope: main
5+
implicit none
6+
7+
type ty
8+
integer :: x
9+
end type ty
10+
!$omp declare mapper(mymapper : ty :: mapped) map(mapped, mapped%x)
11+
!$omp declare mapper(ty :: maptwo) map(maptwo, maptwo%x)
12+
13+
!! Note, symbols come out in their respective scope, but not in declaration order.
14+
!CHECK: default: Misc ConstructName
15+
!CHECK: mymapper: Misc ConstructName
16+
!CHECK: ty: DerivedType components: x
17+
!CHECK: DerivedType scope: ty
18+
!CHECK: OtherConstruct scope:
19+
!CHECK: mapped (OmpMapToFrom) {{.*}} ObjectEntity type: TYPE(ty)
20+
!CHECK: OtherConstruct scope:
21+
!CHECK: maptwo (OmpMapToFrom) {{.*}} ObjectEntity type: TYPE(ty)
22+
23+
end program main
24+

flang/test/Semantics/OpenMP/declare-mapper01.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=50
2-
! Test the source code starting with omp syntax
2+
! Test the declare mapper with non-derived type.
33

44
integer :: y
55

flang/test/Semantics/OpenMP/declare-mapper02.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=50
2-
! Test the source code starting with omp syntax
2+
! Test the declare mapper construct with abstract type.
33

44
type, abstract :: t1
55
integer :: y
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=50
2+
! Test the declare mapper construct with two default mappers.
3+
4+
type :: t1
5+
integer :: y
6+
end type t1
7+
8+
type :: t2
9+
real :: y, z
10+
end type t2
11+
12+
!error: 'default' is already declared in this scoping unit
13+
14+
!$omp declare mapper(t1::x) map(x, x%y)
15+
!$omp declare mapper(t2::w) map(w, w%y, w%z)
16+
end

0 commit comments

Comments
 (0)