From f563bc17d9e914e6e53c385068a021a43541a9c8 Mon Sep 17 00:00:00 2001 From: erichkeane Date: Mon, 13 Oct 2025 09:28:13 -0700 Subject: [PATCH] [OpenACC] Fix memory leak for recipe list in Reduction After misunderstanding what was going on in the ASAN patches, I finally realize I just missed a call to a destructor! This patch ensures that the Recipe is deleted properly with the AST. --- clang/include/clang/AST/OpenACCClause.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/AST/OpenACCClause.h b/clang/include/clang/AST/OpenACCClause.h index ab2bf0e08692c..613c03ce4ad64 100644 --- a/clang/include/clang/AST/OpenACCClause.h +++ b/clang/include/clang/AST/OpenACCClause.h @@ -1325,17 +1325,17 @@ class OpenACCReductionClause final Op(Operator) { assert(VarList.size() == Recipes.size()); setExprs(getTrailingObjects(VarList.size()), VarList); + llvm::uninitialized_copy(Recipes, + getTrailingObjects()); + } - // Initialize the recipe list. - unsigned I = 0; - for (const OpenACCReductionRecipe &R : Recipes) { - new (&getTrailingObjects()[I]) - OpenACCReductionRecipe(R); - ++I; +public: + ~OpenACCReductionClause() { + for (unsigned I = 0; I < getExprs().size(); ++I) { + getTrailingObjects()[I].~OpenACCReductionRecipe(); } } -public: static bool classof(const OpenACCClause *C) { return C->getClauseKind() == OpenACCClauseKind::Reduction; }