@@ -829,7 +829,8 @@ static bool isAddrSpaceMapManglingEnabled(const TargetInfo &TI,
829
829
ASTContext::ASTContext (LangOptions &LOpts, SourceManager &SM,
830
830
IdentifierTable &idents, SelectorTable &sels,
831
831
Builtin::Context &builtins)
832
- : FunctionProtoTypes(this_()), TemplateSpecializationTypes(this_()),
832
+ : ConstantArrayTypes(this_()), FunctionProtoTypes(this_()),
833
+ TemplateSpecializationTypes(this_()),
833
834
DependentTemplateSpecializationTypes(this_()),
834
835
SubstTemplateTemplateParmPacks(this_()), SourceMgr(SM), LangOpts(LOpts),
835
836
SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFiles, SM)),
@@ -3165,31 +3166,38 @@ QualType ASTContext::getMemberPointerType(QualType T, const Type *Cls) const {
3165
3166
// / array of the specified element type.
3166
3167
QualType ASTContext::getConstantArrayType (QualType EltTy,
3167
3168
const llvm::APInt &ArySizeIn,
3169
+ const Expr *SizeExpr,
3168
3170
ArrayType::ArraySizeModifier ASM,
3169
3171
unsigned IndexTypeQuals) const {
3170
3172
assert ((EltTy->isDependentType () ||
3171
3173
EltTy->isIncompleteType () || EltTy->isConstantSizeType ()) &&
3172
3174
" Constant array of VLAs is illegal!" );
3173
3175
3176
+ // We only need the size as part of the type if it's instantiation-dependent.
3177
+ if (SizeExpr && !SizeExpr->isInstantiationDependent ())
3178
+ SizeExpr = nullptr ;
3179
+
3174
3180
// Convert the array size into a canonical width matching the pointer size for
3175
3181
// the target.
3176
3182
llvm::APInt ArySize (ArySizeIn);
3177
3183
ArySize = ArySize.zextOrTrunc (Target->getMaxPointerWidth ());
3178
3184
3179
3185
llvm::FoldingSetNodeID ID;
3180
- ConstantArrayType::Profile (ID, EltTy, ArySize, ASM, IndexTypeQuals);
3186
+ ConstantArrayType::Profile (ID, *this , EltTy, ArySize, SizeExpr, ASM,
3187
+ IndexTypeQuals);
3181
3188
3182
3189
void *InsertPos = nullptr ;
3183
3190
if (ConstantArrayType *ATP =
3184
3191
ConstantArrayTypes.FindNodeOrInsertPos (ID, InsertPos))
3185
3192
return QualType (ATP, 0 );
3186
3193
3187
- // If the element type isn't canonical or has qualifiers, this won't
3188
- // be a canonical type either, so fill in the canonical type field.
3194
+ // If the element type isn't canonical or has qualifiers, or the array bound
3195
+ // is instantiation-dependent, this won't be a canonical type either, so fill
3196
+ // in the canonical type field.
3189
3197
QualType Canon;
3190
- if (!EltTy.isCanonical () || EltTy.hasLocalQualifiers ()) {
3198
+ if (!EltTy.isCanonical () || EltTy.hasLocalQualifiers () || SizeExpr ) {
3191
3199
SplitQualType canonSplit = getCanonicalType (EltTy).split ();
3192
- Canon = getConstantArrayType (QualType (canonSplit.Ty , 0 ), ArySize,
3200
+ Canon = getConstantArrayType (QualType (canonSplit.Ty , 0 ), ArySize, nullptr ,
3193
3201
ASM, IndexTypeQuals);
3194
3202
Canon = getQualifiedType (Canon, canonSplit.Quals );
3195
3203
@@ -3199,8 +3207,11 @@ QualType ASTContext::getConstantArrayType(QualType EltTy,
3199
3207
assert (!NewIP && " Shouldn't be in the map!" ); (void )NewIP;
3200
3208
}
3201
3209
3202
- auto *New = new (*this ,TypeAlignment)
3203
- ConstantArrayType (EltTy, Canon, ArySize, ASM, IndexTypeQuals);
3210
+ void *Mem = Allocate (
3211
+ ConstantArrayType::totalSizeToAlloc<const Expr *>(SizeExpr ? 1 : 0 ),
3212
+ TypeAlignment);
3213
+ auto *New = new (Mem)
3214
+ ConstantArrayType (EltTy, Canon, ArySize, SizeExpr, ASM, IndexTypeQuals);
3204
3215
ConstantArrayTypes.InsertNode (New, InsertPos);
3205
3216
Types.push_back (New);
3206
3217
return QualType (New, 0 );
@@ -3297,6 +3308,7 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const {
3297
3308
result = getConstantArrayType (
3298
3309
getVariableArrayDecayedType (cat->getElementType ()),
3299
3310
cat->getSize (),
3311
+ cat->getSizeExpr (),
3300
3312
cat->getSizeModifier (),
3301
3313
cat->getIndexTypeCVRQualifiers ());
3302
3314
break ;
@@ -5192,7 +5204,7 @@ QualType ASTContext::getUnqualifiedArrayType(QualType type,
5192
5204
5193
5205
if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
5194
5206
return getConstantArrayType (unqualElementType, CAT->getSize (),
5195
- CAT->getSizeModifier (), 0 );
5207
+ CAT->getSizeExpr (), CAT-> getSizeModifier (), 0 );
5196
5208
}
5197
5209
5198
5210
if (const auto *IAT = dyn_cast<IncompleteArrayType>(AT)) {
@@ -5565,6 +5577,7 @@ const ArrayType *ASTContext::getAsArrayType(QualType T) const {
5565
5577
5566
5578
if (const auto *CAT = dyn_cast<ConstantArrayType>(ATy))
5567
5579
return cast<ArrayType>(getConstantArrayType (NewEltTy, CAT->getSize (),
5580
+ CAT->getSizeExpr (),
5568
5581
CAT->getSizeModifier (),
5569
5582
CAT->getIndexTypeCVRQualifiers ()));
5570
5583
if (const auto *IAT = dyn_cast<IncompleteArrayType>(ATy))
@@ -7471,7 +7484,7 @@ static TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) {
7471
7484
llvm::APInt Size (Context->getTypeSize (Context->getSizeType ()), 1 );
7472
7485
QualType VaListTagArrayType
7473
7486
= Context->getConstantArrayType (VaListTagTypedefType,
7474
- Size, ArrayType::Normal, 0 );
7487
+ Size, nullptr , ArrayType::Normal, 0 );
7475
7488
return Context->buildImplicitTypedef (VaListTagArrayType, " __builtin_va_list" );
7476
7489
}
7477
7490
@@ -7524,16 +7537,16 @@ CreateX86_64ABIBuiltinVaListDecl(const ASTContext *Context) {
7524
7537
7525
7538
// typedef struct __va_list_tag __builtin_va_list[1];
7526
7539
llvm::APInt Size (Context->getTypeSize (Context->getSizeType ()), 1 );
7527
- QualType VaListTagArrayType =
7528
- Context-> getConstantArrayType ( VaListTagType, Size, ArrayType::Normal, 0 );
7540
+ QualType VaListTagArrayType = Context-> getConstantArrayType (
7541
+ VaListTagType, Size, nullptr , ArrayType::Normal, 0 );
7529
7542
return Context->buildImplicitTypedef (VaListTagArrayType, " __builtin_va_list" );
7530
7543
}
7531
7544
7532
7545
static TypedefDecl *CreatePNaClABIBuiltinVaListDecl (const ASTContext *Context) {
7533
7546
// typedef int __builtin_va_list[4];
7534
7547
llvm::APInt Size (Context->getTypeSize (Context->getSizeType ()), 4 );
7535
- QualType IntArrayType =
7536
- Context->getConstantArrayType (Context-> IntTy , Size, ArrayType::Normal, 0 );
7548
+ QualType IntArrayType = Context-> getConstantArrayType (
7549
+ Context->IntTy , Size, nullptr , ArrayType::Normal, 0 );
7537
7550
return Context->buildImplicitTypedef (IntArrayType, " __builtin_va_list" );
7538
7551
}
7539
7552
@@ -7627,8 +7640,8 @@ CreateSystemZBuiltinVaListDecl(const ASTContext *Context) {
7627
7640
7628
7641
// typedef __va_list_tag __builtin_va_list[1];
7629
7642
llvm::APInt Size (Context->getTypeSize (Context->getSizeType ()), 1 );
7630
- QualType VaListTagArrayType =
7631
- Context-> getConstantArrayType ( VaListTagType, Size, ArrayType::Normal, 0 );
7643
+ QualType VaListTagArrayType = Context-> getConstantArrayType (
7644
+ VaListTagType, Size, nullptr , ArrayType::Normal, 0 );
7632
7645
7633
7646
return Context->buildImplicitTypedef (VaListTagArrayType, " __builtin_va_list" );
7634
7647
}
@@ -9072,10 +9085,14 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS,
9072
9085
return LHS;
9073
9086
if (RCAT && getCanonicalType (RHSElem) == getCanonicalType (ResultType))
9074
9087
return RHS;
9075
- if (LCAT) return getConstantArrayType (ResultType, LCAT->getSize (),
9076
- ArrayType::ArraySizeModifier (), 0 );
9077
- if (RCAT) return getConstantArrayType (ResultType, RCAT->getSize (),
9078
- ArrayType::ArraySizeModifier (), 0 );
9088
+ if (LCAT)
9089
+ return getConstantArrayType (ResultType, LCAT->getSize (),
9090
+ LCAT->getSizeExpr (),
9091
+ ArrayType::ArraySizeModifier (), 0 );
9092
+ if (RCAT)
9093
+ return getConstantArrayType (ResultType, RCAT->getSize (),
9094
+ RCAT->getSizeExpr (),
9095
+ ArrayType::ArraySizeModifier (), 0 );
9079
9096
if (LVAT && getCanonicalType (LHSElem) == getCanonicalType (ResultType))
9080
9097
return LHS;
9081
9098
if (RVAT && getCanonicalType (RHSElem) == getCanonicalType (ResultType))
@@ -10317,7 +10334,7 @@ QualType ASTContext::getStringLiteralArrayType(QualType EltTy,
10317
10334
10318
10335
// Get an array type for the string, according to C99 6.4.5. This includes
10319
10336
// the null terminator character.
10320
- return getConstantArrayType (EltTy, llvm::APInt (32 , Length + 1 ),
10337
+ return getConstantArrayType (EltTy, llvm::APInt (32 , Length + 1 ), nullptr ,
10321
10338
ArrayType::Normal, /* IndexTypeQuals*/ 0 );
10322
10339
}
10323
10340
0 commit comments