Skip to content

Commit e01aa7b

Browse files
committed
[clang] AST: remove source locations from DependentSizedArrayType
Source locations should be handled at the TypeLoc level, and these locations are already wired up to the base ArrayLoc. There was nothing important wired to these, so just remove.
1 parent 761787d commit e01aa7b

File tree

13 files changed

+32
-83
lines changed

13 files changed

+32
-83
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,8 +1574,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
15741574
/// point.
15751575
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
15761576
ArraySizeModifier ASM,
1577-
unsigned IndexTypeQuals,
1578-
SourceRange Brackets) const;
1577+
unsigned IndexTypeQuals) const;
15791578

15801579
/// Return a unique reference to the type for an incomplete array of
15811580
/// the specified element type.

clang/include/clang/AST/Type.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,12 +3884,8 @@ class DependentSizedArrayType : public ArrayType {
38843884
/// type will have its size deduced from an initializer.
38853885
Stmt *SizeExpr;
38863886

3887-
/// The range spanned by the left and right array brackets.
3888-
SourceRange Brackets;
3889-
38903887
DependentSizedArrayType(QualType et, QualType can, Expr *e,
3891-
ArraySizeModifier sm, unsigned tq,
3892-
SourceRange brackets);
3888+
ArraySizeModifier sm, unsigned tq);
38933889

38943890
public:
38953891
friend class StmtIteratorBase;
@@ -3900,10 +3896,6 @@ class DependentSizedArrayType : public ArrayType {
39003896
return (Expr*) SizeExpr;
39013897
}
39023898

3903-
SourceRange getBracketsRange() const { return Brackets; }
3904-
SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3905-
SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3906-
39073899
bool isSugared() const { return false; }
39083900
QualType desugar() const { return QualType(this, 0); }
39093901

clang/include/clang/AST/TypeProperties.td

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,11 @@ let Class = VariableArrayType in {
173173
}
174174

175175
let Class = DependentSizedArrayType in {
176-
def : Property<"size", ExprRef> {
177-
let Read = [{ node->getSizeExpr() }];
178-
}
179-
def : Property<"leftBracketLoc", SourceLocation> {
180-
let Read = [{ node->getLBracketLoc() }];
181-
}
182-
def : Property<"rightBracketLoc", SourceLocation> {
183-
let Read = [{ node->getRBracketLoc() }];
184-
}
176+
def : Property<"size", ExprRef> { let Read = [{ node->getSizeExpr() }]; }
185177

186178
def : Creator<[{
187179
return ctx.getDependentSizedArrayType(elementType, size, sizeModifier,
188-
indexQualifiers.getCVRQualifiers(),
189-
SourceRange(leftBracketLoc,
190-
rightBracketLoc));
180+
indexQualifiers.getCVRQualifiers());
191181
}]>;
192182
}
193183

clang/lib/AST/ASTContext.cpp

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4261,11 +4261,8 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const {
42614261
case Type::DependentSizedArray: {
42624262
const auto *dat = cast<DependentSizedArrayType>(ty);
42634263
result = getDependentSizedArrayType(
4264-
getVariableArrayDecayedType(dat->getElementType()),
4265-
dat->getSizeExpr(),
4266-
dat->getSizeModifier(),
4267-
dat->getIndexTypeCVRQualifiers(),
4268-
dat->getBracketsRange());
4264+
getVariableArrayDecayedType(dat->getElementType()), dat->getSizeExpr(),
4265+
dat->getSizeModifier(), dat->getIndexTypeCVRQualifiers());
42694266
break;
42704267
}
42714268

