Skip to content

Commit 10a1502

Browse files
authored
[clang] AST: remove source locations from [Variable/Dependent]SizedArrayType (#135511)
1 parent 4cb1803 commit 10a1502

15 files changed

+66
-143
lines changed

Diff for: clang/include/clang/AST/ASTContext.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1564,8 +1564,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
15641564
/// Return a non-unique reference to the type for a variable array of
15651565
/// the specified element type.
15661566
QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
1567-
ArraySizeModifier ASM, unsigned IndexTypeQuals,
1568-
SourceRange Brackets) const;
1567+
ArraySizeModifier ASM,
1568+
unsigned IndexTypeQuals) const;
15691569

15701570
/// Return a non-unique reference to the type for a dependently-sized
15711571
/// array of the specified element type.
@@ -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.

Diff for: clang/include/clang/AST/Type.h

+4-21
Original file line numberDiff line numberDiff line change
@@ -3827,14 +3827,9 @@ class VariableArrayType : public ArrayType {
38273827
/// a function block.
38283828
Stmt *SizeExpr;
38293829

3830-
/// The range spanned by the left and right array brackets.
3831-
SourceRange Brackets;
3832-
3833-
VariableArrayType(QualType et, QualType can, Expr *e,
3834-
ArraySizeModifier sm, unsigned tq,
3835-
SourceRange brackets)
3836-
: ArrayType(VariableArray, et, can, sm, tq, e),
3837-
SizeExpr((Stmt*) e), Brackets(brackets) {}
3830+
VariableArrayType(QualType et, QualType can, Expr *e, ArraySizeModifier sm,
3831+
unsigned tq)
3832+
: ArrayType(VariableArray, et, can, sm, tq, e), SizeExpr((Stmt *)e) {}
38383833

38393834
public:
38403835
friend class StmtIteratorBase;
@@ -3845,10 +3840,6 @@ class VariableArrayType : public ArrayType {
38453840
return (Expr*) SizeExpr;
38463841
}
38473842

3848-
SourceRange getBracketsRange() const { return Brackets; }
3849-
SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3850-
SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3851-
38523843
bool isSugared() const { return false; }
38533844
QualType desugar() const { return QualType(this, 0); }
38543845

@@ -3884,12 +3875,8 @@ class DependentSizedArrayType : public ArrayType {
38843875
/// type will have its size deduced from an initializer.
38853876
Stmt *SizeExpr;
38863877

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

38943881
public:
38953882
friend class StmtIteratorBase;
@@ -3900,10 +3887,6 @@ class DependentSizedArrayType : public ArrayType {
39003887
return (Expr*) SizeExpr;
39013888
}
39023889

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

Diff for: clang/include/clang/AST/TypeProperties.td

+3-21
Original file line numberDiff line numberDiff line change
@@ -154,40 +154,22 @@ let Class = IncompleteArrayType in {
154154
}
155155

156156
let Class = VariableArrayType in {
157-
def : Property<"leftBracketLoc", SourceLocation> {
158-
let Read = [{ node->getLBracketLoc() }];
159-
}
160-
def : Property<"rightBracketLoc", SourceLocation> {
161-
let Read = [{ node->getRBracketLoc() }];
162-
}
163157
def : Property<"size", ExprRef> {
164158
let Read = [{ node->getSizeExpr() }];
165159
}
166160

167161
def : Creator<[{
168162
return ctx.getVariableArrayType(elementType, size, sizeModifier,
169-
indexQualifiers.getCVRQualifiers(),
170-
SourceRange(leftBracketLoc,
171-
rightBracketLoc));
163+
indexQualifiers.getCVRQualifiers());
172164
}]>;
173165
}
174166

175167
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-
}
168+
def : Property<"size", ExprRef> { let Read = [{ node->getSizeExpr() }]; }
185169

186170
def : Creator<[{
187171
return ctx.getDependentSizedArrayType(elementType, size, sizeModifier,
188-
indexQualifiers.getCVRQualifiers(),
189-
SourceRange(leftBracketLoc,
190-
rightBracketLoc));
172+
indexQualifiers.getCVRQualifiers());
191173
}]>;
192174
}
193175

Diff for: clang/lib/AST/ASTContext.cpp

+27-43
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

@@ -4275,17 +4272,17 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const {
42754272
result =
42764273
getVariableArrayType(getVariableArrayDecayedType(iat->getElementType()),
42774274
/*size*/ nullptr, ArraySizeModifier::Normal,
4278-
iat->getIndexTypeCVRQualifiers(), SourceRange());
4275+
iat->getIndexTypeCVRQualifiers());
42794276
break;
42804277
}
42814278

42824279
// Turn VLA types into [*] types.
42834280
case Type::VariableArray: {
42844281
const auto *vat = cast<VariableArrayType>(ty);
4285-
result = getVariableArrayType(
4286-
getVariableArrayDecayedType(vat->getElementType()),
4287-
/*size*/ nullptr, ArraySizeModifier::Star,
4288-
vat->getIndexTypeCVRQualifiers(), vat->getBracketsRange());
4282+
result =
4283+
getVariableArrayType(getVariableArrayDecayedType(vat->getElementType()),
4284+
/*size*/ nullptr, ArraySizeModifier::Star,
4285+
vat->getIndexTypeCVRQualifiers());
42894286
break;
42904287
}
42914288
}
@@ -4298,8 +4295,7 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const {
42984295
/// variable array of the specified element type.
42994296
QualType ASTContext::getVariableArrayType(QualType EltTy, Expr *NumElts,
43004297
ArraySizeModifier ASM,
4301-
unsigned IndexTypeQuals,
4302-
SourceRange Brackets) const {
4298+
unsigned IndexTypeQuals) const {
43034299
// Since we don't unique expressions, it isn't possible to unique VLA's
43044300
// that have an expression provided for their size.
43054301
QualType Canon;
@@ -4309,12 +4305,12 @@ QualType ASTContext::getVariableArrayType(QualType EltTy, Expr *NumElts,
43094305
if (!EltTy.isCanonical() || EltTy.hasLocalQualifiers()) {
43104306
SplitQualType canonSplit = getCanonicalType(EltTy).split();
43114307
Canon = getVariableArrayType(QualType(canonSplit.Ty, 0), NumElts, ASM,
4312-
IndexTypeQuals, Brackets);
4308+
IndexTypeQuals);
43134309
Canon = getQualifiedType(Canon, canonSplit.Quals);
43144310
}
43154311

43164312
auto *New = new (*this, alignof(VariableArrayType))
4317-
VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals, Brackets);
4313+
VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals);
43184314

43194315
VariableArrayTypes.push_back(New);
43204316
Types.push_back(New);
@@ -4324,11 +4320,10 @@ QualType ASTContext::getVariableArrayType(QualType EltTy, Expr *NumElts,
43244320
/// getDependentSizedArrayType - Returns a non-unique reference to
43254321
/// the type for a dependently-sized array of the specified element
43264322
/// type.
4327-
QualType ASTContext::getDependentSizedArrayType(QualType elementType,
4328-
Expr *numElements,
4329-
ArraySizeModifier ASM,
4330-
unsigned elementTypeQuals,
4331-
SourceRange brackets) const {
4323+
QualType
4324+
ASTContext::getDependentSizedArrayType(QualType elementType, Expr *numElements,
4325+
ArraySizeModifier ASM,
4326+
unsigned elementTypeQuals) const {
43324327
assert((!numElements || numElements->isTypeDependent() ||
43334328
numElements->isValueDependent()) &&
43344329
"Size must be type- or value-dependent!");
@@ -4354,7 +4349,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType,
43544349

43554350
auto *newType = new (*this, alignof(DependentSizedArrayType))
43564351
DependentSizedArrayType(elementType, QualType(), numElements, ASM,
4357-
elementTypeQuals, brackets);
4352+
elementTypeQuals);
43584353
DependentSizedArrayTypes.InsertNode(newType, insertPos);
43594354
Types.push_back(newType);
43604355
return QualType(newType, 0);
@@ -4364,7 +4359,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType,
43644359
if (!canonTy) {
43654360
canonTy = new (*this, alignof(DependentSizedArrayType))
43664361
DependentSizedArrayType(QualType(canonElementType.Ty, 0), QualType(),
4367-
numElements, ASM, elementTypeQuals, brackets);
4362+
numElements, ASM, elementTypeQuals);
43684363
DependentSizedArrayTypes.InsertNode(canonTy, insertPos);
43694364
Types.push_back(canonTy);
43704365
}
@@ -4383,7 +4378,7 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType,
43834378
// of the element type.
43844379
auto *sugaredType = new (*this, alignof(DependentSizedArrayType))
43854380
DependentSizedArrayType(elementType, canon, numElements, ASM,
4386-
elementTypeQuals, brackets);
4381+
elementTypeQuals);
43874382
Types.push_back(sugaredType);
43884383
return QualType(sugaredType, 0);
43894384
}
@@ -6775,17 +6770,14 @@ QualType ASTContext::getUnqualifiedArrayType(QualType type,
67756770
}
67766771

