Skip to content

Commit

Permalink
[OpenMP] Move unsupported structured bindings diagnostic (#80216)
Browse files Browse the repository at this point in the history
Move the diagnostic so it fires only when doing an OpenMP capture, not
for non-OpenMP captures. This allows non-OpenMP code to work when using
OpenMP elsewhere, such as the code reported in
#66999.
  • Loading branch information
mikerice1969 committed Feb 1, 2024
1 parent 87e04b4 commit de1ea78
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
18 changes: 8 additions & 10 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19528,16 +19528,6 @@ static bool captureInLambda(LambdaScopeInfo *LSI, ValueDecl *Var,
ByRef = (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref);
}

BindingDecl *BD = dyn_cast<BindingDecl>(Var);
// FIXME: We should support capturing structured bindings in OpenMP.
if (!Invalid && BD && S.LangOpts.OpenMP) {
if (BuildAndDiagnose) {
S.Diag(Loc, diag::err_capture_binding_openmp) << Var;
S.Diag(Var->getLocation(), diag::note_entity_declared_at) << Var;
}
Invalid = true;
}

if (BuildAndDiagnose && S.Context.getTargetInfo().getTriple().isWasm() &&
CaptureType.getNonReferenceType().isWebAssemblyReferenceType()) {
S.Diag(Loc, diag::err_wasm_ca_reference) << 0;
Expand Down Expand Up @@ -19879,6 +19869,14 @@ bool Sema::tryCaptureVariable(
// just break here. Similarly, global variables that are captured in a
// target region should not be captured outside the scope of the region.
if (RSI->CapRegionKind == CR_OpenMP) {
// FIXME: We should support capturing structured bindings in OpenMP.
if (isa<BindingDecl>(Var)) {
if (BuildAndDiagnose) {
Diag(ExprLoc, diag::err_capture_binding_openmp) << Var;
Diag(Var->getLocation(), diag::note_entity_declared_at) << Var;
}
return true;
}
OpenMPClauseKind IsOpenMPPrivateDecl = isOpenMPPrivateDecl(
Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel);
// If the variable is private (i.e. not captured) and has variably
Expand Down
29 changes: 24 additions & 5 deletions clang/test/SemaCXX/decomposition-openmp.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@

// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -fopenmp %s

// FIXME: OpenMP should support capturing structured bindings
// Okay, not an OpenMP capture.
auto f() {
int i[2] = {};
auto [a, b] = i; // expected-note 2{{declared here}}
auto [a, b] = i;
return [=, &a] {
// expected-error@-1 {{capturing a structured binding is not yet supported in OpenMP}}
return a + b;
// expected-error@-1 {{capturing a structured binding is not yet supported in OpenMP}}
};
}

// Okay, not an OpenMP capture.
void foo(int);
void g() {
#pragma omp parallel
{
int i[2] = {};
auto [a, b] = i;
auto L = [&] { foo(a+b); };
}
}

// FIXME: OpenMP should support capturing structured bindings
void h() {
int i[2] = {};
auto [a, b] = i; // expected-note 2{{declared here}}
#pragma omp parallel
{
// expected-error@+1 2{{capturing a structured binding is not yet supported in OpenMP}}
foo(a + b);
}
}

0 comments on commit de1ea78

Please sign in to comment.