================ @@ -5965,6 +5967,266 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema &SemaRef) { return Checker.teamsLoopCanBeParallelFor(); } +static Expr *getInitialExprFromCapturedExpr(Expr *Cond) { + + Expr *SubExpr = Cond->IgnoreParenImpCasts(); + + if (auto *DeclRef = dyn_cast<DeclRefExpr>(SubExpr)) { + if (auto *CapturedExprDecl = + dyn_cast<OMPCapturedExprDecl>(DeclRef->getDecl())) { + + // Retrieve the initial expression from the captured expression + return CapturedExprDecl->getInit(); + } + } + return nullptr; +} + +static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context, Expr *, + SemaOpenMP *, bool); + +/// cloneAssociatedStmt() function is for cloning the Associated Statement +/// present with a Directive and then modifying it. By this we avoid modifying +/// the original Associated Statement. +static StmtResult cloneAssociatedStmt(const ASTContext &Context, Stmt *StmtP, + SemaOpenMP *SemaPtr, bool NoContext) { + if (auto *AssocStmt = dyn_cast<CapturedStmt>(StmtP)) { + CapturedDecl *CDecl = AssocStmt->getCapturedDecl(); + Stmt *AssocExprStmt = AssocStmt->getCapturedStmt(); + auto *AssocExpr = dyn_cast<Expr>(AssocExprStmt); + Expr *NewCallOrPseudoObjOrBinExpr = replaceWithNewTraitsOrDirectCall( + Context, AssocExpr, SemaPtr, NoContext); + + // Copy Current Captured Decl to a New Captured Decl for noting the + // Annotation + CapturedDecl *NewDecl = + CapturedDecl::Create(const_cast<ASTContext &>(Context), + CDecl->getDeclContext(), CDecl->getNumParams()); + NewDecl->setBody(static_cast<Stmt *>(NewCallOrPseudoObjOrBinExpr)); + for (unsigned I : llvm::seq<unsigned>(CDecl->getNumParams())) { + if (I != CDecl->getContextParamPosition()) + NewDecl->setParam(I, CDecl->getParam(I)); + else + NewDecl->setContextParam(I, CDecl->getContextParam()); + } + + // Create a New Captured Stmt containing the New Captured Decl + SmallVector<CapturedStmt::Capture, 4> Captures; + SmallVector<Expr *, 4> CaptureInits; + for (const CapturedStmt::Capture &Capture : AssocStmt->captures()) + Captures.push_back(Capture); + for (Expr *CaptureInit : AssocStmt->capture_inits()) + CaptureInits.push_back(CaptureInit); + auto *NewStmt = CapturedStmt::Create( + Context, AssocStmt->getCapturedStmt(), + AssocStmt->getCapturedRegionKind(), Captures, CaptureInits, NewDecl, + const_cast<RecordDecl *>(AssocStmt->getCapturedRecordDecl())); + + return NewStmt; + } + return static_cast<Stmt *>(nullptr); ---------------- shiltian wrote:
I'm confused by this return. Why do you want to cast a `nullptr` to a `Stmt *`, and then implicit cast it to `StmtResult`? https://github.com/llvm/llvm-project/pull/117904 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits