================
@@ -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.
+        }
----------------
alexey-bataev wrote:

Skipping duplicate captures means the resulting `CapturedStmt` has fewer 
captures than `RSI->Captures` originally tracked. AST consumers (template 
instantiation, AST dumpers, source-to-source rewriters, libTooling clients) 
that walk `S.captures()` in lockstep with the original tracked bindings will be 
off by one or more. Verify this is safe for existing template instantiation 
paths (e.g. a function template that captures a binding pair in OpenMP, 
instantiated multiple times) and add a regression test.

https://github.com/llvm/llvm-project/pull/190832
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to