================
@@ -18040,16 +18128,29 @@ StmtResult 
SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
           llvm::append_range(PreInits, TransformPreInit);
       }
 
-      FinalLoops.push_back(SeqAnalysis.Loops[I].TheForStmt);
+      // For out-of-range loop-transformations, emit their finalization inline
+      // right after the transformed loop so that IVs are restored as if the
+      // transformation had not been present (OpenMP 6.0 finalization rule).
+      Stmt *LoopStmt = SeqAnalysis.Loops[I].TheForStmt;
+      if (Stmt *LoopFinals = SeqAnalysis.Loops[I].TransformFinals)
+        LoopStmt = CompoundStmt::Create(Context, {LoopStmt, LoopFinals},
+                                        FPOptionsOverride(), SourceLocation(),
+                                        SourceLocation());
+      FinalLoops.push_back(LoopStmt);
     }
----------------
zahiraam wrote:

Fixed. Added your example to `loop_transform_iv.c` and a runtime test, 
`transform/fuse/nested-looprange-reverse.c`.
  
  This  https://godbolt.org/z/o9xr1aGaf crashes on `main` without this PR. 
Suggesting to fix this in a subsequent PR?

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

Reply via email to