[clang] [clang] Preserve ext_vector_type locations during template substitution (PR #229328)
Chen Miao via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 13 03:29:26 PDT 2026
================
@@ -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());
----------------
ChenMiaoi wrote:
This happens because the patch adds a separate `SizeExpr` field to the dependent vector TypeLocs and initializes it to nullptr. For example:
``` cc
template<int N> struct V {
typedef int type __attribute__((ext_vector_type(N)));
};
```
The Type retains the expression N, but the current TypeLoc-building path does not populate the new TypeLoc field after initialization.
Looking at this again, initializing the field with `setSizeExpr(getTypePtr()->getSizeExpr())`, as `DependentSizedArrayTypeLoc` does, seems better and should allow us to simplify the fallback logic?
https://github.com/llvm/llvm-project/pull/229328
More information about the cfe-commits
mailing list