67776772
if (const auto *VAT = dyn_cast<VariableArrayType>(AT)) {
6778-
return getVariableArrayType(unqualElementType,
6779-
VAT->getSizeExpr(),
6773+
return getVariableArrayType(unqualElementType, VAT->getSizeExpr(),
67806774
VAT->getSizeModifier(),
6781-
VAT->getIndexTypeCVRQualifiers(),
6782-
VAT->getBracketsRange());
6775+
VAT->getIndexTypeCVRQualifiers());
67836776
}
67846777

67856778
const auto *DSAT = cast<DependentSizedArrayType>(AT);
67866779
return getDependentSizedArrayType(unqualElementType, DSAT->getSizeExpr(),
6787-
DSAT->getSizeModifier(), 0,
6788-
SourceRange());
6780+
DSAT->getSizeModifier(), 0);
67896781
}
67906782

67916783
/// 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 {
77297721
IAT->getIndexTypeCVRQualifiers()));
77307722

77317723
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()));
7724+
return cast<ArrayType>(getDependentSizedArrayType(
7725+
NewEltTy, DSAT->getSizeExpr(), DSAT->getSizeModifier(),
7726+
DSAT->getIndexTypeCVRQualifiers()));
77387727

77397728
const auto *VAT = cast<VariableArrayType>(ATy);
7740-
return cast<ArrayType>(getVariableArrayType(NewEltTy,
7741-
VAT->getSizeExpr(),
7742-
VAT->getSizeModifier(),
7743-
VAT->getIndexTypeCVRQualifiers(),
7744-
VAT->getBracketsRange()));
7729+
return cast<ArrayType>(
7730+
getVariableArrayType(NewEltTy, VAT->getSizeExpr(), VAT->getSizeModifier(),
7731+
VAT->getIndexTypeCVRQualifiers()));
77457732
}
77467733

77477734
QualType ASTContext::getAdjustedParameterType(QualType T) const {
@@ -13846,10 +13833,7 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
1384613833
return Ctx.getDependentSizedArrayType(
1384713834
getCommonArrayElementType(Ctx, AX, QX, AY, QY),
1384813835
getCommonSizeExpr(Ctx, AX, AY), getCommonSizeModifier(AX, AY),
13849-
getCommonIndexTypeCVRQualifiers(AX, AY),
13850-
AX->getBracketsRange() == AY->getBracketsRange()
13851-
? AX->getBracketsRange()
13852-
: SourceRange());
13836+
getCommonIndexTypeCVRQualifiers(AX, AY));
1385313837
}
1385413838
case Type::ConstantArray: {
1385513839
const auto *AX = cast<ConstantArrayType>(X),

Diff for: clang/lib/AST/ASTDiagnostic.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
142142
ElementTy, CAT->getSize(), CAT->getSizeExpr(),
143143
CAT->getSizeModifier(), CAT->getIndexTypeCVRQualifiers());
144144
else if (const auto *VAT = dyn_cast<VariableArrayType>(AT))
145-
QT = Context.getVariableArrayType(
146-
ElementTy, VAT->getSizeExpr(), VAT->getSizeModifier(),
147-
VAT->getIndexTypeCVRQualifiers(), VAT->getBracketsRange());
145+
QT = Context.getVariableArrayType(ElementTy, VAT->getSizeExpr(),
146+
VAT->getSizeModifier(),
147+
VAT->getIndexTypeCVRQualifiers());
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());

