Keep track of the Expr used to describe the size of an array type,
from Enea Zaffanella!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74831 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 0075815..08607d5 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -475,6 +475,8 @@
Align = getTypeAlign(cast<ArrayType>(T)->getElementType());
break;
+ case Type::ConstantArrayWithExpr:
+ case Type::ConstantArrayWithoutExpr:
case Type::ConstantArray: {
const ConstantArrayType *CAT = cast<ConstantArrayType>(T);
@@ -1344,16 +1346,68 @@
return QualType(New, 0);
}
+/// getConstantArrayWithExprType - Return a reference to the type for
+/// an array of the specified element type.
+QualType
+ASTContext::getConstantArrayWithExprType(QualType EltTy,
+ const llvm::APInt &ArySizeIn,
+ Expr *ArySizeExpr,
+ ArrayType::ArraySizeModifier ASM,
+ unsigned EltTypeQuals,
+ SourceRange Brackets) {
+ // Convert the array size into a canonical width matching the pointer
+ // size for the target.
+ llvm::APInt ArySize(ArySizeIn);
+ ArySize.zextOrTrunc(Target.getPointerWidth(EltTy.getAddressSpace()));
+
+ // Compute the canonical ConstantArrayType.
+ QualType Canonical = getConstantArrayType(getCanonicalType(EltTy),
+ ArySize, ASM, EltTypeQuals);
+ // Since we don't unique expressions, it isn't possible to unique VLA's
+ // that have an expression provided for their size.
+ ConstantArrayWithExprType *New =
+ new(*this,8)ConstantArrayWithExprType(EltTy, Canonical,
+ ArySize, ArySizeExpr,
+ ASM, EltTypeQuals, Brackets);
+ Types.push_back(New);
+ return QualType(New, 0);
+}
+
+/// getConstantArrayWithoutExprType - Return a reference to the type for
+/// an array of the specified element type.
+QualType
+ASTContext::getConstantArrayWithoutExprType(QualType EltTy,
+ const llvm::APInt &ArySizeIn,
+ ArrayType::ArraySizeModifier ASM,
+ unsigned EltTypeQuals) {
+ // Convert the array size into a canonical width matching the pointer
+ // size for the target.
+ llvm::APInt ArySize(ArySizeIn);
+ ArySize.zextOrTrunc(Target.getPointerWidth(EltTy.getAddressSpace()));
+
+ // Compute the canonical ConstantArrayType.
+ QualType Canonical = getConstantArrayType(getCanonicalType(EltTy),
+ ArySize, ASM, EltTypeQuals);
+ ConstantArrayWithoutExprType *New =
+ new(*this,8)ConstantArrayWithoutExprType(EltTy, Canonical,
+ ArySize, ASM, EltTypeQuals);
+ Types.push_back(New);
+ return QualType(New, 0);
+}
+
/// getVariableArrayType - Returns a non-unique reference to the type for a
/// variable array of the specified element type.
-QualType ASTContext::getVariableArrayType(QualType EltTy, Expr *NumElts,
+QualType ASTContext::getVariableArrayType(QualType EltTy,
+ Expr *NumElts,
ArrayType::ArraySizeModifier ASM,
- unsigned EltTypeQuals) {
+ unsigned EltTypeQuals,
+ SourceRange Brackets) {
// Since we don't unique expressions, it isn't possible to unique VLA's
// that have an expression provided for their size.
VariableArrayType *New =
- new(*this,8)VariableArrayType(EltTy,QualType(), NumElts, ASM, EltTypeQuals);
+ new(*this,8)VariableArrayType(EltTy, QualType(),
+ NumElts, ASM, EltTypeQuals, Brackets);
VariableArrayTypes.push_back(New);
Types.push_back(New);
@@ -1364,9 +1418,11 @@
/// the type for a dependently-sized array of the specified element
/// type. FIXME: We will need these to be uniqued, or at least
/// comparable, at some point.
-QualType ASTContext::getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
+QualType ASTContext::getDependentSizedArrayType(QualType EltTy,
+ Expr *NumElts,
ArrayType::ArraySizeModifier ASM,
- unsigned EltTypeQuals) {
+ unsigned EltTypeQuals,
+ SourceRange Brackets) {
assert((NumElts->isTypeDependent() || NumElts->isValueDependent()) &&
"Size must be type- or value-dependent!");
@@ -1374,8 +1430,9 @@
// dependently-sized array types.
DependentSizedArrayType *New =
- new (*this,8) DependentSizedArrayType(EltTy, QualType(), NumElts,
- ASM, EltTypeQuals);
+ new (*this,8) DependentSizedArrayType(EltTy, QualType(),
+ NumElts, ASM, EltTypeQuals,
+ Brackets);
DependentSizedArrayTypes.push_back(New);
Types.push_back(New);
@@ -1407,8 +1464,9 @@
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
- IncompleteArrayType *New = new (*this,8) IncompleteArrayType(EltTy, Canonical,
- ASM, EltTypeQuals);
+ IncompleteArrayType *New
+ = new (*this,8) IncompleteArrayType(EltTy, Canonical,
+ ASM, EltTypeQuals);
IncompleteArrayTypes.InsertNode(New, InsertPos);
Types.push_back(New);
@@ -1974,14 +2032,18 @@
IAT->getIndexTypeQualifier());
if (DependentSizedArrayType *DSAT = dyn_cast<DependentSizedArrayType>(AT))
- return getDependentSizedArrayType(NewEltTy, DSAT->getSizeExpr(),
+ return getDependentSizedArrayType(NewEltTy,
+ DSAT->getSizeExpr(),
DSAT->getSizeModifier(),
- DSAT->getIndexTypeQualifier());
+ DSAT->getIndexTypeQualifier(),
+ DSAT->getBracketsRange());
VariableArrayType *VAT = cast<VariableArrayType>(AT);
- return getVariableArrayType(NewEltTy, VAT->getSizeExpr(),
+ return getVariableArrayType(NewEltTy,
+ VAT->getSizeExpr(),
VAT->getSizeModifier(),
- VAT->getIndexTypeQualifier());
+ VAT->getIndexTypeQualifier(),
+ VAT->getBracketsRange());
}
Decl *ASTContext::getCanonicalDecl(Decl *D) {
@@ -2136,7 +2198,7 @@
if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(ATy))
return cast<ArrayType>(getIncompleteArrayType(NewEltTy,
IAT->getSizeModifier(),
- IAT->getIndexTypeQualifier()));
+ IAT->getIndexTypeQualifier()));
if (const DependentSizedArrayType *DSAT
= dyn_cast<DependentSizedArrayType>(ATy))
@@ -2144,12 +2206,15 @@
getDependentSizedArrayType(NewEltTy,
DSAT->getSizeExpr(),
DSAT->getSizeModifier(),
- DSAT->getIndexTypeQualifier()));
+ DSAT->getIndexTypeQualifier(),
+ DSAT->getBracketsRange()));
const VariableArrayType *VAT = cast<VariableArrayType>(ATy);
- return cast<ArrayType>(getVariableArrayType(NewEltTy, VAT->getSizeExpr(),
+ return cast<ArrayType>(getVariableArrayType(NewEltTy,
+ VAT->getSizeExpr(),
VAT->getSizeModifier(),
- VAT->getIndexTypeQualifier()));
+ VAT->getIndexTypeQualifier(),
+ VAT->getBracketsRange()));
}
@@ -3528,7 +3593,8 @@
}
if (getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS;
if (getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS;
- return getIncompleteArrayType(ResultType, ArrayType::ArraySizeModifier(),0);
+ return getIncompleteArrayType(ResultType,
+ ArrayType::ArraySizeModifier(), 0);
}
case Type::FunctionNoProto:
return mergeFunctionTypes(LHS, RHS);
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 4e061a9..2b307c8 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -37,6 +37,18 @@
C.Deallocate(this);
}
+void ConstantArrayWithExprType::Destroy(ASTContext& C) {
+ // FIXME: destruction of SizeExpr commented out due to resource contention.
+ // SizeExpr->Destroy(C);
+ // See FIXME in SemaDecl.cpp:1536: if we were able to either steal
+ // or clone the SizeExpr there, then here we could freely delete it.
+ // Since we do not know how to steal or clone, we keep a pointer to
+ // a shared resource, but we cannot free it.
+ // (There probably is a trivial solution ... for people knowing clang!).
+ this->~ConstantArrayWithExprType();
+ C.Deallocate(this);
+}
+
void VariableArrayType::Destroy(ASTContext& C) {
if (SizeExpr)
SizeExpr->Destroy(C);
@@ -163,6 +175,8 @@
case Pointer:
case VariableArray:
case ConstantArray:
+ case ConstantArrayWithExpr:
+ case ConstantArrayWithoutExpr:
case IncompleteArray:
case FunctionProto:
case FunctionNoProto:
@@ -1339,6 +1353,29 @@
getElementType().getAsStringInternal(S, Policy);
}
+void ConstantArrayWithExprType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
+ if (Policy.ConstantArraySizeAsWritten) {
+ std::string SStr;
+ llvm::raw_string_ostream s(SStr);
+ getSizeExpr()->printPretty(s, 0, Policy);
+ S += '[';
+ S += s.str();
+ S += ']';
+ getElementType().getAsStringInternal(S, Policy);
+ }
+ else
+ ConstantArrayType::getAsStringInternal(S, Policy);
+}
+
+void ConstantArrayWithoutExprType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
+ if (Policy.ConstantArraySizeAsWritten) {
+ S += "[]";
+ getElementType().getAsStringInternal(S, Policy);
+ }
+ else
+ ConstantArrayType::getAsStringInternal(S, Policy);
+}
+
void IncompleteArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
S += "[]";
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index 2bf8a22..cf8e19a 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -780,6 +780,8 @@
return Slot = CreateType(cast<FunctionType>(Ty), Unit);
case Type::ConstantArray:
+ case Type::ConstantArrayWithExpr:
+ case Type::ConstantArrayWithoutExpr:
case Type::VariableArray:
case Type::IncompleteArray:
return Slot = CreateType(cast<ArrayType>(Ty), Unit);
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 95b1661..7d65c4b 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -1753,7 +1753,32 @@
unsigned IndexTypeQuals = Record[2];
unsigned Idx = 3;
llvm::APInt Size = ReadAPInt(Record, Idx);
- return Context->getConstantArrayType(ElementType, Size, ASM,IndexTypeQuals);
+ return Context->getConstantArrayType(ElementType, Size,
+ ASM, IndexTypeQuals);
+ }
+
+ case pch::TYPE_CONSTANT_ARRAY_WITH_EXPR: {
+ QualType ElementType = GetType(Record[0]);
+ ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
+ unsigned IndexTypeQuals = Record[2];
+ SourceLocation LBLoc = SourceLocation::getFromRawEncoding(Record[3]);
+ SourceLocation RBLoc = SourceLocation::getFromRawEncoding(Record[4]);
+ unsigned Idx = 5;
+ llvm::APInt Size = ReadAPInt(Record, Idx);
+ return Context->getConstantArrayWithExprType(ElementType,
+ Size, ReadTypeExpr(),
+ ASM, IndexTypeQuals,
+ SourceRange(LBLoc, RBLoc));
+ }
+
+ case pch::TYPE_CONSTANT_ARRAY_WITHOUT_EXPR: {
+ QualType ElementType = GetType(Record[0]);
+ ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
+ unsigned IndexTypeQuals = Record[2];
+ unsigned Idx = 3;
+ llvm::APInt Size = ReadAPInt(Record, Idx);
+ return Context->getConstantArrayWithoutExprType(ElementType, Size,
+ ASM, IndexTypeQuals);
}
case pch::TYPE_INCOMPLETE_ARRAY: {
@@ -1767,8 +1792,11 @@
QualType ElementType = GetType(Record[0]);
ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
unsigned IndexTypeQuals = Record[2];
+ SourceLocation LBLoc = SourceLocation::getFromRawEncoding(Record[3]);
+ SourceLocation RBLoc = SourceLocation::getFromRawEncoding(Record[4]);
return Context->getVariableArrayType(ElementType, ReadTypeExpr(),
- ASM, IndexTypeQuals);
+ ASM, IndexTypeQuals,
+ SourceRange(LBLoc, RBLoc));
}
case pch::TYPE_VECTOR: {
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 3bfc9e8..fee2137 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -124,6 +124,23 @@
Code = pch::TYPE_CONSTANT_ARRAY;
}
+void PCHTypeWriter
+::VisitConstantArrayWithExprType(const ConstantArrayWithExprType *T) {
+ VisitArrayType(T);
+ Writer.AddSourceLocation(T->getLBracketLoc(), Record);
+ Writer.AddSourceLocation(T->getRBracketLoc(), Record);
+ Writer.AddAPInt(T->getSize(), Record);
+ Writer.AddStmt(T->getSizeExpr());
+ Code = pch::TYPE_CONSTANT_ARRAY_WITH_EXPR;
+}
+
+void PCHTypeWriter
+::VisitConstantArrayWithoutExprType(const ConstantArrayWithoutExprType *T) {
+ VisitArrayType(T);
+ Writer.AddAPInt(T->getSize(), Record);
+ Code = pch::TYPE_CONSTANT_ARRAY_WITHOUT_EXPR;
+}
+
void PCHTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
VisitArrayType(T);
Code = pch::TYPE_INCOMPLETE_ARRAY;
@@ -131,6 +148,8 @@
void PCHTypeWriter::VisitVariableArrayType(const VariableArrayType *T) {
VisitArrayType(T);
+ Writer.AddSourceLocation(T->getLBracketLoc(), Record);
+ Writer.AddSourceLocation(T->getRBracketLoc(), Record);
Writer.AddStmt(T->getSizeExpr());
Code = pch::TYPE_VARIABLE_ARRAY;
}
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 4a3532c..d599438 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -2690,7 +2690,8 @@
SourceLocation EndLoc = MatchRHSPunctuation(tok::r_square, StartLoc);
// Remember that we parsed the empty array type.
OwningExprResult NumElements(Actions);
- D.AddTypeInfo(DeclaratorChunk::getArray(0, false, false, 0, StartLoc),
+ D.AddTypeInfo(DeclaratorChunk::getArray(0, false, false, 0,
+ StartLoc, EndLoc),
EndLoc);
return;
} else if (Tok.getKind() == tok::numeric_constant &&
@@ -2706,8 +2707,8 @@
ExprRes.release(); // Deallocate expr, just use [].
// Remember that we parsed a array type, and remember its features.
- D.AddTypeInfo(DeclaratorChunk::getArray(0, false, 0,
- ExprRes.release(), StartLoc),
+ D.AddTypeInfo(DeclaratorChunk::getArray(0, false, 0, ExprRes.release(),
+ StartLoc, EndLoc),
EndLoc);
return;
}
@@ -2770,7 +2771,8 @@
// Remember that we parsed a array type, and remember its features.
D.AddTypeInfo(DeclaratorChunk::getArray(DS.getTypeQualifiers(),
StaticLoc.isValid(), isStar,
- NumElements.release(), StartLoc),
+ NumElements.release(),
+ StartLoc, EndLoc),
EndLoc);
}
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index 1220b2d..1c00a8e 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -966,7 +966,7 @@
SourceLocation RLoc = MatchRHSPunctuation(tok::r_square, LLoc);
D.AddTypeInfo(DeclaratorChunk::getArray(0, /*static=*/false, /*star=*/false,
- Size.release(), LLoc),
+ Size.release(), LLoc, RLoc),
RLoc);
if (RLoc.isInvalid())
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index d1e8e21..6cbb1c3 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -282,8 +282,8 @@
llvm::APInt One(Context.getTypeSize(Context.getSizeType()),
true);
QualType T
- = Context.getConstantArrayType(ArrayT->getElementType(),
- One, ArrayType::Normal, 0);
+ = Context.getConstantArrayWithoutExprType(ArrayT->getElementType(),
+ One, ArrayType::Normal, 0);
VD->setType(T);
}
} else if (RequireCompleteType(VD->getLocation(), VD->getType(),
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 7af80c0..4c213b6 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -378,7 +378,7 @@
SourceLocation Loc, DeclarationName Entity);
QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
Expr *ArraySize, unsigned Quals,
- SourceLocation Loc, DeclarationName Entity);
+ SourceRange Brackets, DeclarationName Entity);
QualType BuildExtVectorType(QualType T, ExprArg ArraySize,
SourceLocation AttrLoc);
QualType BuildFunctionType(QualType T,
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 1fd5697..f148e8d 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1568,9 +1568,18 @@
return QualType();
llvm::APSInt &Res = EvalResult.Val.getInt();
- if (Res >= llvm::APSInt(Res.getBitWidth(), Res.isUnsigned()))
- return Context.getConstantArrayType(VLATy->getElementType(),
- Res, ArrayType::Normal, 0);
+ if (Res >= llvm::APSInt(Res.getBitWidth(), Res.isUnsigned())) {
+ Expr* ArySizeExpr = VLATy->getSizeExpr();
+ // FIXME: here we could "steal" (how?) ArySizeExpr from the VLA,
+ // so as to transfer ownership to the ConstantArrayWithExpr.
+ // Alternatively, we could "clone" it (how?).
+ // Since we don't know how to do things above, we just use the
+ // very same Expr*.
+ return Context.getConstantArrayWithExprType(VLATy->getElementType(),
+ Res, ArySizeExpr,
+ ArrayType::Normal, 0,
+ VLATy->getBracketsRange());
+ }
SizeIsNegative = true;
return QualType();
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index ecfdfd7..5be07e3 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -97,8 +97,9 @@
llvm::APSInt ConstVal(32);
ConstVal = StrLength;
// Return a new array type (C99 6.7.8p22).
- DeclT = S.Context.getConstantArrayType(IAT->getElementType(), ConstVal,
- ArrayType::Normal, 0);
+ DeclT = S.Context.getConstantArrayWithoutExprType(IAT->getElementType(),
+ ConstVal,
+ ArrayType::Normal, 0);
return;
}
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 6c2dc77..6ee50ab 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -421,7 +421,20 @@
IntegerLiteral ArraySize(Size, SizeType, Loc);
return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(),
&ArraySize, T->getIndexTypeQualifier(),
- Loc, Entity);
+ SourceRange(), // FIXME: provide proper range?
+ Entity);
+}
+
+QualType
+TemplateTypeInstantiator::InstantiateConstantArrayWithExprType
+(const ConstantArrayWithExprType *T) const {
+ return InstantiateConstantArrayType(T);
+}
+
+QualType
+TemplateTypeInstantiator::InstantiateConstantArrayWithoutExprType
+(const ConstantArrayWithoutExprType *T) const {
+ return InstantiateConstantArrayType(T);
}
QualType
@@ -432,8 +445,9 @@
return ElementType;
return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(),
- 0, T->getIndexTypeQualifier(),
- Loc, Entity);
+ 0, T->getIndexTypeQualifier(),
+ SourceRange(), // FIXME: provide proper range?
+ Entity);
}
QualType
@@ -468,7 +482,9 @@
return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(),
InstantiatedArraySize.takeAs<Expr>(),
- T->getIndexTypeQualifier(), Loc, Entity);
+ T->getIndexTypeQualifier(),
+ SourceRange(), // FIXME: provide proper range?
+ Entity);
}
QualType
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 3756df8..da61e6e 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -483,7 +483,8 @@
/// returns a NULL type.
QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
Expr *ArraySize, unsigned Quals,
- SourceLocation Loc, DeclarationName Entity) {
+ SourceRange Brackets, DeclarationName Entity) {
+ SourceLocation Loc = Brackets.getBegin();
// C99 6.7.5.2p1: If the element type is an incomplete or function type,
// reject it (e.g. void ary[7], struct foo ary[7], void ary[7]())
if (RequireCompleteType(Loc, T,
@@ -530,16 +531,16 @@
llvm::APSInt ConstVal(32);
if (!ArraySize) {
if (ASM == ArrayType::Star)
- T = Context.getVariableArrayType(T, 0, ASM, Quals);
+ T = Context.getVariableArrayType(T, 0, ASM, Quals, Brackets);
else
T = Context.getIncompleteArrayType(T, ASM, Quals);
} else if (ArraySize->isValueDependent()) {
- T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals);
+ T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals, Brackets);
} else if (!ArraySize->isIntegerConstantExpr(ConstVal, Context) ||
(!T->isDependentType() && !T->isConstantSizeType())) {
// Per C99, a variable array is an array with either a non-constant
// size or an element type that has a non-constant-size
- T = Context.getVariableArrayType(T, ArraySize, ASM, Quals);
+ T = Context.getVariableArrayType(T, ArraySize, ASM, Quals, Brackets);
} else {
// C99 6.7.5.2p1: If the expression is a constant expression, it shall
// have a value greater than zero.
@@ -555,7 +556,8 @@
<< ArraySize->getSourceRange();
}
}
- T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);
+ T = Context.getConstantArrayWithExprType(T, ConstVal, ArraySize,
+ ASM, Quals, Brackets);
}
// If this is not C99, extwarn about VLA's and C99 array size modifiers.
if (!getLangOptions().C99) {
@@ -923,7 +925,8 @@
ASM = ArrayType::Normal;
D.setInvalidType(true);
}
- T = BuildArrayType(T, ASM, ArraySize, ATI.TypeQuals, DeclType.Loc, Name);
+ T = BuildArrayType(T, ASM, ArraySize, ATI.TypeQuals,
+ SourceRange(DeclType.Loc, DeclType.EndLoc), Name);
break;
}
case DeclaratorChunk::Function: {