[clang] [clang] Preserve ext_vector_type locations during template substitution (PR #235689)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 26 03:50:45 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-modules
@llvm/pr-subscribers-clang
Author: Divyanshu Tata (divyanshutata09)
<details>
<summary>Changes</summary>
Instantiating a fixed-length `ext_vector_type` with a dependent element type
emitted an invalid-element diagnostic without any source location.
Record the attribute location and size expression in `VectorTypeLocInfo`
(used by `VectorTypeLoc`, `DependentVectorTypeLoc`, and `DependentSizedExtVectorTypeLoc`)
and preserve them through template substitution in `TreeTransform`, including
when a dependent-sized vector becomes fixed-sized. Also preserve them across
AST traversal and PCH serialization/deserialization.
Fixes #<!-- -->229300
---
Patch is 24.96 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/235689.diff
13 Files Affected:
- (modified) clang/docs/ReleaseNotes.md (+3)
- (modified) clang/include/clang/AST/ASTNodeTraverser.h (+10-1)
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+10-5)
- (modified) clang/include/clang/AST/TypeLoc.h (+29-8)
- (modified) clang/lib/Sema/SemaTemplate.cpp (+2)
- (modified) clang/lib/Sema/SemaType.cpp (+26-6)
- (modified) clang/lib/Sema/TreeTransform.h (+27-13)
- (modified) clang/lib/Serialization/ASTReader.cpp (+7-1)
- (modified) clang/lib/Serialization/ASTWriter.cpp (+7-1)
- (modified) clang/test/PCH/cxx-dependent-sized-ext-vector.cpp (+22-1)
- (modified) clang/test/SemaCXX/vector.cpp (+4-2)
- (modified) clang/test/SemaTemplate/ext-vector-type.cpp (+29-1)
- (modified) clang/unittests/AST/SourceLocationTest.cpp (+29)
``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 44f30666457f94..0bcdefba1aa063 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -458,6 +458,9 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and
### Improvements to Clang's diagnostics
+- Errors for invalid element types during instantiation of an `ext_vector_type`
+ now include a source location, including in alias templates. (#GH229300)
+
- Fixed missing `-Wuninitialized-explicit-init` warnings for C file-scope
tentative definitions of structure types which contain a field marked with
the `require_explicit_initialization` attribute. (#GH232483)
diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h
index 8e09c49982e5d6..c287c100fab88e 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -525,7 +525,16 @@ class ASTNodeTraverser
Visit(TL.getSizeExpr());
}
void VisitDependentSizedExtVectorTypeLoc(DependentSizedExtVectorTypeLoc TL) {
- Visit(cast<DependentSizedExtVectorType>(TL.getType())->getSizeExpr());
+ Expr *Size = TL.getSizeExpr();
+ Visit(Size ? Size : TL.getTypePtr()->getSizeExpr());
+ }
+ void VisitVectorTypeLoc(VectorTypeLoc TL) {
+ if (Expr *Size = TL.getSizeExpr())
+ Visit(Size);
+ }
+ void VisitDependentVectorTypeLoc(DependentVectorTypeLoc TL) {
+ Expr *Size = TL.getSizeExpr();
+ Visit(Size ? Size : TL.getTypePtr()->getSizeExpr());
}
void VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
Visit(TL.getUnderlyingExpr());
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index 13dd5eda84fa65..c7944fd4a10f05 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -1381,25 +1381,30 @@ DEF_TRAVERSE_TYPELOC(DependentAddressSpaceType, {
// FIXME: order? why not size expr first?
// FIXME: base VectorTypeLoc is unfinished
DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
- if (TL.getTypePtr()->getSizeExpr())
- TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
+ Expr *Size = TL.getSizeExpr();
+ if (!Size)
+ Size = TL.getTypePtr()->getSizeExpr();
+ TRY_TO(TraverseStmt(Size));
TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
})
// FIXME: VectorTypeLoc is unfinished
DEF_TRAVERSE_TYPELOC(VectorType, {
+ TRY_TO(TraverseStmt(TL.getSizeExpr()));
TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
})
DEF_TRAVERSE_TYPELOC(DependentVectorType, {
- if (TL.getTypePtr()->getSizeExpr())
- TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
+ Expr *Size = TL.getSizeExpr();
+ if (!Size)
+ Size = TL.getTypePtr()->getSizeExpr();
+ TRY_TO(TraverseStmt(Size));
TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
})
-// FIXME: size and attributes
// FIXME: base VectorTypeLoc is unfinished
DEF_TRAVERSE_TYPELOC(ExtVectorType, {
+ TRY_TO(TraverseStmt(TL.getSizeExpr()));
TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
})
diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h
index b3cb4d0f336295..eb3df4389d4993 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -2062,25 +2062,35 @@ class DependentAddressSpaceTypeLoc
//
//===----------------------------------------------------------------------===//
-// FIXME: size expression and attribute locations (or keyword if we
-// ever fully support altivec syntax).
+// FIXME: keyword location if we ever fully support altivec syntax.
struct VectorTypeLocInfo {
SourceLocation NameLoc;
+ SourceLocation AttrLoc;
+ Expr *SizeExpr;
};
+// FIXME: Make VectorTypeLoc a common base for fixed-size and dependent vector
+// type locations, similar to MatrixTypeLoc.
class VectorTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, VectorTypeLoc,
VectorType, VectorTypeLocInfo> {
public:
SourceLocation getNameLoc() const { return this->getLocalData()->NameLoc; }
-
void setNameLoc(SourceLocation Loc) { this->getLocalData()->NameLoc = Loc; }
+ SourceLocation getAttrNameLoc() const { return getLocalData()->AttrLoc; }
+ void setAttrNameLoc(SourceLocation Loc) { getLocalData()->AttrLoc = Loc; }
+
+ Expr *getSizeExpr() const { return getLocalData()->SizeExpr; }
+ void setSizeExpr(Expr *E) { getLocalData()->SizeExpr = E; }
+
SourceRange getLocalSourceRange() const {
return SourceRange(getNameLoc(), getNameLoc());
}
void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setNameLoc(Loc);
+ setAttrNameLoc(Loc);
+ setSizeExpr(nullptr);
}
TypeLoc getElementLoc() const { return getInnerTypeLoc(); }
@@ -2088,22 +2098,27 @@ class VectorTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, VectorTypeLoc,
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 ConcreteTypeLoc<UnqualTypeLoc, DependentVectorTypeLoc,
DependentVectorType, VectorTypeLocInfo> {
public:
SourceLocation getNameLoc() const { return this->getLocalData()->NameLoc; }
-
void setNameLoc(SourceLocation Loc) { this->getLocalData()->NameLoc = Loc; }
+ SourceLocation getAttrNameLoc() const { return getLocalData()->AttrLoc; }
+ void setAttrNameLoc(SourceLocation Loc) { getLocalData()->AttrLoc = Loc; }
+
+ Expr *getSizeExpr() const { return getLocalData()->SizeExpr; }
+ void setSizeExpr(Expr *E) { getLocalData()->SizeExpr = E; }
+
SourceRange getLocalSourceRange() const {
return SourceRange(getNameLoc(), getNameLoc());
}
void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setNameLoc(Loc);
+ setAttrNameLoc(Loc);
+ setSizeExpr(nullptr);
}
TypeLoc getElementLoc() const { return getInnerTypeLoc(); }
@@ -2111,12 +2126,10 @@ class DependentVectorTypeLoc
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 ConcreteTypeLoc<UnqualTypeLoc, DependentSizedExtVectorTypeLoc,
@@ -2126,12 +2139,20 @@ class DependentSizedExtVectorTypeLoc
void setNameLoc(SourceLocation Loc) { this->getLocalData()->NameLoc = Loc; }
+ SourceLocation getAttrNameLoc() const { return getLocalData()->AttrLoc; }
+ void setAttrNameLoc(SourceLocation Loc) { getLocalData()->AttrLoc = Loc; }
+
+ Expr *getSizeExpr() const { return getLocalData()->SizeExpr; }
+ void setSizeExpr(Expr *E) { getLocalData()->SizeExpr = E; }
+
SourceRange getLocalSourceRange() const {
return SourceRange(getNameLoc(), getNameLoc());
}
void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setNameLoc(Loc);
+ setAttrNameLoc(Loc);
+ setSizeExpr(nullptr);
}
TypeLoc getElementLoc() const { return getInnerTypeLoc(); }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ec1f8077893eb3..f8d5c0d2d65813 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3911,6 +3911,8 @@ QualType Sema::CheckTemplateIdType(ElaboratedTypeKeyword Keyword,
if (!AliasTemplate->getDeclContext()->isFileContext())
SavedContext.emplace(*this, AliasTemplate->getDeclContext());
+ // FIXME: Preserve the pattern's type source information during substitution
+ // while respecting underlying type changes made by mode attributes.
CanonType =
SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
AliasTemplate->getLocation(), AliasTemplate->getDeclName());
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index af0403e73480c0..675eeda667b56e 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5954,6 +5954,26 @@ static void fillMatrixTypeLoc(MatrixTypeLoc MTL,
llvm_unreachable("no matrix_type attribute found at the expected location!");
}
+// FIXME: Also handle attributes on the decl-specifier, declarator and
+// declaration. Matrix type locations need the same handling.
+static void fillVectorTypeLoc(VectorTypeLoc VTL,
+ const ParsedAttributesView &Attrs) {
+ auto Kind = isa<ExtVectorType>(VTL.getTypePtr())
+ ? ParsedAttr::AT_ExtVectorType
+ : ParsedAttr::AT_VectorSize;
+ for (const ParsedAttr &AL : Attrs) {
+ if (AL.getKind() == Kind && !AL.isInvalid() && AL.getNumArgs() == 1) {
+ VTL.setAttrNameLoc(AL.getLoc());
+ VTL.setSizeExpr(AL.getArgAsExpr(0));
+ return;
+ }
+ }
+
+ // The attribute may be on the declarator rather than this chunk, or the
+ // vector may use a target-specific attribute. Keep the default locations
+ // when no matching attribute is present.
+}
+
static void fillAtomicQualLoc(AtomicTypeLoc ATL, const DeclaratorChunk &Chunk) {
SourceLocation Loc;
switch (Chunk.Kind) {
@@ -6356,19 +6376,19 @@ 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 VisitVectorTypeLoc(VectorTypeLoc TL) {
+ TL.initializeLocal(Context, Chunk.Loc);
+ fillVectorTypeLoc(TL, Chunk.getAttrs());
}
- void VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
- TL.setNameLoc(Chunk.Loc);
+ void VisitDependentVectorTypeLoc(DependentVectorTypeLoc TL) {
+ TL.initializeLocal(Context, Chunk.Loc);
}
void VisitAtomicTypeLoc(AtomicTypeLoc TL) {
fillAtomicQualLoc(TL, Chunk);
}
void
VisitDependentSizedExtVectorTypeLoc(DependentSizedExtVectorTypeLoc TL) {
- TL.setNameLoc(Chunk.Loc);
+ TL.initializeLocal(Context, Chunk.Loc);
}
void VisitMatrixTypeLoc(MatrixTypeLoc TL) {
fillMatrixTypeLoc(TL, Chunk.getAttrs());
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 25e9113aeb7a46..0aa15b5c999e3a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6213,14 +6213,17 @@ QualType TreeTransform<Derived>::TransformDependentVectorType(
EnterExpressionEvaluationContext Unevaluated(
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
- ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
+ Expr *OrigSize = TL.getSizeExpr();
+ if (!OrigSize)
+ OrigSize = T->getSizeExpr();
+ ExprResult Size = getDerived().TransformExpr(OrigSize);
Size = SemaRef.ActOnConstantExpression(Size);
if (Size.isInvalid())
return QualType();
QualType Result = TL.getType();
if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
- Size.get() != T->getSizeExpr()) {
+ Size.get() != OrigSize) {
Result = getDerived().RebuildDependentVectorType(
ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
if (Result.isNull())
@@ -6232,9 +6235,13 @@ QualType TreeTransform<Derived>::TransformDependentVectorType(
DependentVectorTypeLoc NewTL =
TLB.push<DependentVectorTypeLoc>(Result);
NewTL.setNameLoc(TL.getNameLoc());
+ NewTL.setAttrNameLoc(TL.getAttrNameLoc());
+ NewTL.setSizeExpr(Size.get());
} else {
VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
NewTL.setNameLoc(TL.getNameLoc());
+ NewTL.setAttrNameLoc(TL.getAttrNameLoc());
+ NewTL.setSizeExpr(Size.get());
}
return Result;
@@ -6246,7 +6253,6 @@ QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
DependentSizedExtVectorTypeLoc TL) {
const DependentSizedExtVectorType *T = TL.getTypePtr();
- // FIXME: ext vector locs should be nested
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
if (ElementType.isNull())
return QualType();
@@ -6255,18 +6261,19 @@ QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
EnterExpressionEvaluationContext Unevaluated(
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
- ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
+ Expr *OrigSize = TL.getSizeExpr();
+ if (!OrigSize)
+ OrigSize = T->getSizeExpr();
+ ExprResult Size = getDerived().TransformExpr(OrigSize);
Size = SemaRef.ActOnConstantExpression(Size);
if (Size.isInvalid())
return QualType();
QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- ElementType != T->getElementType() ||
- Size.get() != T->getSizeExpr()) {
- Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
- Size.get(),
- T->getAttributeLoc());
+ if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
+ Size.get() != OrigSize) {
+ Result = getDerived().RebuildDependentSizedExtVectorType(
+ ElementType, Size.get(), T->getAttributeLoc());
if (Result.isNull())
return QualType();
}
@@ -6276,9 +6283,13 @@ QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
DependentSizedExtVectorTypeLoc NewTL
= TLB.push<DependentSizedExtVectorTypeLoc>(Result);
NewTL.setNameLoc(TL.getNameLoc());
+ NewTL.setAttrNameLoc(TL.getAttrNameLoc());
+ NewTL.setSizeExpr(Size.get());
} else {
ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
NewTL.setNameLoc(TL.getNameLoc());
+ NewTL.setAttrNameLoc(TL.getAttrNameLoc());
+ NewTL.setSizeExpr(Size.get());
}
return Result;
@@ -6428,6 +6439,8 @@ QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
NewTL.setNameLoc(TL.getNameLoc());
+ NewTL.setAttrNameLoc(TL.getAttrNameLoc());
+ NewTL.setSizeExpr(TL.getSizeExpr());
return Result;
}
@@ -6443,15 +6456,16 @@ QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
QualType Result = TL.getType();
if (getDerived().AlwaysRebuild() ||
ElementType != T->getElementType()) {
- Result = getDerived().RebuildExtVectorType(ElementType,
- T->getNumElements(),
- /*FIXME*/ SourceLocation());
+ Result = getDerived().RebuildExtVectorType(ElementType, T->getNumElements(),
+ TL.getAttrNameLoc());
if (Result.isNull())
return QualType();
}
ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
NewTL.setNameLoc(TL.getNameLoc());
+ NewTL.setAttrNameLoc(TL.getAttrNameLoc());
+ NewTL.setSizeExpr(TL.getSizeExpr());
return Result;
}
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 56f1aa8a7f932a..0bed289ecbbc67 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -7670,19 +7670,25 @@ void TypeLocReader::VisitDependentAddressSpaceTypeLoc(
void TypeLocReader::VisitDependentSizedExtVectorTypeLoc(
DependentSizedExtVectorTypeLoc TL) {
TL.setNameLoc(readSourceLocation());
+ TL.setAttrNameLoc(readSourceLocation());
+ TL.setSizeExpr(Reader.readExpr());
}
void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) {
TL.setNameLoc(readSourceLocation());
+ TL.setAttrNameLoc(readSourceLocation());
+ TL.setSizeExpr(Reader.readExpr());
}
void TypeLocReader::VisitDependentVectorTypeLoc(
DependentVectorTypeLoc TL) {
TL.setNameLoc(readSourceLocation());
+ TL.setAttrNameLoc(readSourceLocation());
+ TL.setSizeExpr(Reader.readExpr());
}
void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
- TL.setNameLoc(readSourceLocation());
+ VisitVectorTypeLoc(TL);
}
void TypeLocReader::VisitConstantMatrixTypeLoc(ConstantMatrixTypeLoc TL) {
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index cb89eaffc4bf00..95ff6cdb4d7e5a 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -433,19 +433,25 @@ void TypeLocWriter::VisitDependentAddressSpaceTypeLoc(
void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc(
DependentSizedExtVectorTypeLoc TL) {
addSourceLocation(TL.getNameLoc());
+ addSourceLocation(TL.getAttrNameLoc());
+ Record.AddStmt(TL.getSizeExpr());
}
void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) {
addSourceLocation(TL.getNameLoc());
+ addSourceLocation(TL.getAttrNameLoc());
+ Record.AddStmt(TL.getSizeExpr());
}
void TypeLocWriter::VisitDependentVectorTypeLoc(
DependentVectorTypeLoc TL) {
addSourceLocation(TL.getNameLoc());
+ addSourceLocation(TL.getAttrNameLoc());
+ Record.AddStmt(TL.getSizeExpr());
}
void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
- addSourceLocation(TL.getNameLoc());
+ VisitVectorTypeLoc(TL);
}
void TypeLocWriter::VisitConstantMatrixTypeLoc(ConstantMatrixTypeLoc TL) {
diff --git a/clang/test/PCH/cxx-dependent-sized-ext-vector.cpp b/clang/test/PCH/cxx-dependent-sized-ext-vector.cpp
index 93fb56161dfc00..23345a03c0663b 100644
--- a/clang/test/PCH/cxx-dependent-sized-ext-vector.cpp
+++ b/clang/test/PCH/cxx-dependent-sized-ext-vector.cpp
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 -std=c++11 -emit-pch %s -o %t
// RUN: %clang_cc1 -std=c++11 -include-pch %t -verify %s
+// RUN: not %clang_cc1 -std=c++11 -include-pch %t -fno-caret-diagnostics %s 2>&1 | FileCheck %s --implicit-check-not='error:'
// RUN: %clang_cc1 -std=c++11 -emit-pch -fpch-instantiate-templates %s -o %t
// RUN: %clang_cc1 -std=c++11 -include-pch %t -verify %s
@@ -9,13 +10,33 @@
#define HEADER_INCLUDED
template<typename T, int N>
+// CHECK: :[[#@LINE+1]]:30: error: zero vector size
using vec = T __attribute__((ext_vector_type(N)));
+struct S {};
+
+template <class T>
+// CHECK: :[[#@LINE+1]]:1: error: invalid vector element type 'S'
+using Alias = T __attribute__((ext_vector_type(4)));
+
+template <class T, int N>
+// CHECK: :[[#@LINE+1]]:32: error: invalid vector element type 'S'
+using Sized = T __attribute__((vector_size(N)));
+
+template <class T> struct Attributed {
+ // CHECK: :[[#@LINE+1]]:29: error: invalid vector element type 'S'
+ typedef T (__attribute__((ext_vector_type(4))) Type);
+};
+
#else
void test() {
- vec<float, 2> a; // expected-error at -5 {{zero vector size}}
+ vec<float, 2> a; // expected-error at -20 {{zero vector size}}
vec<float, 0> b; // expected-note {{in instantiation of template type alias 'vec' requested here}}
}
+Alias<S> alias; // expected-error at -18 {{invalid vector element type 'S'}} expected-note {{in instantiation of template type alias 'Alias' requested here}}
+Sized<S, 16> invalid_sized; // expected-error at -15 {{invalid vector element type 'S'}} expected-note {{in instantiation of template type alias 'Sized' requested here}}
+Attributed<S> attributed; // expected-error at -12 {{invalid vector element type 'S'}} expected-note {{in instantiation of template class 'Attributed<S>' requested here}}
+
#endif
diff --git a/clang/test/SemaCXX/vector.cpp b/clang/test/SemaCXX/vector.cpp
index fd6127a33f1ae6..6ae7d3103d3f54 100644
--- a/clang/test/SemaCXX/vector.cpp
+++ b/clang/test/SemaCXX/vector.cpp
@@ -5,6 +5,7 @@
// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++20 %s
// RUN: %clang_cc1 -flax-vector-conversions=integer -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT
// RUN: %clang_cc1 -flax-vector-conversions=none -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT -DNO_LAX_INT
+// RUN: not %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -fno...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/235689
More information about the cfe-commits
mailing list