================
@@ -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());
+
+    // TODO:  OpenACC: This currently only works for '1', but we need to figure
+    // out a way to do least/largest/all-1s.
+    if (Ty->isFloatingType()) {
+      Exprs.push_back(FloatingLiteral::Create(
+          Context, llvm::APFloat::getOne(Context.getFloatTypeSemantics(Ty)),
+          /*isExact=*/true, Ty, ExprRange.getBegin()));
+    } else if (Ty->isPointerType()) {
+      // It isn't clear here what we can do, we don't know the intended
+      // size/etc, as that isn't present in the recipe. We probably have to 
come
+      // up with a way to have the bounds passed to these, but it isn't clear
+      // how that should work.
+      return nullptr;
+    } else {
+      Exprs.push_back(IntegerLiteral::Create(
----------------
andykaylor wrote:

Will this work correctly for complex types?

https://github.com/llvm/llvm-project/pull/156122
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to