Skip to content

Commit 604e274

Browse files
committed
Fix memory leak by re-using existing Parser::ParseLexedAttributeList
method and tweak it for parsing C attributes
1 parent bcc39cf commit 604e274

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

clang/lib/Parse/ParseCXXInlineMethods.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,13 @@ void Parser::ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
744744
for (unsigned i = 0, ni = LAs.size(); i < ni; ++i) {
745745
if (D)
746746
LAs[i]->addDecl(D);
747-
ParseLexedAttribute(*LAs[i], EnterScope, OnDefinition);
747+
// FIXME: There has to be a better way to ask "is this C?""
748+
if (LangStandard::getLangStandardForKind(getLangOpts().LangStd)
749+
.getLanguage() == Language::C) {
750+
// TODO: Use `EnterScope`
751+
ParseLexedCAttribute(*LAs[i]);
752+
} else
753+
ParseLexedAttribute(*LAs[i], EnterScope, OnDefinition);
748754
delete LAs[i];
749755
}
750756
LAs.clear();

clang/lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5032,7 +5032,7 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
50325032

50335033
// `LateAttrParseExperimentalExtOnly=true` requests that only attributes
50345034
// marked with `LateAttrParseExperimentalExt` are late parsed.
5035-
LateParsedAttrList LateFieldAttrs(/*PSoon=*/false,
5035+
LateParsedAttrList LateFieldAttrs(/*PSoon=*/true,
50365036
/*LateAttrParseExperimentalExtOnly=*/true);
50375037

50385038
// While we still have something to read, read the declarations in the struct.
@@ -5142,8 +5142,8 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
51425142

51435143
// Late parse field attributes if necessary.
51445144
assert(!getLangOpts().CPlusPlus);
5145-
for (auto *LateAttr : LateFieldAttrs)
5146-
ParseLexedCAttribute(*LateAttr);
5145+
ParseLexedAttributeList(LateFieldAttrs, /*Decl=*/nullptr,
5146+
/*EnterScope=*/false, /*OnDefinition=*/false);
51475147

51485148
SmallVector<Decl *, 32> FieldDecls(TagDecl->fields());
51495149

0 commit comments

Comments
 (0)