diff options
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/Sema.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 15 | ||||
-rw-r--r-- | lib/Sema/SemaInit.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 24 | ||||
-rw-r--r-- | lib/Sema/SemaType.cpp | 15 |
6 files changed, 47 insertions, 18 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index d1e8e2104d..6cbb1c3712 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -282,8 +282,8 @@ void Sema::ActOnEndOfTranslationUnit() { 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 7af80c0261..4c213b6594 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -378,7 +378,7 @@ public: 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 1fd569729a..f148e8d0e1 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1568,9 +1568,18 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T, 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 ecfdfd7ba0..5be07e3986 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -97,8 +97,9 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, Sema &S) { 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 6c2dc77b4c..6ee50ab98c 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -421,7 +421,20 @@ InstantiateConstantArrayType(const ConstantArrayType *T) const { 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 @@ InstantiateIncompleteArrayType(const IncompleteArrayType *T) const { 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 @@ InstantiateDependentSizedArrayType(const DependentSizedArrayType *T) const { 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 3756df870c..da61e6eb9e 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -483,7 +483,8 @@ QualType Sema::BuildReferenceType(QualType T, bool LValueRef, unsigned Quals, /// 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 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, 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 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, << 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 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip, 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: { |