Diff for: clang/lib/AST/ASTImporter.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1295,28 +1295,26 @@ ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
12951295
Error Err = Error::success();
12961296
QualType ToElementType = importChecked(Err, T->getElementType());
12971297
Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1298-
SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
12991298
if (Err)
13001299
return std::move(Err);
13011300
return Importer.getToContext().getVariableArrayType(
13021301
ToElementType, ToSizeExpr, T->getSizeModifier(),
1303-
T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1302+
T->getIndexTypeCVRQualifiers());
13041303
}
13051304

13061305
ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
13071306
const DependentSizedArrayType *T) {
13081307
Error Err = Error::success();
13091308
QualType ToElementType = importChecked(Err, T->getElementType());
13101309
Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1311-
SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
13121310
if (Err)
13131311
return std::move(Err);
13141312
// SizeExpr may be null if size is not specified directly.
13151313
// For example, 'int a[]'.
13161314

13171315
return Importer.getToContext().getDependentSizedArrayType(
13181316
ToElementType, ToSizeExpr, T->getSizeModifier(),
1319-
T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1317+
T->getIndexTypeCVRQualifiers());
13201318
}
13211319

13221320
ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(

Diff for: clang/lib/AST/MicrosoftMangle.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3308,7 +3308,7 @@ void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) {
33083308
const DependentSizedArrayType *DSAT =
33093309
getASTContext().getAsDependentSizedArrayType(ElementTy);
33103310
Error(DSAT->getSizeExpr()->getExprLoc(), "dependent-length")
3311-
<< DSAT->getBracketsRange();
3311+
<< DSAT->getSizeExpr()->getSourceRange();
33123312
return;
33133313
} else {
33143314
break;

Diff for: clang/lib/AST/TextNodeDumper.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -1941,16 +1941,12 @@ void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) {
19411941
}
19421942

19431943
void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) {
1944-
OS << " ";
1945-
dumpSourceRange(T->getBracketsRange());
19461944
VisitArrayType(T);
19471945
}
19481946

19491947
void TextNodeDumper::VisitDependentSizedArrayType(
19501948
const DependentSizedArrayType *T) {
19511949
VisitArrayType(T);
1952-
OS << " ";
1953-
dumpSourceRange(T->getBracketsRange());
19541950
}
19551951

19561952
void TextNodeDumper::VisitDependentSizedExtVectorType(

Diff for: clang/lib/AST/Type.cpp

+3-6
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,
@@ -1099,8 +1097,7 @@ struct SimpleTransformVisitor : public TypeVisitor<Derived, QualType> {
10991097

11001098
return Ctx.getVariableArrayType(elementType, T->getSizeExpr(),
11011099
T->getSizeModifier(),
1102-
T->getIndexTypeCVRQualifiers(),
1103-
T->getBracketsRange());
1100+
T->getIndexTypeCVRQualifiers());
11041101
}
11051102

11061103
QualType VisitIncompleteArrayType(const IncompleteArrayType *T) {

Diff for: clang/lib/CodeGen/CGOpenMPRuntime.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3797,7 +3797,7 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
37973797
RValue::get(NumOfElements));
37983798
KmpTaskAffinityInfoArrayTy = C.getVariableArrayType(
37993799
KmpTaskAffinityInfoTy, OVE, ArraySizeModifier::Normal,
3800-
/*IndexTypeQuals=*/0, SourceRange(Loc, Loc));
3800+
/*IndexTypeQuals=*/0);
38013801
// Properly emit variable-sized array.
38023802
auto *PD = ImplicitParamDecl::Create(C, KmpTaskAffinityInfoArrayTy,
38033803
ImplicitParamKind::Other);
@@ -4260,7 +4260,7 @@ std::pair<llvm::Value *, Address> CGOpenMPRuntime::emitDependClause(
42604260
RValue::get(NumOfElements));
42614261
KmpDependInfoArrayTy =
42624262
C.getVariableArrayType(KmpDependInfoTy, OVE, ArraySizeModifier::Normal,
4263-
/*IndexTypeQuals=*/0, SourceRange(Loc, Loc));
4263+
/*IndexTypeQuals=*/0);
42644264
// CGF.EmitVariablyModifiedType(KmpDependInfoArrayTy);
42654265
// Properly emit variable-sized array.
42664266
auto *PD = ImplicitParamDecl::Create(C, KmpDependInfoArrayTy,

0 commit comments

Comments
 (0)