Fix memory leak in [Clang] Implement __builtin_source_location.

Fixes: d61487490022
This commit is contained in:
James Y Knight 2022-03-29 17:32:52 -04:00
parent 9b36e126fd
commit 8f66f13719
2 changed files with 14 additions and 6 deletions

View File

@ -4221,7 +4221,8 @@ class UnnamedGlobalConstantDecl : public ValueDecl,
void anchor() override;
UnnamedGlobalConstantDecl(DeclContext *DC, QualType T, const APValue &Val);
UnnamedGlobalConstantDecl(const ASTContext &C, DeclContext *DC, QualType T,
const APValue &Val);
static UnnamedGlobalConstantDecl *Create(const ASTContext &C, QualType T,
const APValue &APVal);

View File

@ -3365,23 +3365,30 @@ APValue &MSGuidDecl::getAsAPValue() const {
void UnnamedGlobalConstantDecl::anchor() {}
UnnamedGlobalConstantDecl::UnnamedGlobalConstantDecl(DeclContext *DC,
UnnamedGlobalConstantDecl::UnnamedGlobalConstantDecl(const ASTContext &C,
DeclContext *DC,
QualType Ty,
const APValue &Value)
const APValue &Val)
: ValueDecl(Decl::UnnamedGlobalConstant, DC, SourceLocation(),
DeclarationName(), Ty),
Value(Value) {}
Value(Val) {
// Cleanup the embedded APValue if required (note that our destructor is never
// run)
if (Value.needsCleanup())
C.addDestruction(&Value);
}
UnnamedGlobalConstantDecl *
UnnamedGlobalConstantDecl::Create(const ASTContext &C, QualType T,
const APValue &Value) {
DeclContext *DC = C.getTranslationUnitDecl();
return new (C, DC) UnnamedGlobalConstantDecl(DC, T, Value);
return new (C, DC) UnnamedGlobalConstantDecl(C, DC, T, Value);
}
UnnamedGlobalConstantDecl *
UnnamedGlobalConstantDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
return new (C, ID) UnnamedGlobalConstantDecl(nullptr, QualType(), APValue());
return new (C, ID)
UnnamedGlobalConstantDecl(C, nullptr, QualType(), APValue());
}
void UnnamedGlobalConstantDecl::printName(llvm::raw_ostream &OS) const {