Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,12 @@ class OMPDefaultClause : public OMPClause {
/// Start location of the kind in source code.
SourceLocation KindKwLoc;

/// Variable-Category to indicate where Kind is applied
OpenMPDefaultClauseVariableCategory VC = OMPC_DEFAULT_VC_all;

/// Start location of Variable-Category
SourceLocation VCLoc;

/// Set kind of the clauses.
///
/// \param K Argument of clause.
Expand All @@ -1279,6 +1285,15 @@ class OMPDefaultClause : public OMPClause {
/// \param KLoc Argument location.
void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }

/// Set Variable Category used with the Kind Clause (Default Modifier)
void setDefaultVariableCategory(OpenMPDefaultClauseVariableCategory VC) {
this->VC = VC;
}

void setDefaultVariableCategoryLocation(SourceLocation VCLoc) {
this->VCLoc = VCLoc;
}

public:
/// Build 'default' clause with argument \a A ('none' or 'shared').
///
Expand All @@ -1288,10 +1303,11 @@ class OMPDefaultClause : public OMPClause {
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
OpenMPDefaultClauseVariableCategory VC, SourceLocation VCLoc,
SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc)
: OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc), VC(VC), VCLoc(VCLoc) {}

/// Build an empty clause.
OMPDefaultClause()
Expand All @@ -1310,6 +1326,10 @@ class OMPDefaultClause : public OMPClause {
/// Returns location of clause kind.
SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }

OpenMPDefaultClauseVariableCategory getDefaultVC() { return VC; }

