xgupta wrote:

I tried debugging this with logs. It is __begin2 which is not present in the 
map. 

```
/// Private scope for OpenMP loop-based directives, that supports capturing
/// of used expression from loop statement.
class OMPLoopScope : public CodeGenFunction::RunCleanupsScope {
  void emitPreInitStmt(CodeGenFunction &CGF, const OMPLoopBasedDirective &S) {
    const Stmt *PreInits;
    CodeGenFunction::OMPMapVars PreCondVars;
    if (auto *LD = dyn_cast<OMPLoopDirective>(&S)) {
      llvm::DenseSet<const VarDecl *> EmittedAsPrivate;
      for (const auto *E : LD->counters()) {
        const auto *VD = cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl());
        EmittedAsPrivate.insert(VD->getCanonicalDecl());
        (void)PreCondVars.setVarAddr(
            CGF, VD, CGF.CreateMemTemp(VD->getType().getNonReferenceType()));
      }
      // Mark private vars as undefs.
      for (const auto *C : LD->getClausesOfKind<OMPPrivateClause>()) {
        for (const Expr *IRef : C->varlist()) {
          const auto *OrigVD =
              cast<VarDecl>(cast<DeclRefExpr>(IRef)->getDecl());
          if (EmittedAsPrivate.insert(OrigVD->getCanonicalDecl()).second) {
            QualType OrigVDTy = OrigVD->getType().getNonReferenceType();
            (void)PreCondVars.setVarAddr(
                CGF, OrigVD,
                Address(llvm::UndefValue::get(CGF.ConvertTypeForMem(
                            CGF.getContext().getPointerType(OrigVDTy))),
                        CGF.ConvertTypeForMem(OrigVDTy),
                        CGF.getContext().getDeclAlign(OrigVD)));
          }
        }
      }
      (void)PreCondVars.apply(CGF);
      // Emit init, __range and __end variables for C++ range loops.

      (void)OMPLoopBasedDirective::doForAllLoops(
          LD->getInnermostCapturedStmt()->getCapturedStmt(),
          /*TryImperfectlyNestedLoops=*/true, LD->getLoopsNumber(),
          [&CGF](unsigned Cnt, const Stmt *CurStmt) {
            if (const auto *CXXFor = dyn_cast<CXXForRangeStmt>(CurStmt)) {

              if (const Stmt *Init = CXXFor->getInit())
                CGF.EmitStmt(Init);
              CGF.EmitStmt(CXXFor->getRangeStmt());
              CGF.EmitStmt(CXXFor->getEndStmt());
            }
            return false;
          });
      PreInits = LD->getPreInits();
    } else if (const auto *Tile = dyn_cast<OMPTileDirective>(&S)) {
      PreInits = Tile->getPreInits();
    } else if (const auto *Stripe = dyn_cast<OMPStripeDirective>(&S)) {
      PreInits = Stripe->getPreInits();
    } else if (const auto *Unroll = dyn_cast<OMPUnrollDirective>(&S)) {
      PreInits = Unroll->getPreInits();
    } else if (const auto *Reverse = dyn_cast<OMPReverseDirective>(&S)) {
      PreInits = Reverse->getPreInits();
    } else if (const auto *Interchange =
                   dyn_cast<OMPInterchangeDirective>(&S)) {
      PreInits = Interchange->getPreInits();
    } else {
      llvm_unreachable("Unknown loop-based directive kind.");
    }
    doEmitPreinits(PreInits);
    PreCondVars.restore(CGF);
  }
```

In one iteration __begin2 was added in map but removed in 
restore(https://github.com/xgupta/llvm-project/blob/25ea9206993134e1e93e840f3391aa35204a5204/clang/lib/CodeGen/CodeGenFunction.h#L1181C1-L1186C6)
`
--- LocalDeclMap @ restore(entry) ---
  r -> VALID
  __begin2 -> VALID
  .capture_expr. -> VALID
  .capture_expr. -> VALID
  .capture_expr. -> VALID
  .omp.iv -> VALID
  this -> VALID
  __range2 -> VALID
  __end2 -> VALID

--- LocalDeclMap @ restore(exit0) ---
  r -> VALID
  .capture_expr. -> VALID
  .capture_expr. -> VALID
  .capture_expr. -> VALID
  .omp.iv -> VALID
  this -> VALID
  __range2 -> VALID
  __end2 -> VALID
`

and in another iteration two __begin2 added up in apply but removed from in 
restore
`
--- LocalDeclMap @ restore(entry) ---
  r -> VALID
  __begin2 -> VALID
  .capture_expr. -> VALID
  .capture_expr. -> VALID
  .capture_expr. -> VALID
  .omp.iv -> VALID
  this -> VALID
  __begin2 -> VALID
  __range2 -> VALID
  __end2 -> VALID

--- LocalDeclMap @ restore(exit0) ---
  r -> VALID
  .capture_expr. -> VALID
  .capture_expr. -> VALID
  .capture_expr. -> VALID
  .omp.iv -> VALID
  this -> VALID
  __range2 -> VALID
  __end2 -> VALID
`
which causes it to not found in LocalDeclMap.


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

Reply via email to