Skip to content

[clang][OpenMP] Improve handling of non-C/C++ directives #139961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2613,9 +2613,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
Diag(Tok, diag::err_omp_unknown_directive);
return StmtError();
}
if (DKind == OMPD_workshare) {
// "workshare" is an executable, Fortran-only directive. Treat it
// as unknown.
if (!(getDirectiveLanguages(DKind) & SourceLanguage::C)) {
// Treat directives that are not allowed in C/C++ as unknown.
DKind = OMPD_unknown;
}

Expand Down
12 changes: 12 additions & 0 deletions clang/test/OpenMP/openmp_non_c_directives.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s

// Test the reaction to some Fortran-only directives.

void foo() {
#pragma omp allocators // expected-error {{expected an OpenMP directive}}
#pragma omp do // expected-error {{expected an OpenMP directive}}
#pragma omp end workshare // expected-error {{expected an OpenMP directive}}
#pragma omp parallel workshare // expected-warning {{extra tokens at the end of '#pragma omp parallel' are ignored}}
#pragma omp workshare // expected-error {{expected an OpenMP directive}}
}

8 changes: 0 additions & 8 deletions clang/test/OpenMP/openmp_workshare.c

This file was deleted.

6 changes: 6 additions & 0 deletions llvm/include/llvm/ADT/BitmaskEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
using ::llvm::BitmaskEnumDetail::operator^=; \
using ::llvm::BitmaskEnumDetail::operator<<=; \
using ::llvm::BitmaskEnumDetail::operator>>=; \
using ::llvm::BitmaskEnumDetail::operator!; \
/* Force a semicolon at the end of this macro. */ \
using ::llvm::BitmaskEnumDetail::any

Expand Down Expand Up @@ -141,6 +142,11 @@ constexpr unsigned bitWidth(uint64_t Value) {
return Value ? 1 + bitWidth(Value >> 1) : 0;
}

template <typename E, typename = std::enable_if_t<is_bitmask_enum<E>::value>>
constexpr bool operator!(E Val) {
return Val == static_cast<E>(0);
}

template <typename E, typename = std::enable_if_t<is_bitmask_enum<E>::value>>
constexpr bool any(E Val) {
return Val != static_cast<E>(0);
Expand Down
12 changes: 12 additions & 0 deletions llvm/include/llvm/Frontend/Directive/DirectiveBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ def CA_Meta: Category<"Meta"> {}
def CA_Subsidiary: Category<"Subsidiary"> {}
def CA_Utility: Category<"Utility"> {}

class SourceLanguage<string n> {
string name = n; // Name of the enum value in enum class Association.
}

// The C languages also implies C++ until there is a reason to add C++
// separately.
def L_C : SourceLanguage<"C"> {}
def L_Fortran : SourceLanguage<"Fortran"> {}

// Information about a specific directive.
class Directive<string d> {
// Name of the directive. Can be composite directive sepearted by whitespace.
Expand Down Expand Up @@ -205,4 +214,7 @@ class Directive<string d> {

// The category of the directive.
Category category = ?;

// The languages that allow this directive. Default: all languages.
list<SourceLanguage> languages = [L_C, L_Fortran];
}
Loading