[clang] [OpenMP] Fix crash with extern reference and diagnose loop variable reuse in collapsed loops. (PR #203252)

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 13 12:45:41 PDT 2026


================
@@ -8462,6 +8466,19 @@ bool OpenMPIterationSpaceChecker::checkAndSetInit(Stmt *S, bool EmitDiags) {
     }
   }
 
+  // Helper lambda to check if a loop variable is already used in an outer
+  // loop.
+  auto CheckLoopVarReuse = [&](ValueDecl *LoopVar, SourceLocation Loc) -> bool {
+    if (!CollapsedLoopInductionVars.empty() &&
+        CollapsedLoopInductionVars.count(LoopVar->getCanonicalDecl()) &&
+        EmitDiags) {
----------------
alexey-bataev wrote:

```suggestion
    if (EmitDiags &&
        CollapsedLoopInductionVars.contains(LoopVar->getCanonicalDecl())) {
```

https://github.com/llvm/llvm-project/pull/203252


More information about the cfe-commits mailing list