================
@@ -4529,6 +4529,117 @@ void CodeGenFunction::EmitOMPMasterDirective(const 
OMPMasterDirective &S) {
   emitMaster(*this, S);
 }
 
+static Expr *getCapturedExprFromImplicitCastExpr(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 Cond;
+}
+
+static Expr *replaceWithNewTraitsOrDirectCall(Stmt *AssocExpr,
+                                              CallExpr *ReplacementFunction) {
+  Expr *FinalCall = ReplacementFunction;
+
+  if (BinaryOperator *BinaryCopyOpr = dyn_cast<BinaryOperator>(AssocExpr)) {
+    BinaryCopyOpr->setRHS(FinalCall);
+    return BinaryCopyOpr;
+  }
+
+  return FinalCall;
+}
+
+static void transformCallInStmt(Stmt *StmtP) {
+  if (auto *AssocStmt = dyn_cast<CapturedStmt>(StmtP)) {
+    CapturedDecl *CDecl = AssocStmt->getCapturedDecl();
+
+    // Access AnnotateAttr
+    CallExpr *NewCallExpr = nullptr;
+    for (const auto *attr : CDecl->attrs()) {
+      if (const auto *annotateAttr = llvm::dyn_cast<clang::AnnotateAttr>(attr);
+          annotateAttr &&
+          annotateAttr->getAnnotation() == "NoContextInvariant") {
+        NewCallExpr = llvm::dyn_cast<CallExpr>(*annotateAttr->args_begin());
+      }
+    }
+
+    Stmt *CallExprStmt = CDecl->getBody();
+    Stmt *NewCallExprStmt =
+        replaceWithNewTraitsOrDirectCall(CallExprStmt, NewCallExpr);
+    CDecl->setBody(NewCallExprStmt);
+  }
+}
+
+static void EmitIfElse(CodeGenFunction *CGF, Expr *Condition,
----------------
alexey-bataev wrote:
```suggestion
static void emitIfElse(CodeGenFunction *CGF, Expr *Condition,
```


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

Reply via email to