================
@@ -4672,39 +4672,69 @@ static bool
buildCapturedStmtCaptureList(Sema &S, CapturedRegionScopeInfo *RSI,
SmallVectorImpl<CapturedStmt::Capture> &Captures,
SmallVectorImpl<Expr *> &CaptureInits) {
+ llvm::SmallPtrSet<VarDecl *, 4> CapturedDecomposed;
for (const sema::Capture &Cap : RSI->Captures) {
if (Cap.isInvalid())
continue;
+ ValueDecl *CapVar = nullptr;
+ if (Cap.isVariableCapture()) {
+ CapVar = Cap.getVariable();
+ if (auto *BD = dyn_cast<BindingDecl>(CapVar)) {
+ VarDecl *DD = cast<VarDecl>(BD->getDecomposedDecl());
+ if (!CapturedDecomposed.insert(DD).second) {
+ continue; // Skip duplicate.
+ }
+ CapVar = DD;
+ }
+ }
+
// Form the initializer for the capture.
ExprResult Init = S.BuildCaptureInit(Cap, Cap.getLocation(),
RSI->CapRegionKind == CR_OpenMP);
// FIXME: Bail out now if the capture is not used and the initializer has
// no side-effects.
- // Create a field for this capture.
- FieldDecl *Field = S.BuildCaptureField(RSI->TheRecordDecl, Cap);
+ // Build the capture field. For OpenMP BindingDecl captures redirected
+ // to their DecompositionDecl, the field type must use the
+ // DecompositionDecl's type (e.g. int[2]) not the BindingDecl's type (e.g.
+ // int).
+ FieldDecl *Field = nullptr;
+ if (RSI->CapRegionKind == CR_OpenMP && CapVar &&
+ CapVar != Cap.getVariable() && isa<DecompositionDecl>(CapVar)) {
+ // Manually build a reference field with the DecompositionDecl's type.
+ QualType DDType = cast<VarDecl>(CapVar)->getType();
+ QualType RefType = S.Context.getLValueReferenceType(DDType);
+ TypeSourceInfo *TSI =
+ S.Context.getTrivialTypeSourceInfo(RefType, Cap.getLocation());
+ Field = FieldDecl::Create(S.Context, RSI->TheRecordDecl,
+ Cap.getLocation(), Cap.getLocation(),
+ /*Id=*/nullptr, RefType, TSI,
+ /*BW=*/nullptr, /*Mutable=*/false,
ICIS_NoInit);
+ Field->setImplicit(true);
+ Field->setAccess(AS_private);
+ RSI->TheRecordDecl->addDecl(Field);
----------------
alexey-bataev wrote:
Why not just `Field = S.BuildCaptureField(CapVar, Cap);`
https://github.com/llvm/llvm-project/pull/190832
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits