[clang] [clang] AST: remove source locations from [Variable/Dependent]SizedArrayType (PR #135511)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 12 18:18:15 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Matheus Izvekov (mizvekov)
<details>
<summary>Changes</summary>
Source locations should be handled at the TypeLoc level,
and these locations are already wired up to the base ArrayLoc.
There was nothing important using these, so just remove.
---
Patch is 27.63 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/135511.diff
15 Files Affected:
- (modified) clang/include/clang/AST/ASTContext.h (+3-4)
- (modified) clang/include/clang/AST/Type.h (+4-21)
- (modified) clang/include/clang/AST/TypeProperties.td (+3-21)
- (modified) clang/lib/AST/ASTContext.cpp (+27-43)
- (modified) clang/lib/AST/ASTDiagnostic.cpp (+4-4)
- (modified) clang/lib/AST/ASTImporter.cpp (+2-4)
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+1-1)
- (modified) clang/lib/AST/TextNodeDumper.cpp (-4)
- (modified) clang/lib/AST/Type.cpp (+3-6)
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+2-2)
- (modified) clang/lib/Sema/SemaInit.cpp (+5-21)
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+2-2)
- (modified) clang/lib/Sema/SemaType.cpp (+7-7)
- (modified) clang/test/AST/ast-dump-array.cpp (+2-2)
- (modified) clang/test/SemaTemplate/deduction-guide.cpp (+1-1)
``````````diff
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index 0f6c727f6f9ca..3c78833a3f069 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1564,8 +1564,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// Return a non-unique reference to the type for a variable array of
/// the specified element type.
QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
- ArraySizeModifier ASM, unsigned IndexTypeQuals,
- SourceRange Brackets) const;
+ ArraySizeModifier ASM,
+ unsigned IndexTypeQuals) const;
/// Return a non-unique reference to the type for a dependently-sized
/// array of the specified element type.
@@ -1574,8 +1574,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// point.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
ArraySizeModifier ASM,
- unsigned IndexTypeQuals,
- SourceRange Brackets) const;
+ unsigned IndexTypeQuals) const;
/// Return a unique reference to the type for an incomplete array of
/// the specified element type.
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index fe62120a25643..74886ef0cd824 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3827,14 +3827,9 @@ class VariableArrayType : public ArrayType {
/// a function block.
Stmt *SizeExpr;
- /// The range spanned by the left and right array brackets.
- SourceRange Brackets;
-
- VariableArrayType(QualType et, QualType can, Expr *e,
- ArraySizeModifier sm, unsigned tq,
- SourceRange brackets)
- : ArrayType(VariableArray, et, can, sm, tq, e),
- SizeExpr((Stmt*) e), Brackets(brackets) {}
+ VariableArrayType(QualType et, QualType can, Expr *e, ArraySizeModifier sm,
+ unsigned tq)
+ : ArrayType(VariableArray, et, can, sm, tq, e), SizeExpr((Stmt *)e) {}
public:
friend class StmtIteratorBase;
@@ -3845,10 +3840,6 @@ class VariableArrayType : public ArrayType {
return (Expr*) SizeExpr;
}
- SourceRange getBracketsRange() const { return Brackets; }
- SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
- SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
-
bool isSugared() const { return false; }
QualType desugar() const { return QualType(this, 0); }
@@ -3884,12 +3875,8 @@ class DependentSizedArrayType : public ArrayType {
/// type will have its size deduced from an initializer.
Stmt *SizeExpr;
- /// The range spanned by the left and right array brackets.
- SourceRange Brackets;
-
DependentSizedArrayType(QualType et, QualType can, Expr *e,
- ArraySizeModifier sm, unsigned tq,
- SourceRange brackets);
+ ArraySizeModifier sm, unsigned tq);
public:
friend class StmtIteratorBase;
@@ -3900,10 +3887,6 @@ class DependentSizedArrayType : public ArrayType {
return (Expr*) SizeExpr;
}
- SourceRange getBracketsRange() const { return Brackets; }
- SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
- SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
-
bool isSugared() const { return false; }
QualType desugar() const { return QualType(this, 0); }
diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td
index 3bf9239e9cbf5..f4b8ce0994ba8 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -154,40 +154,22 @@ let Class = IncompleteArrayType in {
}
let Class = VariableArrayType in {
- def : Property<"leftBracketLoc", SourceLocation> {
- let Read = [{ node->getLBracketLoc() }];
- }
- def : Property<"rightBracketLoc", SourceLocation> {
- let Read = [{ node->getRBracketLoc() }];
- }
def : Property<"size", ExprRef> {
let Read = [{ node->getSizeExpr() }];
}
def : Creator<[{
return ctx.getVariableArrayType(elementType, size, sizeModifier,
- indexQualifiers.getCVRQualifiers(),
- SourceRange(leftBracketLoc,
- rightBracketLoc));
+ indexQualifiers.getCVRQualifiers());
}]>;
}
let Class = DependentSizedArrayType in {
- def : Property<"size", ExprRef> {
- let Read = [{ node->getSizeExpr() }];
- }
- def : Property<"leftBracketLoc", SourceLocation> {
- let Read = [{ node->getLBracketLoc() }];
- }
- def : Property<"rightBracketLoc", SourceLocation> {
- let Read = [{ node->getRBracketLoc() }];
- }
+ def : Property<"size", ExprRef> { let Read = [{ node->getSizeExpr() }]; }
def : Creator<[{
return ctx.getDependentSizedArrayType(elementType, size, sizeModifier,
- indexQualifiers.getCVRQualifiers(),
- SourceRange(leftBracketLoc,
- rightBracketLoc));
+ indexQualifiers.getCVRQualifiers());
}]>;
}
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 46bd1977d688d..dfae2f5511b43 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4261,11 +4261,8 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const {
case Type::DependentSizedArray: {
const auto *dat = cast<DependentSizedArrayType>(ty);
result = getDependentSizedArrayType(
- getVariableArrayDecayedType(dat->getElementType()),
- dat->getSizeExpr(),
- dat->getSizeModifier(),
- dat->getIndexTypeCVRQualifiers(),
- dat->getBracketsRange());
+ getVariableArrayDecayedType(dat->getElementType()), dat->getSizeExpr(),
+ dat->getSizeModifier(), dat->getIndexTypeCVRQualifiers());
break;
}
@@ -4275,17 +4272,17 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const {
result =
getVariableArrayType(getVariableArrayDecayedType(iat->getElementType()),
/*size*/ nullptr, ArraySizeModifier::Normal,
- iat->getIndexTypeCVRQualifiers(), SourceRange());
+ iat->getIndexTypeCVRQualifiers());
break;
}
// Turn VLA types into [*] types.
case Type::VariableArray: {
const auto *vat = cast<VariableArrayType>(ty);
- result = getVariableArrayType(
- getVariableArrayDecayedType(vat->getElementType()),
- /*size*/ nullptr, ArraySizeModifier::Star,
- vat->getIndexTypeCVRQualifiers(), vat->getBracketsRange());
+ result =
+ getVariableArrayType(getVariableArrayDecayedType(vat->getElementType()),
+ /*size*/ nullptr, ArraySizeModifier::Star,
+ vat->getIndexTypeCVRQualifiers());
break;
}
}
@@ -4298,8 +4295,7 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const {
/// variable array of the specified element type.
QualType ASTContext::getVariableArrayType(QualType EltTy, Expr *NumElts,
ArraySizeModifier ASM,
- unsigned IndexTypeQuals,
- SourceRange Brackets) const {
+ unsigned IndexTypeQuals) const {
// Since we don't unique expressions, it isn't possible to unique VLA's
// that have an expression provided for their size.
QualType Canon;
@@ -4309,12 +4305,12 @@ QualType ASTContext::getVariableArrayType(QualType EltTy, Expr *NumElts,
if (!EltTy.isCanonical() || EltTy.hasLocalQualifiers()) {
SplitQualType canonSplit = getCanonicalType(EltTy).split();
Canon = getVariableArrayType(QualType(canonSplit.Ty, 0), NumElts, ASM,
- IndexTypeQuals, Brackets);
+ IndexTypeQuals);
Canon = getQualifiedType(Canon, canonSplit.Quals);
}
auto *New = new (*this, alignof(VariableArrayType))
- VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals, Brackets);
+ VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals);
VariableArrayTypes.push_back(New);
Types.push_back(New);
@@ -4324,11 +4320,10 @@ QualType ASTContext::getVariableArrayType(QualType EltTy, Expr *NumElts,
/// getDependentSizedArrayType - Returns a non-unique reference to
/// the type for a dependently-sized array of the specified element
/// type.
-QualType ASTContext::getDependentSizedArrayType(QualType elementType,
- Expr *numElements,
- ArraySizeModifier ASM,
- unsigned elementTypeQuals,
- SourceRange brackets) const {
+QualType
+ASTContext::getDependentSizedArrayType(QualType elementType, Expr *numElements,
+ ArraySizeModifier ASM,
+ unsigned elementTypeQuals) const {
assert((!numElements || numElements->isTypeDependent() ||
numElements->isValueDependent()) &&
"Size must be type- or value-dependent!");
@@ -4354,7 +4349,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType,
auto *newType = new (*this, alignof(DependentSizedArrayType))
DependentSizedArrayType(elementType, QualType(), numElements, ASM,
- elementTypeQuals, brackets);
+ elementTypeQuals);
DependentSizedArrayTypes.InsertNode(newType, insertPos);
Types.push_back(newType);
return QualType(newType, 0);
@@ -4364,7 +4359,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType,
if (!canonTy) {
canonTy = new (*this, alignof(DependentSizedArrayType))
DependentSizedArrayType(QualType(canonElementType.Ty, 0), QualType(),
- numElements, ASM, elementTypeQuals, brackets);
+ numElements, ASM, elementTypeQuals);
DependentSizedArrayTypes.InsertNode(canonTy, insertPos);
Types.push_back(canonTy);
}
@@ -4383,7 +4378,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType,
// of the element type.
auto *sugaredType = new (*this, alignof(DependentSizedArrayType))
DependentSizedArrayType(elementType, canon, numElements, ASM,
- elementTypeQuals, brackets);
+ elementTypeQuals);
Types.push_back(sugaredType);
return QualType(sugaredType, 0);
}
@@ -6775,17 +6770,14 @@ QualType ASTContext::getUnqualifiedArrayType(QualType type,
}
if (const auto *VAT = dyn_cast<VariableArrayType>(AT)) {
- return getVariableArrayType(unqualElementType,
- VAT->getSizeExpr(),
+ return getVariableArrayType(unqualElementType, VAT->getSizeExpr(),
VAT->getSizeModifier(),
- VAT->getIndexTypeCVRQualifiers(),
- VAT->getBracketsRange());
+ VAT->getIndexTypeCVRQualifiers());
}
const auto *DSAT = cast<DependentSizedArrayType>(AT);
return getDependentSizedArrayType(unqualElementType, DSAT->getSizeExpr(),
- DSAT->getSizeModifier(), 0,
- SourceRange());
+ DSAT->getSizeModifier(), 0);
}
/// Attempt to unwrap two types that may both be array types with the same bound
@@ -7729,19 +7721,14 @@ const ArrayType *ASTContext::getAsArrayType(QualType T) const {
IAT->getIndexTypeCVRQualifiers()));
if (const auto *DSAT = dyn_cast<DependentSizedArrayType>(ATy))
- return cast<ArrayType>(
- getDependentSizedArrayType(NewEltTy,
- DSAT->getSizeExpr(),
- DSAT->getSizeModifier(),
- DSAT->getIndexTypeCVRQualifiers(),
- DSAT->getBracketsRange()));
+ return cast<ArrayType>(getDependentSizedArrayType(
+ NewEltTy, DSAT->getSizeExpr(), DSAT->getSizeModifier(),
+ DSAT->getIndexTypeCVRQualifiers()));
const auto *VAT = cast<VariableArrayType>(ATy);
- return cast<ArrayType>(getVariableArrayType(NewEltTy,
- VAT->getSizeExpr(),
- VAT->getSizeModifier(),
- VAT->getIndexTypeCVRQualifiers(),
- VAT->getBracketsRange()));
+ return cast<ArrayType>(
+ getVariableArrayType(NewEltTy, VAT->getSizeExpr(), VAT->getSizeModifier(),
+ VAT->getIndexTypeCVRQualifiers()));
}
QualType ASTContext::getAdjustedParameterType(QualType T) const {
@@ -13846,10 +13833,7 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
return Ctx.getDependentSizedArrayType(
getCommonArrayElementType(Ctx, AX, QX, AY, QY),
getCommonSizeExpr(Ctx, AX, AY), getCommonSizeModifier(AX, AY),
- getCommonIndexTypeCVRQualifiers(AX, AY),
- AX->getBracketsRange() == AY->getBracketsRange()
- ? AX->getBracketsRange()
- : SourceRange());
+ getCommonIndexTypeCVRQualifiers(AX, AY));
}
case Type::ConstantArray: {
const auto *AX = cast<ConstantArrayType>(X),
diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 5baff6c1e13e9..5c8acde452dbc 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -142,13 +142,13 @@ QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
ElementTy, CAT->getSize(), CAT->getSizeExpr(),
CAT->getSizeModifier(), CAT->getIndexTypeCVRQualifiers());
else if (const auto *VAT = dyn_cast<VariableArrayType>(AT))
- QT = Context.getVariableArrayType(
- ElementTy, VAT->getSizeExpr(), VAT->getSizeModifier(),
- VAT->getIndexTypeCVRQualifiers(), VAT->getBracketsRange());
+ QT = Context.getVariableArrayType(ElementTy, VAT->getSizeExpr(),
+ VAT->getSizeModifier(),
+ VAT->getIndexTypeCVRQualifiers());
else if (const auto *DSAT = dyn_cast<DependentSizedArrayType>(AT))
QT = Context.getDependentSizedArrayType(
ElementTy, DSAT->getSizeExpr(), DSAT->getSizeModifier(),
- DSAT->getIndexTypeCVRQualifiers(), DSAT->getBracketsRange());
+ DSAT->getIndexTypeCVRQualifiers());
else if (const auto *IAT = dyn_cast<IncompleteArrayType>(AT))
QT = Context.getIncompleteArrayType(ElementTy, IAT->getSizeModifier(),
IAT->getIndexTypeCVRQualifiers());
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 378734e9c1909..b55b8f2c14147 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -1295,12 +1295,11 @@ ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
Error Err = Error::success();
QualType ToElementType = importChecked(Err, T->getElementType());
Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
- SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
if (Err)
return std::move(Err);
return Importer.getToContext().getVariableArrayType(
ToElementType, ToSizeExpr, T->getSizeModifier(),
- T->getIndexTypeCVRQualifiers(), ToBracketsRange);
+ T->getIndexTypeCVRQualifiers());
}
ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
@@ -1308,7 +1307,6 @@ ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
Error Err = Error::success();
QualType ToElementType = importChecked(Err, T->getElementType());
Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
- SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
if (Err)
return std::move(Err);
// SizeExpr may be null if size is not specified directly.
@@ -1316,7 +1314,7 @@ ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
return Importer.getToContext().getDependentSizedArrayType(
ToElementType, ToSizeExpr, T->getSizeModifier(),
- T->getIndexTypeCVRQualifiers(), ToBracketsRange);
+ T->getIndexTypeCVRQualifiers());
}
ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 4d14614fc1ec7..88f6926929ea9 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -3312,7 +3312,7 @@ void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) {
const DependentSizedArrayType *DSAT =
getASTContext().getAsDependentSizedArrayType(ElementTy);
Error(DSAT->getSizeExpr()->getExprLoc(), "dependent-length")
- << DSAT->getBracketsRange();
+ << DSAT->getSizeExpr()->getSourceRange();
return;
} else {
break;
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index be8d609974d81..837477c112f3d 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1941,16 +1941,12 @@ void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) {
}
void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) {
- OS << " ";
- dumpSourceRange(T->getBracketsRange());
VisitArrayType(T);
}
void TextNodeDumper::VisitDependentSizedArrayType(
const DependentSizedArrayType *T) {
VisitArrayType(T);
- OS << " ";
- dumpSourceRange(T->getBracketsRange());
}
void TextNodeDumper::VisitDependentSizedExtVectorType(
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 7898e6b90bf4b..62e48062cf241 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -279,10 +279,8 @@ QualType ArrayParameterType::getConstantArrayType(const ASTContext &Ctx) const {
DependentSizedArrayType::DependentSizedArrayType(QualType et, QualType can,
Expr *e, ArraySizeModifier sm,
- unsigned tq,
- SourceRange brackets)
- : ArrayType(DependentSizedArray, et, can, sm, tq, e), SizeExpr((Stmt *)e),
- Brackets(brackets) {}
+ unsigned tq)
+ : ArrayType(DependentSizedArray, et, can, sm, tq, e), SizeExpr((Stmt *)e) {}
void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID,
const ASTContext &Context,
@@ -1099,8 +1097,7 @@ struct SimpleTransformVisitor : public TypeVisitor<Derived, QualType> {
return Ctx.getVariableArrayType(elementType, T->getSizeExpr(),
T->getSizeModifier(),
- T->getIndexTypeCVRQualifiers(),
- T->getBracketsRange());
+ T->getIndexTypeCVRQualifiers());
}
QualType VisitIncompleteArrayType(const IncompleteArrayType *T) {
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 5736864d4cc6b..918b064c3cfd5 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3797,7 +3797,7 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
RValue::get(NumOfEle...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/135511
More information about the cfe-commits
mailing list