================ @@ -4529,6 +4529,191 @@ void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) { emitMaster(*this, S); } +static Expr *replaceWithNewTraitsOrDirectCall(CapturedDecl *CDecl, + Expr *NewExpr) { + Expr *CurrentCallExpr = nullptr; + Stmt *CallExprStmt = CDecl->getBody(); + + if (BinaryOperator *BinaryCopyOpr = dyn_cast<BinaryOperator>(CallExprStmt)) { + CurrentCallExpr = BinaryCopyOpr->getRHS(); + BinaryCopyOpr->setRHS(NewExpr); + } else { + CurrentCallExpr = dyn_cast<Expr>(CallExprStmt); + CDecl->setBody(NewExpr); + } + + return CurrentCallExpr; +} + +static Expr *transformCallInStmt(Stmt *StmtP, bool NoContext = false) { + Expr *CurrentExpr = nullptr; + if (auto *CptStmt = dyn_cast<CapturedStmt>(StmtP)) { + CapturedDecl *CDecl = CptStmt->getCapturedDecl(); + + CallExpr *NewCallExpr = nullptr; + for (const auto *attr : CDecl->attrs()) { + if (NoContext) { + if (const auto *annotateAttr = + llvm::dyn_cast<clang::AnnotateAttr>(attr); + annotateAttr && annotateAttr->getAnnotation() == "NoContextAttr") { + NewCallExpr = llvm::dyn_cast<CallExpr>(*annotateAttr->args_begin()); + } + } else { + if (const auto *annotateAttr = + llvm::dyn_cast<clang::AnnotateAttr>(attr); + annotateAttr && annotateAttr->getAnnotation() == "NoVariantsAttr") { + NewCallExpr = llvm::dyn_cast<CallExpr>(*annotateAttr->args_begin()); + } + } + } + + CurrentExpr = replaceWithNewTraitsOrDirectCall(CDecl, NewCallExpr); + } + return CurrentExpr; +} + ---------------- alexey-bataev wrote:
I still think these functions should not be needed, if something is required, it should be build in Sema and stored in AST. If you need to replace some AST values by some LVM IR values, use OpaqueValue nodes, which can be replaced in codegen by special RAIIs. https://github.com/llvm/llvm-project/pull/131838 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits