Skip to content
6 changes: 4 additions & 2 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -9475,15 +9475,17 @@ class ConstOMPClauseVisitor :
class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
raw_ostream &OS;
const PrintingPolicy &Policy;
unsigned Version;

/// Process clauses with list of variables.
template <typename T> void VisitOMPClauseList(T *Node, char StartSym);
/// Process motion clauses.
template <typename T> void VisitOMPMotionClause(T *Node);

public:
OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
: OS(OS), Policy(Policy) {}
OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy,
unsigned OpenMPVersion)
: OS(OS), Policy(Policy), Version(OpenMPVersion) {}

#define GEN_CLANG_CLAUSE_CLASS
#define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S);
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/AST/DeclPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
Out << ")";
}
if (!D->clauselist_empty()) {
OMPClausePrinter Printer(Out, Policy);
OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
for (OMPClause *C : D->clauselists()) {
Out << " ";
Printer.Visit(C);
Expand All @@ -1838,7 +1838,7 @@ void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
void DeclPrinter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
Out << "#pragma omp requires ";
if (!D->clauselist_empty()) {
OMPClausePrinter Printer(Out, Policy);
OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
for (auto I = D->clauselist_begin(), E = D->clauselist_end(); I != E; ++I)
Printer.Visit(*I);
}
Expand Down Expand Up @@ -1891,7 +1891,7 @@ void DeclPrinter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
Out << D->getVarName();
Out << ")";
if (!D->clauselist_empty()) {
OMPClausePrinter Printer(Out, Policy);
OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
for (auto *C : D->clauselists()) {
Out << " ";
Printer.Visit(C);
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/AST/OpenMPClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ OMPThreadLimitClause *OMPThreadLimitClause::CreateEmpty(const ASTContext &C,
void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
OS << "if(";
if (Node->getNameModifier() != OMPD_unknown)
OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
OS << getOpenMPDirectiveName(Node->getNameModifier(), Version) << ": ";
Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
OS << ")";
}
Expand Down Expand Up @@ -2049,7 +2049,7 @@ void OMPClausePrinter::VisitOMPAbsentClause(OMPAbsentClause *Node) {
for (auto &D : Node->getDirectiveKinds()) {
if (!First)
OS << ", ";
OS << getOpenMPDirectiveName(D);
OS << getOpenMPDirectiveName(D, Version);
First = false;
}
OS << ")";
Expand All @@ -2067,7 +2067,7 @@ void OMPClausePrinter::VisitOMPContainsClause(OMPContainsClause *Node) {
for (auto &D : Node->getDirectiveKinds()) {
if (!First)
OS << ", ";
OS << getOpenMPDirectiveName(D);
OS << getOpenMPDirectiveName(D, Version);
First = false;
}
OS << ")";
Expand Down
12 changes: 9 additions & 3 deletions clang/lib/AST/StmtPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,9 @@ void StmtPrinter::VisitOMPCanonicalLoop(OMPCanonicalLoop *Node) {

void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S,
bool ForceNoStmt) {
OMPClausePrinter Printer(OS, Policy);
unsigned OpenMPVersion =
Context ? Context->getLangOpts().OpenMP : llvm::omp::FallbackVersion;
OMPClausePrinter Printer(OS, Policy, OpenMPVersion);
ArrayRef<OMPClause *> Clauses = S->clauses();
for (auto *Clause : Clauses)
if (Clause && !Clause->isImplicit()) {
Expand Down Expand Up @@ -964,14 +966,18 @@ void StmtPrinter::VisitOMPTeamsDirective(OMPTeamsDirective *Node) {

void StmtPrinter::VisitOMPCancellationPointDirective(
OMPCancellationPointDirective *Node) {
unsigned OpenMPVersion =
Context ? Context->getLangOpts().OpenMP : llvm::omp::FallbackVersion;
Indent() << "#pragma omp cancellation point "
<< getOpenMPDirectiveName(Node->getCancelRegion());
<< getOpenMPDirectiveName(Node->getCancelRegion(), OpenMPVersion);
PrintOMPExecutableDirective(Node);
}

void StmtPrinter::VisitOMPCancelDirective(OMPCancelDirective *Node) {
unsigned OpenMPVersion =
Context ? Context->getLangOpts().OpenMP : llvm::omp::FallbackVersion;
Indent() << "#pragma omp cancel "
<< getOpenMPDirectiveName(Node->getCancelRegion());
<< getOpenMPDirectiveName(Node->getCancelRegion(), OpenMPVersion);
PrintOMPExecutableDirective(Node);
}

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Basic/OpenMPKinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,8 @@ void clang::getOpenMPCaptureRegions(
case OMPD_master:
return false;
default:
llvm::errs() << getOpenMPDirectiveName(LKind) << '\n';
llvm::errs() << getOpenMPDirectiveName(LKind, llvm::omp::FallbackVersion)
<< '\n';
llvm_unreachable("Unexpected directive");
}
return false;
Expand Down
Loading