diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h --- a/clang/include/clang/AST/TypeLoc.h +++ b/clang/include/clang/AST/TypeLoc.h @@ -1749,30 +1749,79 @@ // FIXME: size expression and attribute locations (or keyword if we // ever fully support altivec syntax). -class VectorTypeLoc : public InheritingConcreteTypeLoc { +struct VectorTypeLocInfo { + SourceLocation NameLoc; +}; + +class VectorTypeLoc : public ConcreteTypeLoc { +public: + SourceLocation getNameLoc() const { return this->getLocalData()->NameLoc; } + + void setNameLoc(SourceLocation Loc) { this->getLocalData()->NameLoc = Loc; } + + SourceRange getLocalSourceRange() const { + return SourceRange(getNameLoc(), getNameLoc()); + } + + void initializeLocal(ASTContext &Context, SourceLocation Loc) { + setNameLoc(Loc); + } + + TypeLoc getElementLoc() const { return getInnerTypeLoc(); } + + QualType getInnerType() const { return this->getTypePtr()->getElementType(); } }; // FIXME: size expression and attribute locations (or keyword if we // ever fully support altivec syntax). class DependentVectorTypeLoc - : public InheritingConcreteTypeLoc {}; + : public ConcreteTypeLoc { +public: + SourceLocation getNameLoc() const { return this->getLocalData()->NameLoc; } -// FIXME: size expression and attribute locations. -class ExtVectorTypeLoc : public InheritingConcreteTypeLoc { + void setNameLoc(SourceLocation Loc) { this->getLocalData()->NameLoc = Loc; } + + SourceRange getLocalSourceRange() const { + return SourceRange(getNameLoc(), getNameLoc()); + } + + void initializeLocal(ASTContext &Context, SourceLocation Loc) { + setNameLoc(Loc); + } + + TypeLoc getElementLoc() const { return getInnerTypeLoc(); } + + QualType getInnerType() const { return this->getTypePtr()->getElementType(); } }; +// FIXME: size expression and attribute locations. +class ExtVectorTypeLoc + : public InheritingConcreteTypeLoc {}; + // FIXME: attribute locations. // For some reason, this isn't a subtype of VectorType. -class DependentSizedExtVectorTypeLoc : - public InheritingConcreteTypeLoc { +class DependentSizedExtVectorTypeLoc + : public ConcreteTypeLoc { +public: + SourceLocation getNameLoc() const { return this->getLocalData()->NameLoc; } + + void setNameLoc(SourceLocation Loc) { this->getLocalData()->NameLoc = Loc; } + + SourceRange getLocalSourceRange() const { + return SourceRange(getNameLoc(), getNameLoc()); + } + + void initializeLocal(ASTContext &Context, SourceLocation Loc) { + setNameLoc(Loc); + } + + TypeLoc getElementLoc() const { return getInnerTypeLoc(); } + + QualType getInnerType() const { return this->getTypePtr()->getElementType(); } }; struct MatrixTypeLocInfo { diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -6135,6 +6135,17 @@ void VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) { TL.setExpansionLoc(Chunk.Loc); } + void VisitVectorTypeLoc(VectorTypeLoc TL) { TL.setNameLoc(Chunk.Loc); } + void VisitDependentVectorTypeLoc(DependentVectorTypeLoc TL) { + TL.setNameLoc(Chunk.Loc); + } + void VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { + TL.setNameLoc(Chunk.Loc); + } + void + VisitDependentSizedExtVectorTypeLoc(DependentSizedExtVectorTypeLoc TL) { + TL.setNameLoc(Chunk.Loc); + } void VisitTypeLoc(TypeLoc TL) { llvm_unreachable("unsupported TypeLoc kind in declarator!"); diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -5178,7 +5178,7 @@ QualType TreeTransform::TransformDependentVectorType( TypeLocBuilder &TLB, DependentVectorTypeLoc TL) { const DependentVectorType *T = TL.getTypePtr(); - QualType ElementType = getDerived().TransformType(T->getElementType()); + QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); if (ElementType.isNull()) return QualType(); @@ -5219,7 +5219,7 @@ const DependentSizedExtVectorType *T = TL.getTypePtr(); // FIXME: ext vector locs should be nested - QualType ElementType = getDerived().TransformType(T->getElementType()); + QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); if (ElementType.isNull()) return QualType(); @@ -5386,7 +5386,7 @@ QualType TreeTransform::TransformVectorType(TypeLocBuilder &TLB, VectorTypeLoc TL) { const VectorType *T = TL.getTypePtr(); - QualType ElementType = getDerived().TransformType(T->getElementType()); + QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); if (ElementType.isNull()) return QualType(); @@ -5409,7 +5409,7 @@ QualType TreeTransform::TransformExtVectorType(TypeLocBuilder &TLB, ExtVectorTypeLoc TL) { const VectorType *T = TL.getTypePtr(); - QualType ElementType = getDerived().TransformType(T->getElementType()); + QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); if (ElementType.isNull()) return QualType(); diff --git a/clang/test/SemaCXX/vector.cpp b/clang/test/SemaCXX/vector.cpp --- a/clang/test/SemaCXX/vector.cpp +++ b/clang/test/SemaCXX/vector.cpp @@ -513,3 +513,20 @@ } } // namespace PR45780 + +namespace PR48540 { +// The below used to cause an OOM error, or an assert, make sure it is still +// valid. +int (__attribute__((vector_size(16))) a); + +template +struct S { + T (__attribute__((vector_size(16))) a); + int (__attribute__((vector_size(I))) b); + T (__attribute__((vector_size(I))) c); +}; + +void use() { + S s; +} +} // namespace PR48540