Skip to content

Commit 3acc691

Browse files
authored
Revert "Revert "[OpenMP][TR12] change property of map-type modifier."… (#91821)
… (#90885)" This reverts commit eea81aa.
1 parent 96ebed7 commit 3acc691

File tree

4 files changed

+165
-54
lines changed

4 files changed

+165
-54
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,13 +1438,18 @@ def err_omp_decl_in_declare_simd_variant : Error<
14381438
def err_omp_sink_and_source_iteration_not_allowd: Error<" '%0 %select{sink:|source:}1' must be with '%select{omp_cur_iteration - 1|omp_cur_iteration}1'">;
14391439
def err_omp_unknown_map_type : Error<
14401440
"incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'">;
1441+
def err_omp_more_one_map_type : Error<"map type is already specified">;
1442+
def note_previous_map_type_specified_here
1443+
: Note<"map type '%0' is previous specified here">;
14411444
def err_omp_unknown_map_type_modifier : Error<
14421445
"incorrect map type modifier, expected one of: 'always', 'close', 'mapper'"
14431446
"%select{|, 'present'|, 'present', 'iterator'}0%select{|, 'ompx_hold'}1">;
14441447
def err_omp_map_type_missing : Error<
14451448
"missing map type">;
14461449
def err_omp_map_type_modifier_missing : Error<
14471450
"missing map type modifier">;
1451+
def err_omp_map_modifier_specification_list : Error<
1452+
"empty modifier-specification-list is not allowed">;
14481453
def err_omp_declare_simd_inbranch_notinbranch : Error<
14491454
"unexpected '%0' clause, '%1' is specified already">;
14501455
def err_omp_expected_clause_argument

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4208,13 +4208,20 @@ bool Parser::parseMapperModifier(SemaOpenMP::OpenMPVarListDataTy &Data) {
42084208
return T.consumeClose();
42094209
}
42104210

4211+
static OpenMPMapClauseKind isMapType(Parser &P);
4212+
42114213
/// Parse map-type-modifiers in map clause.
4212-
/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list)
4214+
/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] [map-type] : ] list)
42134215
/// where, map-type-modifier ::= always | close | mapper(mapper-identifier) |
42144216
/// present
4217+
/// where, map-type ::= alloc | delete | from | release | to | tofrom
42154218
bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy &Data) {
4219+
bool HasMapType = false;
4220+
SourceLocation PreMapLoc = Tok.getLocation();
4221+
StringRef PreMapName = "";
42164222
while (getCurToken().isNot(tok::colon)) {
42174223
OpenMPMapModifierKind TypeModifier = isMapModifier(*this);
4224+
OpenMPMapClauseKind MapKind = isMapType(*this);
42184225
if (TypeModifier == OMPC_MAP_MODIFIER_always ||
42194226
TypeModifier == OMPC_MAP_MODIFIER_close ||
42204227
TypeModifier == OMPC_MAP_MODIFIER_present ||
@@ -4237,6 +4244,19 @@ bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy &Data) {
42374244
Diag(Data.MapTypeModifiersLoc.back(), diag::err_omp_missing_comma)
42384245
<< "map type modifier";
42394246

4247+
} else if (getLangOpts().OpenMP >= 60 && MapKind != OMPC_MAP_unknown) {
4248+
if (!HasMapType) {
4249+
HasMapType = true;
4250+
Data.ExtraModifier = MapKind;
4251+
MapKind = OMPC_MAP_unknown;
4252+
PreMapLoc = Tok.getLocation();
4253+
PreMapName = Tok.getIdentifierInfo()->getName();
4254+
} else {
4255+
Diag(Tok, diag::err_omp_more_one_map_type);
4256+
Diag(PreMapLoc, diag::note_previous_map_type_specified_here)
4257+
<< PreMapName;
4258+
}
4259+
ConsumeToken();
42404260
} else {
42414261
// For the case of unknown map-type-modifier or a map-type.
42424262
// Map-type is followed by a colon; the function returns when it
@@ -4247,8 +4267,14 @@ bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy &Data) {
42474267
continue;
42484268
}
42494269
// Potential map-type token as it is followed by a colon.
4250-
if (PP.LookAhead(0).is(tok::colon))
4251-
return false;
4270+
if (PP.LookAhead(0).is(tok::colon)) {
4271+
if (getLangOpts().OpenMP >= 60) {
4272+
break;
4273+
} else {
4274+
return false;
4275+
}
4276+
}
4277+
42524278
Diag(Tok, diag::err_omp_unknown_map_type_modifier)
42534279
<< (getLangOpts().OpenMP >= 51 ? (getLangOpts().OpenMP >= 52 ? 2 : 1)
42544280
: 0)
@@ -4258,6 +4284,14 @@ bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy &Data) {
42584284
if (getCurToken().is(tok::comma))
42594285
ConsumeToken();
42604286
}
4287+
if (getLangOpts().OpenMP >= 60 && !HasMapType) {
4288+
if (!Tok.is(tok::colon)) {
4289+
Diag(Tok, diag::err_omp_unknown_map_type);
4290+
ConsumeToken();
4291+
} else {
4292+
Data.ExtraModifier = OMPC_MAP_unknown;
4293+
}
4294+
}
42614295
return false;
42624296
}
42634297

