[clang] [OpenACC] 'reduction' 'one-init' lowering, */&& operators. (PR #156122)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 2 06:39:51 PDT 2025


================
@@ -2589,6 +2589,59 @@ SemaOpenACC::ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc) {
   return BuildOpenACCAsteriskSizeExpr(AsteriskLoc);
 }
 
+/// Loops through a type and generates an appropriate InitListExpr to generate
+/// type initialization.
+static Expr *GenerateReductionInitRecipeExpr(ASTContext &Context,
+                                             SourceRange ExprRange,
+                                             QualType Ty) {
+  Ty = Ty.getCanonicalType();
+  llvm::SmallVector<Expr *> Exprs;
+
+  if (const RecordDecl *RD = Ty->getAsRecordDecl()) {
+    for (auto *F : RD->fields()) {
+      if (Expr *NewExpr =
+              GenerateReductionInitRecipeExpr(Context, ExprRange, F->getType()))
+        Exprs.push_back(NewExpr);
+      else
+        return nullptr;
+    }
+  } else if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) {
+    for (uint64_t Idx = 0; Idx < AT->getZExtSize(); ++Idx) {
+      if (Expr *NewExpr = GenerateReductionInitRecipeExpr(Context, ExprRange,
+                                                          AT->getElementType()))
+        Exprs.push_back(NewExpr);
+      else
+        return nullptr;
+    }
+
+  } else {
+    assert(Ty->isScalarType());
----------------
erichkeane wrote:

No, we are limited to scalar, array, or record types by sema.

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


More information about the cfe-commits mailing list