SourceLocation getDefaultVCLoc() { return VCLoc; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OpenMPDefaultClauseVariableCategory getDefaultVC() { return VC; }
SourceLocation getDefaultVCLoc() { return VCLoc; }
OpenMPDefaultClauseVariableCategory getDefaultVC() const { return VC; }
SourceLocation getDefaultVCLoc() const { return VCLoc; }


child_range children() {
return child_range(child_iterator(), child_iterator());
}
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11714,6 +11714,8 @@ def note_omp_default_dsa_none : Note<
"explicit data sharing attribute requested here">;
def note_omp_defaultmap_attr_none : Note<
"explicit data sharing attribute, data mapping attribute, or is_device_ptr clause requested here">;
def err_omp_default_vc : Error<
"wrong variable category specified with modifier %0 in the default clause">;
def err_omp_wrong_dsa : Error<
"%0 variable cannot be %1">;
def err_omp_variably_modified_type_not_supported : Error<
Expand Down
11 changes: 11 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#ifndef OPENMP_DIST_SCHEDULE_KIND
#define OPENMP_DIST_SCHEDULE_KIND(Name)
#endif
#ifndef OPENMP_DEFAULT_VARIABLE_CATEGORY
#define OPENMP_DEFAULT_VARIABLE_CATEGORY(Name)
#endif
#ifndef OPENMP_DEFAULTMAP_KIND
#define OPENMP_DEFAULTMAP_KIND(Name)
#endif
Expand Down Expand Up @@ -112,6 +115,13 @@ OPENMP_SCHEDULE_MODIFIER(simd)
OPENMP_DEVICE_MODIFIER(ancestor)
OPENMP_DEVICE_MODIFIER(device_num)

// Variable-category attributes for 'default' clause.
OPENMP_DEFAULT_VARIABLE_CATEGORY(aggregate)
OPENMP_DEFAULT_VARIABLE_CATEGORY(all)
OPENMP_DEFAULT_VARIABLE_CATEGORY(allocatable)
OPENMP_DEFAULT_VARIABLE_CATEGORY(pointer)
OPENMP_DEFAULT_VARIABLE_CATEGORY(scalar)

// Static attributes for 'defaultmap' clause.
OPENMP_DEFAULTMAP_KIND(scalar)
OPENMP_DEFAULTMAP_KIND(aggregate)
Expand Down Expand Up @@ -267,6 +277,7 @@ OPENMP_DOACROSS_MODIFIER(source_omp_cur_iteration)
#undef OPENMP_MAP_MODIFIER_KIND
#undef OPENMP_MOTION_MODIFIER_KIND
#undef OPENMP_DIST_SCHEDULE_KIND
#undef OPENMP_DEFAULT_VARIABLE_CATEGORY
#undef OPENMP_DEFAULTMAP_KIND
#undef OPENMP_DEFAULTMAP_MODIFIER
#undef OPENMP_DOACROSS_MODIFIER
Expand Down
11 changes: 11 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ enum OpenMPDistScheduleClauseKind {
OMPC_DIST_SCHEDULE_unknown
};

/// OpenMP variable-category for 'default' clause.
enum OpenMPDefaultClauseVariableCategory {
#define OPENMP_DEFAULT_VARIABLE_CATEGORY(Name) OMPC_DEFAULT_VC_##Name,
#include "clang/Basic/OpenMPKinds.def"
OMPC_DEFAULT_VC_unknown
};

/// OpenMP attributes for 'defaultmap' clause.
enum OpenMPDefaultmapClauseKind {
#define OPENMP_DEFAULTMAP_KIND(Name) \
Expand Down Expand Up @@ -257,6 +264,10 @@ struct OMPInteropInfo final {
llvm::SmallVector<Expr *, 4> PreferTypes;
};

OpenMPDefaultClauseVariableCategory
getOpenMPDefaultVariableCategory(StringRef Str, const LangOptions &LangOpts);
const char *getOpenMPDefaultVariableCategoryName(unsigned VC);

unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str,
const LangOptions &LangOpts);
const char *getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type);
Expand Down
10 changes: 5 additions & 5 deletions clang/include/clang/Sema/SemaOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -951,11 +951,11 @@ class SemaOpenMP : public SemaBase {
SourceLocation LParenLoc,
SourceLocation EndLoc);
/// Called on well-formed 'default' clause.
OMPClause *ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind,
SourceLocation KindLoc,
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc);
OMPClause *
ActOnOpenMPDefaultClause(llvm::omp::DefaultKind M, SourceLocation MLoc,
OpenMPDefaultClauseVariableCategory VCKind,
SourceLocation VCKindLoc, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation EndLoc);
/// Called on well-formed 'proc_bind' clause.
OMPClause *ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind,
SourceLocation KindLoc,
Expand Down
9 changes: 7 additions & 2 deletions clang/lib/AST/OpenMPClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,8 +1911,13 @@ void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause *Node) {
void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
OS << "default("
<< getOpenMPSimpleClauseTypeName(OMPC_default,
unsigned(Node->getDefaultKind()))
<< ")";
unsigned(Node->getDefaultKind()));
if (Version >= 60 && Node->getDefaultVC() != OMPC_DEFAULT_VC_all) {
OS << ":"
<< getOpenMPDefaultVariableCategoryName(unsigned(Node->getDefaultVC()));
}

OS << ")";
}

void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
Expand Down
21 changes: 20 additions & 1 deletion clang/lib/Basic/OpenMPKinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@
using namespace clang;
using namespace llvm::omp;

OpenMPDefaultClauseVariableCategory
clang::getOpenMPDefaultVariableCategory(StringRef Str,
const LangOptions &LangOpts) {
return llvm::StringSwitch<OpenMPDefaultClauseVariableCategory>(Str)
#define OPENMP_DEFAULT_VARIABLE_CATEGORY(Name) \
.Case(#Name, OMPC_DEFAULT_VC_##Name)
#include "clang/Basic/OpenMPKinds.def"
.Default(OMPC_DEFAULT_VC_unknown);
}

const char *clang::getOpenMPDefaultVariableCategoryName(unsigned VC) {
switch (VC) {
#define OPENMP_DEFAULT_VARIABLE_CATEGORY(Name) \
case OMPC_DEFAULT_VC_##Name: \
return #Name;
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid Variable Category in the default clause");
}

unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
const LangOptions &LangOpts) {
switch (Kind) {
Expand Down Expand Up @@ -896,4 +916,3 @@ bool clang::checkFailClauseParameter(OpenMPClauseKind FailClauseParameter) {
FailClauseParameter == llvm::omp::OMPC_relaxed ||
FailClauseParameter == llvm::omp::OMPC_seq_cst;
}

40 changes: 39 additions & 1 deletion clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3083,7 +3083,6 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective);
break;
case OMPC_fail:
case OMPC_default:
case OMPC_proc_bind:
case OMPC_atomic_default_mem_order:
case OMPC_at:
Expand Down Expand Up @@ -3115,6 +3114,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
case OMPC_schedule:
case OMPC_dist_schedule:
case OMPC_defaultmap:
case OMPC_default:
case OMPC_order:
// OpenMP [2.7.1, Restrictions, p. 3]
// Only one schedule clause can appear on a loop directive.
Expand Down Expand Up @@ -3734,6 +3734,32 @@ OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
ConsumeAnyToken();
if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma))
DelimLoc = ConsumeAnyToken();
} else if (Kind == OMPC_default) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a check for version 6.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is applicable for even versions before 6.0. Within this if there is another if statement at 3748 which has

if (Tok.is(tok::colon) && getLangOpts().OpenMP >= 60) { 
} else {
      Arg.push_back(OMPC_DEFAULT_VC_all);
      KLoc.push_back(SourceLocation());
}

The rest of the code below } else if (Kind == OMPC_default) { has been re-used. There is no need for a check for version 6.0 at 3737

// Get a default modifier
unsigned Modifier = getOpenMPSimpleClauseType(
Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok), getLangOpts());

Arg.push_back(Modifier);
KLoc.push_back(Tok.getLocation());
if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
Tok.isNot(tok::annot_pragma_openmp_end))
ConsumeAnyToken();
// Parse ':'
if (Tok.is(tok::colon) && getLangOpts().OpenMP >= 60) {
ConsumeAnyToken();
// Get a variable-category attribute for default clause modifier
OpenMPDefaultClauseVariableCategory VariableCategory =
getOpenMPDefaultVariableCategory(
Tok.isAnnotation() ? "" : PP.getSpelling(Tok), getLangOpts());
Arg.push_back(VariableCategory);
KLoc.push_back(Tok.getLocation());
if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
Tok.isNot(tok::annot_pragma_openmp_end))
ConsumeAnyToken();
} else {
Arg.push_back(OMPC_DEFAULT_VC_all);
KLoc.push_back(SourceLocation());
}
} else if (Kind == OMPC_defaultmap) {
// Get a defaultmap modifier
unsigned Modifier = getOpenMPSimpleClauseType(
Expand Down Expand Up @@ -3932,6 +3958,18 @@ OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
if (NeedAnExpression && Val.isInvalid())
return nullptr;

if (Kind == OMPC_default && getLangOpts().OpenMP < 51 && Arg[0] &&
(static_cast<DefaultKind>(Arg[0]) == OMP_DEFAULT_private ||
static_cast<DefaultKind>(Arg[0]) == OMP_DEFAULT_firstprivate)) {
Diag(KLoc[0], diag::err_omp_invalid_dsa)
<< getOpenMPClauseName(static_cast<DefaultKind>(Arg[0]) ==
OMP_DEFAULT_private
? OMPC_private
: OMPC_firstprivate)
<< getOpenMPClauseName(OMPC_default) << "5.1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<< getOpenMPClauseName(OMPC_default) << "5.1";
<< getOpenMPClauseName(OMPC_default) << "5.1";

5.1 is not always correct here, it may be 5.2 or 4.5

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the spec version 5.0 (for c/c++) , default clause has only shared or none as modifier (data-sharing attribute). After spec version 5.1, we see, shared | firstprivate | private | none as the attributes. Do you want me to override spec version 5.1 and mark it as 5.2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, I see, then keep it as is

return nullptr;
}

if (ParseOnly)
return nullptr;
return Actions.OpenMP().ActOnOpenMPSingleExprWithArgClause(
Expand Down
Loading