Author: Richard Smith Date: 2020-12-18T13:42:24-08:00 New Revision: ed13d8c66781b50ff007cb089c5905f9bb9e8af2
URL: https://github.com/llvm/llvm-project/commit/ed13d8c66781b50ff007cb089c5905f9bb9e8af2 DIFF: https://github.com/llvm/llvm-project/commit/ed13d8c66781b50ff007cb089c5905f9bb9e8af2.diff LOG: Fix memory leak complicated non-type template arguments. Added: Modified: clang/include/clang/AST/ASTContext.h clang/lib/AST/TemplateBase.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 0c5d82b3e9aa..a9bfdb4d5fa5 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -2818,8 +2818,8 @@ class ASTContext : public RefCountedBase<ASTContext> { /// for destruction. template <typename T> void addDestruction(T *Ptr) const { if (!std::is_trivially_destructible<T>::value) { - auto DestroyPtr = [](void *V) { static_cast<T *>(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 0029c90a0ab6..a746db315d85 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(); } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits