Skip to content

Commit 8f66f13

Browse files
committed
Fix memory leak in [Clang] Implement __builtin_source_location.
Fixes: d614874
1 parent 9b36e12 commit 8f66f13

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

clang/include/clang/AST/DeclCXX.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4221,7 +4221,8 @@ class UnnamedGlobalConstantDecl : public ValueDecl,
42214221

42224222
void anchor() override;
42234223

4224-
UnnamedGlobalConstantDecl(DeclContext *DC, QualType T, const APValue &Val);
4224+
UnnamedGlobalConstantDecl(const ASTContext &C, DeclContext *DC, QualType T,
4225+
const APValue &Val);
42254226

42264227
static UnnamedGlobalConstantDecl *Create(const ASTContext &C, QualType T,
42274228
const APValue &APVal);

clang/lib/AST/DeclCXX.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,23 +3365,30 @@ APValue &MSGuidDecl::getAsAPValue() const {
33653365

33663366
void UnnamedGlobalConstantDecl::anchor() {}
33673367

3368-
UnnamedGlobalConstantDecl::UnnamedGlobalConstantDecl(DeclContext *DC,
3368+
UnnamedGlobalConstantDecl::UnnamedGlobalConstantDecl(const ASTContext &C,
3369+
DeclContext *DC,
33693370
QualType Ty,
3370-
const APValue &Value)
3371+
const APValue &Val)
33713372
: ValueDecl(Decl::UnnamedGlobalConstant, DC, SourceLocation(),
33723373
DeclarationName(), Ty),
3373-
Value(Value) {}
3374+
Value(Val) {
3375+
// Cleanup the embedded APValue if required (note that our destructor is never
3376+
// run)
3377+
if (Value.needsCleanup())
3378+
C.addDestruction(&Value);
3379+
}
33743380

33753381
UnnamedGlobalConstantDecl *
33763382
UnnamedGlobalConstantDecl::Create(const ASTContext &C, QualType T,
33773383
const APValue &Value) {
33783384
DeclContext *DC = C.getTranslationUnitDecl();
3379-
return new (C, DC) UnnamedGlobalConstantDecl(DC, T, Value);
3385+
return new (C, DC) UnnamedGlobalConstantDecl(C, DC, T, Value);
33803386
}
33813387

33823388
UnnamedGlobalConstantDecl *
33833389
UnnamedGlobalConstantDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
3384-
return new (C, ID) UnnamedGlobalConstantDecl(nullptr, QualType(), APValue());
3390+
return new (C, ID)
3391+
UnnamedGlobalConstantDecl(C, nullptr, QualType(), APValue());
33853392
}
33863393

33873394
void UnnamedGlobalConstantDecl::printName(llvm::raw_ostream &OS) const {

0 commit comments

Comments
 (0)