Skip to content

[Flang][OpenMP] Add -fopenmp-default-none command line flag #120287

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3648,6 +3648,9 @@ def fopenmp_cuda_blocks_per_sm_EQ : Joined<["-"], "fopenmp-cuda-blocks-per-sm=">
Flags<[NoArgumentUnused, HelpHidden]>, Visibility<[ClangOption, CC1Option]>;
def fopenmp_cuda_teams_reduction_recs_num_EQ : Joined<["-"], "fopenmp-cuda-teams-reduction-recs-num=">, Group<f_Group>,
Flags<[NoArgumentUnused, HelpHidden]>, Visibility<[ClangOption, CC1Option]>;
def fopenmp_default_none : Flag<["-"], "fopenmp-default-none">, Group<f_Group>,
Visibility<[FlangOption, FC1Option]>,
HelpText<"Add DEFAULT(NONE) to all OpenMP directives that allow data-sharing clauses.">;

//===----------------------------------------------------------------------===//
// Shared cc1 + fc1 OpenMP Target Options
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
// is experimental.
D.Diag(diag::warn_openmp_experimental);

if (Args.hasArg((options::OPT_fopenmp_default_none)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (Args.hasArg((options::OPT_fopenmp_default_none)))
if (Args.hasArg(options::OPT_fopenmp_default_none))

nit: extra parentheses

CmdArgs.push_back("-fopenmp-default-none");

// FIXME: Clang supports a whole bunch more flags here.
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Common/Fortran-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
PolymorphicActualAllocatableOrPointerToMonomorphicDummy, RelaxedPureDummy,
UndefinableAsynchronousOrVolatileActual, AutomaticInMainProgram, PrintCptr,
SavedLocalInSpecExpr, PrintNamelist, AssumedRankPassedToNonAssumedRank,
IgnoreIrrelevantAttributes)
IgnoreIrrelevantAttributes, OpenMPDefaultNone)

// Portability and suspicious usage warnings
ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Common/Fortran-features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ LanguageFeatureControl::LanguageFeatureControl() {
disable_.set(LanguageFeature::OldDebugLines);
disable_.set(LanguageFeature::OpenACC);
disable_.set(LanguageFeature::OpenMP);
disable_.set(LanguageFeature::OpenMPDefaultNone);
disable_.set(LanguageFeature::CUDA); // !@cuf
disable_.set(LanguageFeature::CudaManaged);
disable_.set(LanguageFeature::CudaUnified);
Expand Down
4 changes: 4 additions & 0 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,10 @@ static bool parseOpenMPArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
res.getLangOpts().OpenMPVersion, diags)) {
res.getLangOpts().OpenMPVersion = Version;
}
if (args.hasArg(clang::driver::options::OPT_fopenmp_default_none)) {
res.getFrontendOpts().features.Enable(
Fortran::common::LanguageFeature::OpenMPDefaultNone);
}
if (args.hasArg(clang::driver::options::OPT_fopenmp_force_usm)) {
res.getLangOpts().OpenMPForceUSM = 1;
}
Expand Down
8 changes: 7 additions & 1 deletion flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,11 @@ void OmpAttributeVisitor::CreateImplicitSymbols(
void OmpAttributeVisitor::Post(const parser::Name &name) {
auto *symbol{name.symbol};

// if -fopenmp-default-none was given on the command line, act as if
// DEFAULT(NONE) was present at the directive.
bool haveOpenMPDefaultNone = context_.languageFeatures().IsEnabled(
common::LanguageFeature::OpenMPDefaultNone);

if (symbol && !dirContext_.empty() && GetContext().withinConstruct) {
if (IsPrivatizable(symbol) && !IsObjectWithDSA(*symbol)) {
// TODO: create a separate function to go through the rules for
Expand All @@ -2276,7 +2281,8 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
if (Symbol * found{currScope().FindSymbol(name.source)}) {
if (symbol != found) {
name.symbol = found; // adjust the symbol within region
} else if (GetContext().defaultDSA == Symbol::Flag::OmpNone &&
} else if ((haveOpenMPDefaultNone ||
GetContext().defaultDSA == Symbol::Flag::OmpNone) &&
!symbol->test(Symbol::Flag::OmpThreadprivate) &&
// Exclude indices of sequential loops that are privatised in
// the scope of the parallel region, and not in this scope.
Expand Down
34 changes: 34 additions & 0 deletions flang/test/Semantics/OpenMP/resolve07.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-default-none


! Test that -fopenmp-default-none shows the same errors as DEFAULT(NONE)
subroutine default_none()
integer a(3)
integer, parameter :: D=10
A = 1
B = 2
!$omp parallel private(c)
!ERROR: The DEFAULT(NONE) clause requires that 'a' must be listed in a data-sharing attribute clause
A(1:2) = 3
!ERROR: The DEFAULT(NONE) clause requires that 'b' must be listed in a data-sharing attribute clause
B = 4
C = 5 + D
!$omp end parallel
end subroutine default_none

! Test that indices of sequential loops are privatised and hence do not error
! for -fopenmp-default-none.
subroutine default_none_seq_loop
integer :: i

!$omp parallel do
do i = 1, 10
do j = 1, 20
enddo
enddo
end subroutine

program mm
call default_none()
call default_none_seq_loop()
Comment on lines +32 to +33
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to add a test for a construct that doesn't support data-sharing clauses, such as workshare, to make sure no error is reported.

end
Loading