Skip to content

Commit de1ea78

Browse files
authored
[OpenMP] Move unsupported structured bindings diagnostic (#80216)
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.
1 parent 87e04b4 commit de1ea78

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19528,16 +19528,6 @@ static bool captureInLambda(LambdaScopeInfo *LSI, ValueDecl *Var,
1952819528
ByRef = (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref);
1952919529
}
1953019530

19531-
BindingDecl *BD = dyn_cast<BindingDecl>(Var);
19532-
// FIXME: We should support capturing structured bindings in OpenMP.
19533-
if (!Invalid && BD && S.LangOpts.OpenMP) {
19534-
if (BuildAndDiagnose) {
19535-
S.Diag(Loc, diag::err_capture_binding_openmp) << Var;
19536-
S.Diag(Var->getLocation(), diag::note_entity_declared_at) << Var;
19537-
}
19538-
Invalid = true;
19539-
}
19540-
1954119531
if (BuildAndDiagnose && S.Context.getTargetInfo().getTriple().isWasm() &&
1954219532
CaptureType.getNonReferenceType().isWebAssemblyReferenceType()) {
1954319533
S.Diag(Loc, diag::err_wasm_ca_reference) << 0;
@@ -19879,6 +19869,14 @@ bool Sema::tryCaptureVariable(
1987919869
// just break here. Similarly, global variables that are captured in a
1988019870
// target region should not be captured outside the scope of the region.
1988119871
if (RSI->CapRegionKind == CR_OpenMP) {
19872+
// FIXME: We should support capturing structured bindings in OpenMP.
19873+
if (isa<BindingDecl>(Var)) {
19874+
if (BuildAndDiagnose) {
19875+
Diag(ExprLoc, diag::err_capture_binding_openmp) << Var;
19876+
Diag(Var->getLocation(), diag::note_entity_declared_at) << Var;
19877+
}
19878+
return true;
19879+
}
1988219880
OpenMPClauseKind IsOpenMPPrivateDecl = isOpenMPPrivateDecl(
1988319881
Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel);
1988419882
// If the variable is private (i.e. not captured) and has variably
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1-
21
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -fopenmp %s
32

4-
// FIXME: OpenMP should support capturing structured bindings
3+
// Okay, not an OpenMP capture.
54
auto f() {
65
int i[2] = {};
7-
auto [a, b] = i; // expected-note 2{{declared here}}
6+
auto [a, b] = i;
87
return [=, &a] {
9-
// expected-error@-1 {{capturing a structured binding is not yet supported in OpenMP}}
108
return a + b;
11-
// expected-error@-1 {{capturing a structured binding is not yet supported in OpenMP}}
129
};
1310
}
11+
12+
// Okay, not an OpenMP capture.
13+
void foo(int);
14+
void g() {
15+
#pragma omp parallel
16+
{
17+
int i[2] = {};
18+
auto [a, b] = i;
19+
auto L = [&] { foo(a+b); };
20+
}
21+
}
22+
23+
// FIXME: OpenMP should support capturing structured bindings
24+
void h() {
25+
int i[2] = {};
26+
auto [a, b] = i; // expected-note 2{{declared here}}
27+
#pragma omp parallel
28+
{
29+
// expected-error@+1 2{{capturing a structured binding is not yet supported in OpenMP}}
30+
foo(a + b);
31+
}
32+
}

0 commit comments

Comments
 (0)