[clang] [Clang] Fix clang crash for fopenmp statement(parallel for) inside lambda function (PR #146772)

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 2 13:46:35 PDT 2025


================
@@ -2332,6 +2332,12 @@ void CodeGenFunction::EmitOMPPrivateLoopCounters(
   for (const Expr *E : S.counters()) {
     const auto *VD = cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl());
     const auto *PrivateVD = cast<VarDecl>(cast<DeclRefExpr>(*I)->getDecl());
+    // Privatize original counter variable (e.g., __beginN, __endN, __rangeN)
+    if (!LocalDeclMap.count(VD)) {
+      Address Addr = CreateMemTemp(VD->getType(), VD->getName());
+      LocalDeclMap.insert({VD, Addr});
+      (void)LoopScope.addPrivate(VD, Addr);
+    }
----------------
alexey-bataev wrote:

I assume this is too broad. Why the original variables are not captured and privatized? Looks like we're missing some analysis

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


More information about the cfe-commits mailing list