@@ -4324,11 +4321,10 @@ QualType ASTContext::getVariableArrayType(QualType EltTy, Expr *NumElts,
43244321
/// getDependentSizedArrayType - Returns a non-unique reference to
43254322
/// the type for a dependently-sized array of the specified element
43264323
/// type.
4327-
QualType ASTContext::getDependentSizedArrayType(QualType elementType,
4328-
Expr *numElements,
4329-
ArraySizeModifier ASM,
4330-
unsigned elementTypeQuals,
4331-
SourceRange brackets) const {
4324+
QualType
4325+
ASTContext::getDependentSizedArrayType(QualType elementType, Expr *numElements,
4326+
ArraySizeModifier ASM,
4327+
unsigned elementTypeQuals) const {
43324328
assert((!numElements || numElements->isTypeDependent() ||
43334329
numElements->isValueDependent()) &&
43344330
"Size must be type- or value-dependent!");
@@ -4354,7 +4350,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType,
43544350

43554351
auto *newType = new (*this, alignof(DependentSizedArrayType))
43564352
DependentSizedArrayType(elementType, QualType(), numElements, ASM,
4357-
elementTypeQuals, brackets);
4353+
elementTypeQuals);
43584354
DependentSizedArrayTypes.InsertNode(newType, insertPos);
43594355
Types.push_back(newType);
43604356
return QualType(newType, 0);
@@ -4364,7 +4360,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType,
43644360
if (!canonTy) {
43654361
canonTy = new (*this, alignof(DependentSizedArrayType))
43664362
DependentSizedArrayType(QualType(canonElementType.Ty, 0), QualType(),
4367-
numElements, ASM, elementTypeQuals, brackets);
4363+
numElements, ASM, elementTypeQuals);
43684364
DependentSizedArrayTypes.InsertNode(canonTy, insertPos);
43694365
Types.push_back(canonTy);
43704366
}
@@ -4383,7 +4379,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType,
43834379
// of the element type.
43844380
auto *sugaredType = new (*this, alignof(DependentSizedArrayType))
43854381
DependentSizedArrayType(elementType, canon, numElements, ASM,
4386-
elementTypeQuals, brackets);
4382+
elementTypeQuals);
43874383
Types.push_back(sugaredType);
43884384
return QualType(sugaredType, 0);
43894385
}
@@ -6784,8 +6780,7 @@ QualType ASTContext::getUnqualifiedArrayType(QualType type,
67846780

67856781
const auto *DSAT = cast<DependentSizedArrayType>(AT);
67866782
return getDependentSizedArrayType(unqualElementType, DSAT->getSizeExpr(),
6787-
DSAT->getSizeModifier(), 0,
6788-
SourceRange());
6783+
DSAT->getSizeModifier(), 0);
67896784
}
67906785

67916786
/// Attempt to unwrap two types that may both be array types with the same bound
@@ -7729,12 +7724,9 @@ const ArrayType *ASTContext::getAsArrayType(QualType T) const {
77297724
IAT->getIndexTypeCVRQualifiers()));
77307725

77317726
if (const auto *DSAT = dyn_cast<DependentSizedArrayType>(ATy))
7732-
return cast<ArrayType>(
7733-
getDependentSizedArrayType(NewEltTy,
7734-
DSAT->getSizeExpr(),
7735-
DSAT->getSizeModifier(),
7736-
DSAT->getIndexTypeCVRQualifiers(),
7737-
DSAT->getBracketsRange()));
7727+
return cast<ArrayType>(getDependentSizedArrayType(
7728+
NewEltTy, DSAT->getSizeExpr(), DSAT->getSizeModifier(),
7729+
DSAT->getIndexTypeCVRQualifiers()));
77387730

77397731
const auto *VAT = cast<VariableArrayType>(ATy);
77407732
return cast<ArrayType>(getVariableArrayType(NewEltTy,
@@ -13846,10 +13838,7 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
1384613838
return Ctx.getDependentSizedArrayType(
1384713839
getCommonArrayElementType(Ctx, AX, QX, AY, QY),
1384813840
getCommonSizeExpr(Ctx, AX, AY), getCommonSizeModifier(AX, AY),
13849-
getCommonIndexTypeCVRQualifiers(AX, AY),
13850-
AX->getBracketsRange() == AY->getBracketsRange()
13851-
? AX->getBracketsRange()
13852-
: SourceRange());
13841+
getCommonIndexTypeCVRQualifiers(AX, AY));
1385313842
}
1385413843
case Type::ConstantArray: {
1385513844
const auto *AX = cast<ConstantArrayType>(X),

clang/lib/AST/ASTDiagnostic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
148148
else if (const auto *DSAT = dyn_cast<DependentSizedArrayType>(AT))
149149
QT = Context.getDependentSizedArrayType(
150150
ElementTy, DSAT->getSizeExpr(), DSAT->getSizeModifier(),
151-
DSAT->getIndexTypeCVRQualifiers(), DSAT->getBracketsRange());
151+
DSAT->getIndexTypeCVRQualifiers());
152152
else if (const auto *IAT = dyn_cast<IncompleteArrayType>(AT))
153153
QT = Context.getIncompleteArrayType(ElementTy, IAT->getSizeModifier(),
154154
IAT->getIndexTypeCVRQualifiers());

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,15 +1308,14 @@ ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
13081308
Error Err = Error::success();
13091309
QualType ToElementType = importChecked(Err, T->getElementType());
13101310
Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1311-
SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
13121311
if (Err)
13131312
return std::move(Err);
13141313
// SizeExpr may be null if size is not specified directly.
13151314
// For example, 'int a[]'.
13161315

