Skip to content

Commit 49d5af9

Browse files
committed
Extract lambda for sema expr init
1 parent cf2ddcb commit 49d5af9

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,16 @@ static Expr *GenerateReductionInitRecipeExpr(ASTContext &Context,
26142614
return nullptr;
26152615
}
26162616

2617+
} else if (Ty->isPointerType()) {
2618+
// For now, we are going to punt/not initialize pointer types, as
2619+
// discussions/designs are ongoing on how to express this behavior,
2620+
// particularly since they probably need the 'bounds' passed to them
2621+
// correctly. A future patch/patch set will go through all of the pointer
2622+
// values for all of the recipes to make sure we have a sane behavior.
2623+
2624+
// For now, this will result in a NYI during code generation for
2625+
// no-initializer.
2626+
return nullptr;
26172627
} else {
26182628
assert(Ty->isScalarType());
26192629

@@ -2623,12 +2633,6 @@ static Expr *GenerateReductionInitRecipeExpr(ASTContext &Context,
26232633
Exprs.push_back(FloatingLiteral::Create(
26242634
Context, llvm::APFloat::getOne(Context.getFloatTypeSemantics(Ty)),
26252635
/*isExact=*/true, Ty, ExprRange.getBegin()));
2626-
} else if (Ty->isPointerType()) {
2627-
// It isn't clear here what we can do, we don't know the intended
2628-
// size/etc, as that isn't present in the recipe. We probably have to come
2629-
// up with a way to have the bounds passed to these, but it isn't clear
2630-
// how that should work.
2631-
return nullptr;
26322636
} else {
26332637
Exprs.push_back(IntegerLiteral::Create(
26342638
Context, llvm::APInt(Context.getTypeSize(Ty), 1), Ty,
@@ -2690,13 +2694,24 @@ SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK,
26902694
Sema::TentativeAnalysisScope Trap{SemaRef};
26912695
InitializedEntity Entity = InitializedEntity::InitializeVariable(Recipe);
26922696

2697+
auto FinishValueInit = [&](Expr *InitExpr) {
2698+
if (InitExpr) {
2699+
InitializationKind Kind = InitializationKind::CreateForInit(
2700+
Recipe->getLocation(), /*DirectInit=*/true, InitExpr);
2701+
InitializationSequence InitSeq(SemaRef.SemaRef, Entity, Kind, InitExpr,
2702+
/*TopLevelOfInitList=*/false,
2703+
/*TreatUnavailableAsInvalid=*/false);
2704+
return InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, InitExpr, &VarTy);
2705+
}
2706+
return ExprEmpty();
2707+
};
2708+
26932709
if (CK == OpenACCClauseKind::Private) {
26942710
InitializationKind Kind =
26952711
InitializationKind::CreateDefault(Recipe->getLocation());
26962712

26972713
InitializationSequence InitSeq(SemaRef.SemaRef, Entity, Kind, {});
26982714
Init = InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, {});
2699-
27002715
} else if (CK == OpenACCClauseKind::FirstPrivate) {
27012716
// Create a VarDecl to be the 'copied-from' for the copy section of the
27022717
// recipe. This allows us to make the association so that we can use the
@@ -2770,12 +2785,7 @@ SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK,
27702785
InitExpr = TemporaryDRE;
27712786
}
27722787

2773-
InitializationKind Kind = InitializationKind::CreateForInit(
2774-
Recipe->getLocation(), /*DirectInit=*/true, InitExpr);
2775-
InitializationSequence InitSeq(SemaRef.SemaRef, Entity, Kind, InitExpr,
2776-
/*TopLevelOfInitList=*/false,
2777-
/*TreatUnavailableAsInvalid=*/false);
2778-
Init = InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, InitExpr, &VarTy);
2788+
Init = FinishValueInit(InitExpr);
27792789
} else if (CK == OpenACCClauseKind::Reduction) {
27802790
// How we initialize the reduction variable depends on the operator used,
27812791
// according to the chart in OpenACC 3.3 section 2.6.15.
@@ -2801,16 +2811,7 @@ SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK,
28012811
Expr *InitExpr = GenerateReductionInitRecipeExpr(
28022812
getASTContext(), VarExpr->getSourceRange(), VarTy);
28032813

2804-
if (InitExpr) {
2805-
InitializationKind Kind = InitializationKind::CreateForInit(
2806-
Recipe->getLocation(), /*DirectInit=*/true, InitExpr);
2807-
InitializationSequence InitSeq(SemaRef.SemaRef, Entity, Kind,
2808-
InitExpr,
2809-
/*TopLevelOfInitList=*/false,
2810-
/*TreatUnavailableAsInvalid=*/false);
2811-
Init =
2812-
InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, InitExpr, &VarTy);
2813-
}
2814+
Init = FinishValueInit(InitExpr);
28142815
break;
28152816
}
28162817
case OpenACCReductionOperator::Addition:
@@ -2826,12 +2827,7 @@ SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK,
28262827
// will get this type correct/etc.
28272828
InitExpr->setType(getASTContext().VoidTy);
28282829

2829-
InitializationKind Kind = InitializationKind::CreateForInit(
2830-
Recipe->getLocation(), /*DirectInit=*/true, InitExpr);
2831-
InitializationSequence InitSeq(SemaRef.SemaRef, Entity, Kind, InitExpr,
2832-
/*TopLevelOfInitList=*/false,
2833-
/*TreatUnavailableAsInvalid=*/false);
2834-
Init = InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, InitExpr, &VarTy);
2830+
Init = FinishValueInit(InitExpr);
28352831
break;
28362832
}
28372833
}

0 commit comments

Comments
 (0)