================
@@ -15033,6 +15033,48 @@ static Expr *makeFloorIVRef(Sema &SemaRef, 
ArrayRef<VarDecl *> FloorIndVars,
                           OrigCntVar->getExprLoc());
 }
 
+/// Build loop variable finalization statement from HelperExprs.Finals.
+/// Returns a CompoundStmt containing all finalization statements, or nullptr
+/// if there are no finalization statements.
+/// Note: Loops with non-arithmetic loop variables (e.g., iterators) are 
skipped
+/// because finalization only applies to integer/floating-point counters.
+static Stmt *
+buildLoopFinalization(ASTContext &Context,
+                      ArrayRef<OMPLoopBasedDirective::HelperExprs> LoopHelpers,
+                      ArrayRef<Stmt *> LoopStmts) {
+  assert(LoopHelpers.size() == LoopStmts.size() &&
+         "LoopHelpers and LoopStmts must have the same size");
+  SmallVector<Stmt *, 8> FinalizationStmts;
+  for (const auto &[Helper, LoopStmt] : llvm::zip(LoopHelpers, LoopStmts)) {
+    // Skip finalization for range-based for loops (CXXForRangeStmt) since
+    // their loop variables are iterators, not integer counters.
+    if (isa<CXXForRangeStmt>(LoopStmt))
+      continue;
+
+    // For ForStmt, check if the loop variable is arithmetic.
----------------
alexey-bataev wrote:

Shall we restore for all datatypes, not only simple counters, but iterators too?

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

Reply via email to