Skip to content

Commit 2b1794e

Browse files
committed
Fix memory leak
1 parent bcc39cf commit 2b1794e

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,8 @@ class Parser : public CodeCompletionHandler {
16461646
void ParseLexedAttributes(ParsingClass &Class);
16471647
void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
16481648
bool EnterScope, bool OnDefinition);
1649+
void ParseLexedCAttributeList(LateParsedAttrList &LA, bool EnterScope,
1650+
ParsedAttributes *OutAttrs = nullptr);
16491651
void ParseLexedAttribute(LateParsedAttribute &LA,
16501652
bool EnterScope, bool OnDefinition);
16511653
void ParseLexedCAttribute(LateParsedAttribute &LA,

clang/lib/Parse/ParseDecl.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,6 +4944,26 @@ void Parser::ParseStructDeclaration(
49444944
}
49454945
}
49464946

4947+
// TODO: All callers of this function should be moved to
4948+
// `Parser::ParseLexedAttributeList`.
4949+
void Parser::ParseLexedCAttributeList(LateParsedAttrList &LAs, bool EnterScope,
4950+
ParsedAttributes *OutAttrs) {
4951+
assert(LAs.parseSoon() &&
4952+
"Attribute list should be marked for immediate parsing.");
4953+
#ifndef NDEBUG
4954+
auto LangStd = getLangOpts().LangStd;
4955+
if (LangStd != LangStandard::lang_unspecified) {
4956+
auto Lang = LangStandard::getLangStandardForKind(LangStd).getLanguage();
4957+
assert(Lang == Language::C || Lang == Language::OpenCL);
4958+
}
4959+
#endif
4960+
for (auto *LA : LAs) {
4961+
ParseLexedCAttribute(*LA, OutAttrs);
4962+
delete LA;
4963+
}
4964+
LAs.clear();
4965+
}
4966+
49474967
/// Finish parsing an attribute for which parsing was delayed.
49484968
/// This will be called at the end of parsing a class declaration
49494969
/// for each LateParsedAttribute. We consume the saved tokens and
@@ -5032,7 +5052,7 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
50325052

50335053
// `LateAttrParseExperimentalExtOnly=true` requests that only attributes
50345054
// marked with `LateAttrParseExperimentalExt` are late parsed.
5035-
LateParsedAttrList LateFieldAttrs(/*PSoon=*/false,
5055+
LateParsedAttrList LateFieldAttrs(/*PSoon=*/true,
50365056
/*LateAttrParseExperimentalExtOnly=*/true);
50375057

50385058
// While we still have something to read, read the declarations in the struct.
@@ -5141,9 +5161,7 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
51415161
MaybeParseGNUAttributes(attrs, &LateFieldAttrs);
51425162

51435163
// Late parse field attributes if necessary.
5144-
assert(!getLangOpts().CPlusPlus);
5145-
for (auto *LateAttr : LateFieldAttrs)
5146-
ParseLexedCAttribute(*LateAttr);
5164+
ParseLexedCAttributeList(LateFieldAttrs, /*EnterScope=*/false);
51475165

51485166
SmallVector<Decl *, 32> FieldDecls(TagDecl->fields());
51495167

0 commit comments

Comments
 (0)