Skip to content

Commit 9e96b0f

Browse files
committed
More stack size reduction
1 parent b431830 commit 9e96b0f

File tree

6 files changed

+35
-30
lines changed

6 files changed

+35
-30
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3844,6 +3844,8 @@ class Parser : public CodeCompletionHandler {
38443844
DeclGroupPtrTy ParseTemplateDeclarationOrSpecialization(
38453845
DeclaratorContext Context, SourceLocation &DeclEnd,
38463846
ParsedAttributes &AccessAttrs, AccessSpecifier AS);
3847+
clang::Parser::DeclGroupPtrTy ParseTemplateDeclarationOrSpecialization(
3848+
DeclaratorContext Context, SourceLocation &DeclEnd, AccessSpecifier AS);
38473849
DeclGroupPtrTy ParseDeclarationAfterTemplate(
38483850
DeclaratorContext Context, ParsedTemplateInfo &TemplateInfo,
38493851
ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,

clang/include/clang/Sema/ParsedAttr.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,14 @@ class ParsedAttributes : public ParsedAttributesView {
970970
pool.takeAllFrom(Other.pool);
971971
}
972972

973+
void takeAllAtEndFrom(ParsedAttributes &Other) {
974+
assert(&Other != this &&
975+
"ParsedAttributes can't take attributes from itself");
976+
addAllAtEnd(Other.begin(), Other.end());
977+
Other.clearListOnly();
978+
pool.takeAllFrom(Other.pool);
979+
}
980+
973981
void takeOneFrom(ParsedAttributes &Other, ParsedAttr *PA) {
974982
assert(&Other != this &&
975983
"ParsedAttributes can't take attribute from itself");
@@ -1067,10 +1075,11 @@ class ParsedAttributes : public ParsedAttributesView {
10671075
mutable AttributePool pool;
10681076
};
10691077

1070-
/// Consumes the attributes from `First` and `Second` and concatenates them into
1071-
/// `Result`. Sets `Result.Range` to the combined range of `First` and `Second`.
1072-
void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &Second,
1073-
ParsedAttributes &Result);
1078+
/// Consumes the attributes from `Second` and concatenates them
1079+
/// at the end of `First`. Sets `First.Range`
1080+
/// to the combined range of `First` and `Second`.
1081+
void takeAndConcatenateAttrs(ParsedAttributes &First,
1082+
ParsedAttributes &&Second);
10741083

10751084
/// These constants match the enumerated choices of
10761085
/// err_attribute_argument_n_type and err_attribute_argument_type.

clang/lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,10 +2076,9 @@ Parser::DeclGroupPtrTy Parser::ParseDeclaration(DeclaratorContext Context,
20762076
ProhibitAttributes(DeclSpecAttrs);
20772077
return ParseNamespace(Context, DeclEnd);
20782078
case tok::kw_using: {
2079-
ParsedAttributes Attrs(AttrFactory);
2080-
takeAndConcatenateAttrs(DeclAttrs, DeclSpecAttrs, Attrs);
2079+
takeAndConcatenateAttrs(DeclAttrs, std::move(DeclSpecAttrs));
20812080
return ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),
2082-
DeclEnd, Attrs);
2081+
DeclEnd, DeclAttrs);
20832082
}
20842083
case tok::kw_static_assert:
20852084
case tok::kw__Static_assert:

clang/lib/Parse/ParseStmt.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ Parser::ParseStatementOrDeclaration(StmtVector &Stmts,
126126
Stmts, StmtCtx, TrailingElseLoc, CXX11Attrs, GNUOrMSAttrs);
127127
MaybeDestroyTemplateIds();
128128

129-
CXX11Attrs.takeAllFrom(GNUOrMSAttrs);
130-
if (!CXX11Attrs.Range.getBegin().isValid())
131-
CXX11Attrs.Range.setBegin(GNUOrMSAttrs.Range.getBegin());
132-
if (GNUOrMSAttrs.Range.getEnd().isValid())
133-
CXX11Attrs.Range.setEnd(GNUOrMSAttrs.Range.getEnd());
129+
takeAndConcatenateAttrs(CXX11Attrs, std::move(GNUOrMSAttrs));
134130

135131
assert((CXX11Attrs.empty() || Res.isInvalid() || Res.isUsable()) &&
136132
"attributes on empty statement");
@@ -208,11 +204,10 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
208204
// Both C++11 and GNU attributes preceding the label appertain to the
209205
// label, so put them in a single list to pass on to
210206
// ParseLabeledStatement().
211-
ParsedAttributes Attrs(AttrFactory);
212-
takeAndConcatenateAttrs(CXX11Attrs, GNUAttrs, Attrs);
207+
takeAndConcatenateAttrs(CXX11Attrs, std::move(GNUAttrs));
213208

214209
// identifier ':' statement
215-
return ParseLabeledStatement(Attrs, StmtCtx);
210+
return ParseLabeledStatement(CXX11Attrs, StmtCtx);
216211
}
217212

218213
// Look up the identifier, and typo-correct it to a keyword if it's not
@@ -303,9 +298,7 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
303298

304299
case tok::kw_template: {
305300
SourceLocation DeclEnd;
306-
ParsedAttributes Attrs(AttrFactory);
307301
ParseTemplateDeclarationOrSpecialization(DeclaratorContext::Block, DeclEnd,
308-
Attrs,
309302
getAccessSpecifierIfPresent());
310303
return StmtError();
311304
}

clang/lib/Parse/ParseTemplate.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ Parser::DeclGroupPtrTy Parser::ParseTemplateDeclarationOrSpecialization(
179179
Context, TemplateInfo, ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
180180
}
181181

182+
Parser::DeclGroupPtrTy Parser::ParseTemplateDeclarationOrSpecialization(
183+
DeclaratorContext Context, SourceLocation &DeclEnd, AccessSpecifier AS) {
184+
ParsedAttributes AccessAttrs(AttrFactory);
185+
return ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AccessAttrs,
186+
AS);
187+
}
188+
182189
/// Parse a single declaration that declares a template,
183190
/// template specialization, or explicit instantiation of a template.
184191
///

clang/lib/Sema/ParsedAttr.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,13 @@ bool ParsedAttr::checkAtMostNumArgs(Sema &S, unsigned Num) const {
310310
}
311311

312312
void clang::takeAndConcatenateAttrs(ParsedAttributes &First,
313-
ParsedAttributes &Second,
314-
ParsedAttributes &Result) {
315-
// Note that takeAllFrom() puts the attributes at the beginning of the list,
316-
// so to obtain the correct ordering, we add `Second`, then `First`.
317-
Result.takeAllFrom(Second);
318-
Result.takeAllFrom(First);
319-
if (First.Range.getBegin().isValid())
320-
Result.Range.setBegin(First.Range.getBegin());
321-
else
322-
Result.Range.setBegin(Second.Range.getBegin());
313+
ParsedAttributes &&Second) {
314+
315+
First.takeAllAtEndFrom(Second);
316+
317+
if (!First.Range.getBegin().isValid())
318+
First.Range.setBegin(Second.Range.getBegin());
319+
323320
if (Second.Range.getEnd().isValid())
324-
Result.Range.setEnd(Second.Range.getEnd());
325-
else
326-
Result.Range.setEnd(First.Range.getEnd());
321+
First.Range.setEnd(Second.Range.getEnd());
327322
}

0 commit comments

Comments
 (0)