13171316
return Importer.getToContext().getDependentSizedArrayType(
13181317
ToElementType, ToSizeExpr, T->getSizeModifier(),
1319-
T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1318+
T->getIndexTypeCVRQualifiers());
13201319
}
13211320

13221321
ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3312,7 +3312,7 @@ void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) {
33123312
const DependentSizedArrayType *DSAT =
33133313
getASTContext().getAsDependentSizedArrayType(ElementTy);
33143314
Error(DSAT->getSizeExpr()->getExprLoc(), "dependent-length")
3315-
<< DSAT->getBracketsRange();
3315+
<< DSAT->getSizeExpr()->getSourceRange();
33163316
return;
33173317
} else {
33183318
break;

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,8 +1949,6 @@ void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) {
19491949
void TextNodeDumper::VisitDependentSizedArrayType(
19501950
const DependentSizedArrayType *T) {
19511951
VisitArrayType(T);
1952-
OS << " ";
1953-
dumpSourceRange(T->getBracketsRange());
19541952
}
19551953

19561954
void TextNodeDumper::VisitDependentSizedExtVectorType(

clang/lib/AST/Type.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,8 @@ QualType ArrayParameterType::getConstantArrayType(const ASTContext &Ctx) const {
279279

280280
DependentSizedArrayType::DependentSizedArrayType(QualType et, QualType can,
281281
Expr *e, ArraySizeModifier sm,
282-
unsigned tq,
283-
SourceRange brackets)
284-
: ArrayType(DependentSizedArray, et, can, sm, tq, e), SizeExpr((Stmt *)e),
285-
Brackets(brackets) {}
282+
unsigned tq)
283+
: ArrayType(DependentSizedArray, et, can, sm, tq, e), SizeExpr((Stmt *)e) {}
286284

287285
void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID,
288286
const ASTContext &Context,

clang/lib/Sema/SemaInit.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7740,27 +7740,11 @@ ExprResult InitializationSequence::Perform(Sema &S,
77407740
// introduced and such). So, we fall back to making the array
77417741
// type a dependently-sized array type with no specified
77427742
// bound.
7743-
if (isa<InitListExpr>((Expr *)Args[0])) {
7744-
SourceRange Brackets;
7745-
7746-
// Scavange the location of the brackets from the entity, if we can.
7747-
if (auto *DD = dyn_cast_or_null<DeclaratorDecl>(Entity.getDecl())) {
7748-
if (TypeSourceInfo *TInfo = DD->getTypeSourceInfo()) {
7749-
TypeLoc TL = TInfo->getTypeLoc();
7750-
if (IncompleteArrayTypeLoc ArrayLoc =
7751-
TL.getAs<IncompleteArrayTypeLoc>())
7752-
Brackets = ArrayLoc.getBracketsRange();
7753-
}
7754-
}
7755-
7756-
*ResultType
7757-
= S.Context.getDependentSizedArrayType(ArrayT->getElementType(),
7758-
/*NumElts=*/nullptr,
7759-
ArrayT->getSizeModifier(),
7760-
ArrayT->getIndexTypeCVRQualifiers(),
7761-
Brackets);
7762-
}
7763-
7743+
if (isa<InitListExpr>((Expr *)Args[0]))
7744+
*ResultType = S.Context.getDependentSizedArrayType(
7745+
ArrayT->getElementType(),
7746+
/*NumElts=*/nullptr, ArrayT->getSizeModifier(),
7747+
ArrayT->getIndexTypeCVRQualifiers());
77647748
}
77657749
}
77667750
if (Kind.getKind() == InitializationKind::IK_Direct &&

0 commit comments

Comments
 (0)