[llvm-branch-commits] [clang] 43043ad - Add element-type to the Vector TypeLoc types.
Erich Keane via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jan 7 09:19:09 PST 2021
Author: Erich Keane
Date: 2021-01-07T09:14:36-08:00
New Revision: 43043adcfbc60945646b791d7162e5a1307a5318
URL: https://github.com/llvm/llvm-project/commit/43043adcfbc60945646b791d7162e5a1307a5318
DIFF: https://github.com/llvm/llvm-project/commit/43043adcfbc60945646b791d7162e5a1307a5318.diff
LOG: Add element-type to the Vector TypeLoc types.
As shown by bug 48540, GCC vector types would cause a crash when the
declaration hada ParenType. This was because the walking of the
declaration would try to expand the 'inner' type, but there was no
ability to get it from the vector type. This patch adds that element
type access to the vector type loc objects.
Differential Revision: https://reviews.llvm.org/D93483
Added:
Modified:
clang/include/clang/AST/TypeLoc.h
clang/lib/Sema/SemaType.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaCXX/vector.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h
index 4c320ce26e4f..65e95d52c303 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -1749,30 +1749,79 @@ class DependentAddressSpaceTypeLoc
// FIXME: size expression and attribute locations (or keyword if we
// ever fully support altivec syntax).
-class VectorTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
- VectorTypeLoc,
- VectorType> {
+struct VectorTypeLocInfo {
+ SourceLocation NameLoc;
+};
+
+class VectorTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, VectorTypeLoc,
+ VectorType, VectorTypeLocInfo> {
+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<TypeSpecTypeLoc,
- DependentVectorTypeLoc,
- DependentVectorType> {};
+ : public ConcreteTypeLoc<UnqualTypeLoc, DependentVectorTypeLoc,
+ DependentVectorType, VectorTypeLocInfo> {
+public:
+ SourceLocation getNameLoc() const { return this->getLocalData()->NameLoc; }
-// FIXME: size expression and attribute locations.
-class ExtVectorTypeLoc : public InheritingConcreteTypeLoc<VectorTypeLoc,
- ExtVectorTypeLoc,
- ExtVectorType> {
+ 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<VectorTypeLoc, ExtVectorTypeLoc,
+ ExtVectorType> {};
+
// FIXME: attribute locations.
// For some reason, this isn't a subtype of VectorType.
-class DependentSizedExtVectorTypeLoc :
- public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
- DependentSizedExtVectorTypeLoc,
- DependentSizedExtVectorType> {
+class DependentSizedExtVectorTypeLoc
+ : public ConcreteTypeLoc<UnqualTypeLoc, DependentSizedExtVectorTypeLoc,
+ DependentSizedExtVectorType, VectorTypeLocInfo> {
+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
index f51c616169f5..fe775b82a1d6 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -6135,6 +6135,17 @@ namespace {
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
index 2cc8b9c8324f..0a596e50658b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -5178,7 +5178,7 @@ template <typename Derived>
QualType TreeTransform<Derived>::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 @@ QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
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 @@ template <typename Derived>
QualType TreeTransform<Derived>::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 @@ template<typename Derived>
QualType TreeTransform<Derived>::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
index 4b2ebc99a183..9608be576fab 100644
--- a/clang/test/SemaCXX/vector.cpp
+++ b/clang/test/SemaCXX/vector.cpp
@@ -513,3 +513,20 @@ void use(char16 c) {
}
} // 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 <typename T, int I>
+struct S {
+ T (__attribute__((vector_size(16))) a);
+ int (__attribute__((vector_size(I))) b);
+ T (__attribute__((vector_size(I))) c);
+};
+
+void use() {
+ S<int, 16> s;
+}
+} // namespace PR48540
More information about the llvm-branch-commits
mailing list