From: Richard Smith Date: Fri, 18 Dec 2020 21:25:18 +0000 (-0800) Subject: Fix memory leak complicated non-type template arguments. X-Git-Tag: llvmorg-13-init~2922 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ed13d8c66781b50ff007cb089c5905f9bb9e8af2;p=platform%2Fupstream%2Fllvm.git Fix memory leak complicated non-type template arguments. --- diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 0c5d82b..a9bfdb4 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -2818,8 +2818,8 @@ public: /// for destruction. template void addDestruction(T *Ptr) const { if (!std::is_trivially_destructible::value) { - auto DestroyPtr = [](void *V) { static_cast(V)->~T(); }; - AddDeallocation(DestroyPtr, Ptr); + auto DestroyPtr = [](void *V) { ((T*)V)->~T(); }; + AddDeallocation(DestroyPtr, (void*)Ptr); } } diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp index 0029c90..a746db3 100644 --- a/clang/lib/AST/TemplateBase.cpp +++ b/clang/lib/AST/TemplateBase.cpp @@ -137,6 +137,7 @@ TemplateArgument::TemplateArgument(const ASTContext &Ctx, QualType Type, else { Value.Kind = UncommonValue; Value.Value = new (Ctx) APValue(V); + Ctx.addDestruction(Value.Value); Value.Type = Type.getAsOpaquePtr(); } }