Skip to content

Commit f852e36

Browse files
committed
Fix semantic check for default declare mappers.
1 parent 7cf2860 commit f852e36

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "flang/Semantics/type.h"
3939
#include "flang/Support/Fortran.h"
4040
#include "flang/Support/default-kinds.h"
41+
#include "llvm/ADT/SmallVector.h"
4142
#include "llvm/Support/raw_ostream.h"
4243
#include <list>
4344
#include <map>
@@ -1766,14 +1767,6 @@ void OmpVisitor::ProcessMapperSpecifier(const parser::OmpMapperSpecifier &spec,
17661767
// just following the natural flow, the map clauses gets processed before
17671768
// the type has been fully processed.
17681769
BeginDeclTypeSpec();
1769-
if (auto &mapperName{std::get<std::optional<parser::Name>>(spec.t)}) {
1770-
mapperName->symbol =
1771-
&MakeSymbol(*mapperName, MiscDetails{MiscDetails::Kind::ConstructName});
1772-
} else {
1773-
const parser::CharBlock defaultName{"default", 7};
1774-
MakeSymbol(
1775-
defaultName, Attrs{}, MiscDetails{MiscDetails::Kind::ConstructName});
1776-
}
17771770

17781771
PushScope(Scope::Kind::OtherConstruct, nullptr);
17791772
Walk(std::get<parser::TypeSpec>(spec.t));
@@ -1783,6 +1776,18 @@ void OmpVisitor::ProcessMapperSpecifier(const parser::OmpMapperSpecifier &spec,
17831776
Walk(clauses);
17841777
EndDeclTypeSpec();
17851778
PopScope();
1779+
1780+
if (auto &mapperName{std::get<std::optional<parser::Name>>(spec.t)}) {
1781+
mapperName->symbol =
1782+
&MakeSymbol(*mapperName, MiscDetails{MiscDetails::Kind::ConstructName});
1783+
} else {
1784+
const auto &type = std::get<parser::TypeSpec>(spec.t);
1785+
static llvm::SmallVector<std::string> defaultNames;
1786+
defaultNames.emplace_back(
1787+
type.declTypeSpec->derivedTypeSpec().name().ToString() + ".default");
1788+
MakeSymbol(defaultNames.back(), Attrs{},
1789+
MiscDetails{MiscDetails::Kind::ConstructName});
1790+
}
17861791
}
17871792

17881793
void OmpVisitor::ProcessReductionSpecifier(

flang/test/Semantics/OpenMP/declare-mapper-symbols.f90

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
program main
44
!CHECK-LABEL: MainProgram scope: main
5-
implicit none
5+
implicit none
66

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)
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)
1212

1313
!! Note, symbols come out in their respective scope, but not in declaration order.
14-
!CHECK: default: Misc ConstructName
1514
!CHECK: mymapper: Misc ConstructName
1615
!CHECK: ty: DerivedType components: x
16+
!CHECK: ty.default: Misc ConstructName
1717
!CHECK: DerivedType scope: ty
1818
!CHECK: OtherConstruct scope:
1919
!CHECK: mapped (OmpMapToFrom) {{.*}} ObjectEntity type: TYPE(ty)
20-
!CHECK: OtherConstruct scope:
20+
!CHECK: OtherConstruct scope:
2121
!CHECK: maptwo (OmpMapToFrom) {{.*}} ObjectEntity type: TYPE(ty)
22-
22+
2323
end program main
2424

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
integer :: y
66
end type t1
77

8-
type :: t2
9-
real :: y, z
10-
end type t2
11-
128
!error: 'default' is already declared in this scoping unit
139

1410
!$omp declare mapper(t1::x) map(x, x%y)
15-
!$omp declare mapper(t2::w) map(w, w%y, w%z)
11+
!$omp declare mapper(t1::x) map(x)
1612
end

0 commit comments

Comments
 (0)