@@ -3258,152 +3258,153 @@ class InitListTransformer {
32583258 Expr **ArgIt = nullptr ;
32593259 bool Wrap;
32603260
3261- bool castInitializer (Expr *E) {
3262- assert (DstIt && " This should always be something!" );
3263- if (DstIt == DestTypes.end ()) {
3264- if (!Wrap) {
3265- ArgExprs.push_back (E);
3266- // This is odd, but it isn't technically a failure due to conversion, we
3267- // handle mismatched counts of arguments differently.
3268- return true ;
3261+ bool castInitializer (Expr *E) {
3262+ assert (DstIt && " This should always be something!" );
3263+ if (DstIt == DestTypes.end ()) {
3264+ if (!Wrap) {
3265+ ArgExprs.push_back (E);
3266+ // This is odd, but it isn't technically a failure due to conversion, we
3267+ // handle mismatched counts of arguments differently.
3268+ return true ;
3269+ }
3270+ DstIt = DestTypes.begin ();
32693271 }
3270- DstIt = DestTypes.begin ();
3271- }
3272- InitializedEntity Entity =
3273- InitializedEntity::InitializeParameter (Ctx, *DstIt, true );
3274- ExprResult Res = S.PerformCopyInitialization (Entity, E->getBeginLoc (), E);
3275- if (Res.isInvalid ())
3276- return false ;
3277- Expr *Init = Res.get ();
3278- ArgExprs.push_back (Init);
3279- DstIt++;
3280- return true ;
3281- }
3282-
3283- bool buildInitializerListImpl (Expr *E) {
3284- // If this is an initialization list, traverse the sub initializers.
3285- if (auto *Init = dyn_cast<InitListExpr>(E)) {
3286- for (auto *SubInit : Init->inits ())
3287- if (!buildInitializerListImpl (SubInit))
3288- return false ;
3272+ InitializedEntity Entity =
3273+ InitializedEntity::InitializeParameter (Ctx, *DstIt, true );
3274+ ExprResult Res = S.PerformCopyInitialization (Entity, E->getBeginLoc (), E);
3275+ if (Res.isInvalid ())
3276+ return false ;
3277+ Expr *Init = Res.get ();
3278+ ArgExprs.push_back (Init);
3279+ DstIt++;
32893280 return true ;
32903281 }
32913282
3292- // If this is a scalar type, just enqueue the expression.
3293- QualType Ty = E->getType ();
3283+ bool buildInitializerListImpl (Expr *E) {
3284+ // If this is an initialization list, traverse the sub initializers.
3285+ if (auto *Init = dyn_cast<InitListExpr>(E)) {
3286+ for (auto *SubInit : Init->inits ())
3287+ if (!buildInitializerListImpl (SubInit))
3288+ return false ;
3289+ return true ;
3290+ }
32943291
3295- if (Ty-> isScalarType () || (Ty-> isRecordType () && !Ty-> isAggregateType ()))
3296- return castInitializer (E );
3292+ // If this is a scalar type, just enqueue the expression.
3293+ QualType Ty = E-> getType ( );
32973294
3298- if (auto *VecTy = Ty->getAs <VectorType> ()) {
3299- uint64_t Size = VecTy-> getNumElements ( );
3295+ if (Ty-> isScalarType () || (Ty-> isRecordType () && ! Ty->isAggregateType ()))
3296+ return castInitializer (E );
33003297
3301- QualType SizeTy = Ctx.getSizeType ();
3302- uint64_t SizeTySize = Ctx.getTypeSize (SizeTy);
3303- for (uint64_t I = 0 ; I < Size; ++I) {
3304- auto *Idx = IntegerLiteral::Create (Ctx, llvm::APInt (SizeTySize, I),
3305- SizeTy, SourceLocation ());
3298+ if (auto *VecTy = Ty->getAs <VectorType>()) {
3299+ uint64_t Size = VecTy->getNumElements ();
33063300
3307- ExprResult ElExpr = S.CreateBuiltinArraySubscriptExpr (
3308- E, E->getBeginLoc (), Idx, E->getEndLoc ());
3309- if (ElExpr.isInvalid ())
3310- return false ;
3311- if (!castInitializer (ElExpr.get ()))
3312- return false ;
3313- }
3314- return true ;
3315- }
3301+ QualType SizeTy = Ctx.getSizeType ();
3302+ uint64_t SizeTySize = Ctx.getTypeSize (SizeTy);
3303+ for (uint64_t I = 0 ; I < Size; ++I) {
3304+ auto *Idx = IntegerLiteral::Create (Ctx, llvm::APInt (SizeTySize, I),
3305+ SizeTy, SourceLocation ());
33163306
3317- if (auto *ArrTy = dyn_cast<ConstantArrayType>(Ty.getTypePtr ())) {
3318- uint64_t Size = ArrTy->getZExtSize ();
3319- QualType SizeTy = Ctx.getSizeType ();
3320- uint64_t SizeTySize = Ctx.getTypeSize (SizeTy);
3321- for (uint64_t I = 0 ; I < Size; ++I) {
3322- auto *Idx = IntegerLiteral::Create (Ctx, llvm::APInt (SizeTySize, I),
3323- SizeTy, SourceLocation ());
3324- ExprResult ElExpr = S.CreateBuiltinArraySubscriptExpr (
3325- E, E->getBeginLoc (), Idx, E->getEndLoc ());
3326- if (ElExpr.isInvalid ())
3327- return false ;
3328- if (!buildInitializerListImpl (ElExpr.get ()))
3329- return false ;
3307+ ExprResult ElExpr = S.CreateBuiltinArraySubscriptExpr (
3308+ E, E->getBeginLoc (), Idx, E->getEndLoc ());
3309+ if (ElExpr.isInvalid ())
3310+ return false ;
3311+ if (!castInitializer (ElExpr.get ()))
3312+ return false ;
3313+ }
3314+ return true ;
33303315 }
3331- return true ;
3332- }
33333316
3334- if (auto *RTy = Ty->getAs <RecordType>()) {
3335- llvm::SmallVector<const RecordType *> RecordTypes;
3336- RecordTypes.push_back (RTy);
3337- while (RecordTypes.back ()->getAsCXXRecordDecl ()->getNumBases ()) {
3338- CXXRecordDecl *D = RecordTypes.back ()->getAsCXXRecordDecl ();
3339- assert (D->getNumBases () == 1 &&
3340- " HLSL doesn't support multiple inheritance" );
3341- RecordTypes.push_back (D->bases_begin ()->getType ()->getAs <RecordType>());
3342- }
3343- while (!RecordTypes.empty ()) {
3344- const RecordType *RT = RecordTypes.back ();
3345- RecordTypes.pop_back ();
3346- for (auto *FD : RT->getDecl ()->fields ()) {
3347- DeclAccessPair Found = DeclAccessPair::make (FD, FD->getAccess ());
3348- DeclarationNameInfo NameInfo (FD->getDeclName (), E->getBeginLoc ());
3349- ExprResult Res = S.BuildFieldReferenceExpr (
3350- E, false , E->getBeginLoc (), CXXScopeSpec (), FD, Found, NameInfo);
3351- if (Res.isInvalid ())
3317+ if (auto *ArrTy = dyn_cast<ConstantArrayType>(Ty.getTypePtr ())) {
3318+ uint64_t Size = ArrTy->getZExtSize ();
3319+ QualType SizeTy = Ctx.getSizeType ();
3320+ uint64_t SizeTySize = Ctx.getTypeSize (SizeTy);
3321+ for (uint64_t I = 0 ; I < Size; ++I) {
3322+ auto *Idx = IntegerLiteral::Create (Ctx, llvm::APInt (SizeTySize, I),
3323+ SizeTy, SourceLocation ());
3324+ ExprResult ElExpr = S.CreateBuiltinArraySubscriptExpr (
3325+ E, E->getBeginLoc (), Idx, E->getEndLoc ());
3326+ if (ElExpr.isInvalid ())
33523327 return false ;
3353- if (!buildInitializerListImpl (Res .get ()))
3328+ if (!buildInitializerListImpl (ElExpr .get ()))
33543329 return false ;
33553330 }
3331+ return true ;
33563332 }
3333+
3334+ if (auto *RTy = Ty->getAs <RecordType>()) {
3335+ llvm::SmallVector<const RecordType *> RecordTypes;
3336+ RecordTypes.push_back (RTy);
3337+ while (RecordTypes.back ()->getAsCXXRecordDecl ()->getNumBases ()) {
3338+ CXXRecordDecl *D = RecordTypes.back ()->getAsCXXRecordDecl ();
3339+ assert (D->getNumBases () == 1 &&
3340+ " HLSL doesn't support multiple inheritance" );
3341+ RecordTypes.push_back (D->bases_begin ()->getType ()->getAs <RecordType>());
3342+ }
3343+ while (!RecordTypes.empty ()) {
3344+ const RecordType *RT = RecordTypes.back ();
3345+ RecordTypes.pop_back ();
3346+ for (auto *FD : RT->getDecl ()->fields ()) {
3347+ DeclAccessPair Found = DeclAccessPair::make (FD, FD->getAccess ());
3348+ DeclarationNameInfo NameInfo (FD->getDeclName (), E->getBeginLoc ());
3349+ ExprResult Res = S.BuildFieldReferenceExpr (
3350+ E, false , E->getBeginLoc (), CXXScopeSpec (), FD, Found, NameInfo);
3351+ if (Res.isInvalid ())
3352+ return false ;
3353+ if (!buildInitializerListImpl (Res.get ()))
3354+ return false ;
3355+ }
3356+ }
3357+ }
3358+ return true ;
33573359 }
3358- return true ;
3359- }
33603360
3361- Expr *generateInitListsImpl (QualType Ty) {
3362- assert (ArgIt != ArgExprs.end () && " Something is off in iteration!" );
3363- if (Ty->isScalarType () || (Ty->isRecordType () && !Ty->isAggregateType ()))
3364- return *(ArgIt++);
3365-
3366- llvm::SmallVector<Expr *> Inits;
3367- assert (!isa<MatrixType>(Ty) && " Matrix types not yet supported in HLSL" );
3368- Ty = Ty.getDesugaredType (Ctx);
3369- if (Ty->isVectorType () || Ty->isConstantArrayType ()) {
3370- QualType ElTy;
3371- uint64_t Size = 0 ;
3372- if (auto *ATy = Ty->getAs <VectorType>()) {
3373- ElTy = ATy->getElementType ();
3374- Size = ATy->getNumElements ();
3375- } else {
3376- auto *VTy = cast<ConstantArrayType>(Ty.getTypePtr ());
3377- ElTy = VTy->getElementType ();
3378- Size = VTy->getZExtSize ();
3379- }
3380- for (uint64_t I = 0 ; I < Size; ++I)
3381- Inits.push_back (generateInitListsImpl (ElTy));
3382- }
3383- if (auto *RTy = Ty->getAs <RecordType>()) {
3384- llvm::SmallVector<const RecordType *> RecordTypes;
3385- RecordTypes.push_back (RTy);
3386- while (RecordTypes.back ()->getAsCXXRecordDecl ()->getNumBases ()) {
3387- CXXRecordDecl *D = RecordTypes.back ()->getAsCXXRecordDecl ();
3388- assert (D->getNumBases () == 1 &&
3389- " HLSL doesn't support multiple inheritance" );
3390- RecordTypes.push_back (D->bases_begin ()->getType ()->getAs <RecordType>());
3391- }
3392- while (!RecordTypes.empty ()) {
3393- const RecordType *RT = RecordTypes.back ();
3394- RecordTypes.pop_back ();
3395- for (auto *FD : RT->getDecl ()->fields ()) {
3396- Inits.push_back (generateInitListsImpl (FD->getType ()));
3361+ Expr *generateInitListsImpl (QualType Ty) {
3362+ assert (ArgIt != ArgExprs.end () && " Something is off in iteration!" );
3363+ if (Ty->isScalarType () || (Ty->isRecordType () && !Ty->isAggregateType ()))
3364+ return *(ArgIt++);
3365+
3366+ llvm::SmallVector<Expr *> Inits;
3367+ assert (!isa<MatrixType>(Ty) && " Matrix types not yet supported in HLSL" );
3368+ Ty = Ty.getDesugaredType (Ctx);
3369+ if (Ty->isVectorType () || Ty->isConstantArrayType ()) {
3370+ QualType ElTy;
3371+ uint64_t Size = 0 ;
3372+ if (auto *ATy = Ty->getAs <VectorType>()) {
3373+ ElTy = ATy->getElementType ();
3374+ Size = ATy->getNumElements ();
3375+ } else {
3376+ auto *VTy = cast<ConstantArrayType>(Ty.getTypePtr ());
3377+ ElTy = VTy->getElementType ();
3378+ Size = VTy->getZExtSize ();
3379+ }
3380+ for (uint64_t I = 0 ; I < Size; ++I)
3381+ Inits.push_back (generateInitListsImpl (ElTy));
3382+ }
3383+ if (auto *RTy = Ty->getAs <RecordType>()) {
3384+ llvm::SmallVector<const RecordType *> RecordTypes;
3385+ RecordTypes.push_back (RTy);
3386+ while (RecordTypes.back ()->getAsCXXRecordDecl ()->getNumBases ()) {
3387+ CXXRecordDecl *D = RecordTypes.back ()->getAsCXXRecordDecl ();
3388+ assert (D->getNumBases () == 1 &&
3389+ " HLSL doesn't support multiple inheritance" );
3390+ RecordTypes.push_back (D->bases_begin ()->getType ()->getAs <RecordType>());
3391+ }
3392+ while (!RecordTypes.empty ()) {
3393+ const RecordType *RT = RecordTypes.back ();
3394+ RecordTypes.pop_back ();
3395+ for (auto *FD : RT->getDecl ()->fields ()) {
3396+ Inits.push_back (generateInitListsImpl (FD->getType ()));
3397+ }
33973398 }
33983399 }
3400+ auto *NewInit = new (Ctx) InitListExpr (Ctx, Inits.front ()->getBeginLoc (),
3401+ Inits, Inits.back ()->getEndLoc ());
3402+ NewInit->setType (Ty);
3403+ return NewInit;
33993404 }
3400- auto *NewInit = new (Ctx) InitListExpr (Ctx, Inits.front ()->getBeginLoc (),
3401- Inits, Inits.back ()->getEndLoc ());
3402- NewInit->setType (Ty);
3403- return NewInit;
3404- }
3405+
34053406public:
3406- llvm::SmallVector<QualType, 16 > DestTypes;
3407+ llvm::SmallVector<QualType, 16 > DestTypes;
34073408 llvm::SmallVector<Expr *, 16 > ArgExprs;
34083409 InitListTransformer (Sema &SemaRef, const InitializedEntity &Entity)
34093410 : S(SemaRef), Ctx(SemaRef.getASTContext()),
@@ -3413,14 +3414,12 @@ llvm::SmallVector<QualType, 16> DestTypes;
34133414 // need to wrap around both when building the initializers and when
34143415 // generating the final initializer lists.
34153416 if (Wrap)
3416- InitTy = QualType (InitTy->getBaseElementTypeUnsafe (),0 );
3417+ InitTy = QualType (InitTy->getBaseElementTypeUnsafe (), 0 );
34173418 BuildFlattenedTypeList (InitTy, DestTypes);
34183419 DstIt = DestTypes.begin ();
34193420 }
34203421
3421- bool buildInitializerList (Expr *E) {
3422- return buildInitializerListImpl (E);
3423- }
3422+ bool buildInitializerList (Expr *E) { return buildInitializerListImpl (E); }
34243423
34253424 Expr *generateInitLists () {
34263425 ArgIt = ArgExprs.begin ();
@@ -3438,7 +3437,7 @@ llvm::SmallVector<QualType, 16> DestTypes;
34383437 return NewInit;
34393438 }
34403439};
3441- }
3440+ } // namespace
34423441
34433442bool SemaHLSL::TransformInitList (const InitializedEntity &Entity,
34443443 const InitializationKind &Kind,
@@ -3469,7 +3468,8 @@ bool SemaHLSL::TransformInitList(const InitializedEntity &Entity,
34693468 // the user intended more, and errors that there are too few initializers to
34703469 // complete the final element.
34713470 if (Entity.getType ()->isIncompleteArrayType ())
3472- ExpectedSize = ((ActualSize + ExpectedSize - 1 ) / ExpectedSize) * ExpectedSize;
3471+ ExpectedSize =
3472+ ((ActualSize + ExpectedSize - 1 ) / ExpectedSize) * ExpectedSize;
34733473
34743474 // An initializer list might be attempting to initialize a reference or
34753475 // rvalue-reference. When checking the initializer we should look through
0 commit comments