@@ -4269,13 +4303,12 @@ static OpenMPMapClauseKind isMapType(Parser &P) {
42694303
if (!Tok.isOneOf(tok::identifier, tok::kw_delete))
42704304
return OMPC_MAP_unknown;
42714305
Preprocessor &PP = P.getPreprocessor();
4272-
OpenMPMapClauseKind MapType =
4273-
static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
4274-
OMPC_map, PP.getSpelling(Tok), P.getLangOpts()));
4306+
unsigned MapType =
4307+
getOpenMPSimpleClauseType(OMPC_map, PP.getSpelling(Tok), P.getLangOpts());
42754308
if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_from ||
42764309
MapType == OMPC_MAP_tofrom || MapType == OMPC_MAP_alloc ||
42774310
MapType == OMPC_MAP_delete || MapType == OMPC_MAP_release)
4278-
return MapType;
4311+
return static_cast<OpenMPMapClauseKind>(MapType);
42794312
return OMPC_MAP_unknown;
42804313
}
42814314

@@ -4659,8 +4692,10 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
46594692
// Only parse map-type-modifier[s] and map-type if a colon is present in
46604693
// the map clause.
46614694
if (ColonPresent) {
4695+
if (getLangOpts().OpenMP >= 60 && getCurToken().is(tok::colon))
4696+
Diag(Tok, diag::err_omp_map_modifier_specification_list);
46624697
IsInvalidMapperModifier = parseMapTypeModifiers(Data);
4663-
if (!IsInvalidMapperModifier)
4698+
if (getLangOpts().OpenMP < 60 && !IsInvalidMapperModifier)
46644699
parseMapType(*this, Data);
46654700
else
46664701
SkipUntil(tok::colon, tok::annot_pragma_openmp_end, StopBeforeMatch);

clang/test/OpenMP/target_ast_print.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,64 @@ foo();
12011201
}
12021202
#endif // OMP52
12031203

1204+
#ifdef OMP60
1205+
1206+
///==========================================================================///
1207+
// RUN: %clang_cc1 -DOMP60 -verify -Wno-vla -fopenmp -fopenmp-version=60 -ast-print %s | FileCheck %s --check-prefix OMP60
1208+
// RUN: %clang_cc1 -DOMP60 -fopenmp -fopenmp-version=60 -x c++ -std=c++11 -emit-pch -o %t %s
1209+
// RUN: %clang_cc1 -DOMP60 -fopenmp -fopenmp-version=60 -std=c++11 -include-pch %t -verify -Wno-vla %s -ast-print | FileCheck %s --check-prefix OMP60
1210+
1211+
// RUN: %clang_cc1 -DOMP60 -verify -Wno-vla -fopenmp-simd -fopenmp-version=60 -ast-print %s | FileCheck %s --check-prefix OMP60
1212+
// RUN: %clang_cc1 -DOMP60 -fopenmp-simd -fopenmp-version=60 -x c++ -std=c++11 -emit-pch -o %t %s
1213+
// RUN: %clang_cc1 -DOMP60 -fopenmp-simd -fopenmp-version=60 -std=c++11 -include-pch %t -verify -Wno-vla %s -ast-print | FileCheck %s --check-prefix OMP60
1214+
1215+
void foo() {}
1216+
template <typename T, int C>
1217+
T tmain(T argc, T *argv) {
1218+
T i;
1219+
#pragma omp target map(from always: i)
1220+
foo();
1221+
#pragma omp target map(from, close: i)
1222+
foo();
1223+
#pragma omp target map(always,close: i)
1224+
foo();
1225+
return 0;
1226+
}
1227+
//OMP60: template <typename T, int C> T tmain(T argc, T *argv) {
1228+
//OMP60-NEXT: T i;
1229+
//OMP60-NEXT: #pragma omp target map(always,from: i)
1230+
//OMP60-NEXT: foo();
1231+
//OMP60-NEXT: #pragma omp target map(close,from: i)
1232+
//OMP60-NEXT: foo();
1233+
//OMP60-NEXT: #pragma omp target map(always,close,tofrom: i)
1234+
//OMP60-NEXT: foo();
1235+
//OMP60-NEXT: return 0;
1236+
//OMP60-NEXT:}
1237+
//OMP60: template<> int tmain<int, 5>(int argc, int *argv) {
1238+
//OMP60-NEXT: int i;
1239+
//OMP60-NEXT: #pragma omp target map(always,from: i)
1240+
//OMP60-NEXT: foo();
1241+
//OMP60-NEXT: #pragma omp target map(close,from: i)
1242+
//OMP60-NEXT: foo();
1243+
//OMP60-NEXT: #pragma omp target map(always,close,tofrom: i)
1244+
//OMP60-NEXT: foo();
1245+
//OMP60-NEXT: return 0;
1246+
//OMP60-NEXT:}
1247+
//OMP60: template<> char tmain<char, 1>(char argc, char *argv) {
1248+
//OMP60-NEXT: char i;
1249+
//OMP60-NEXT: #pragma omp target map(always,from: i)
1250+
//OMP60-NEXT: foo();
1251+
//OMP60-NEXT: #pragma omp target map(close,from: i)
1252+
//OMP60-NEXT: foo();
1253+
//OMP60-NEXT: #pragma omp target map(always,close,tofrom: i)
1254+
//OMP60-NEXT: foo();
1255+
//OMP60-NEXT: return 0;
1256+
//OMP60-NEXT:}
1257+
int main (int argc, char **argv) {
1258+
return tmain<int, 5>(argc, &argc) + tmain<char, 1>(argv[0][0], argv[0]);
1259+
}
1260+
#endif // OMP60
1261+
12041262
#ifdef OMPX
12051263

12061264
// RUN: %clang_cc1 -DOMPX -verify -Wno-vla -fopenmp -fopenmp-extensions -ast-print %s | FileCheck %s --check-prefix=OMPX

0 commit comments

Comments
 (0)