[clang] 09d9f50 - [OpenACC] Fix memory leak for recipe list in Reduction (#163219)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 13 09:32:09 PDT 2025


Author: Erich Keane
Date: 2025-10-13T09:32:04-07:00
New Revision: 09d9f508a44a30a323bd06fe14a5962b2cf95866

URL: https://github.com/llvm/llvm-project/commit/09d9f508a44a30a323bd06fe14a5962b2cf95866
DIFF: https://github.com/llvm/llvm-project/commit/09d9f508a44a30a323bd06fe14a5962b2cf95866.diff

LOG: [OpenACC] Fix memory leak for recipe list in Reduction (#163219)

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.

Added: 
    

Modified: 
    clang/include/clang/AST/OpenACCClause.h

Removed: 
    


################################################################################
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<Expr *>(VarList.size()), VarList);
+    llvm::uninitialized_copy(Recipes,
+                             getTrailingObjects<OpenACCReductionRecipe>());
+  }
 
-    // Initialize the recipe list.
-    unsigned I = 0;
-    for (const OpenACCReductionRecipe &R : Recipes) {
-      new (&getTrailingObjects<OpenACCReductionRecipe>()[I])
-          OpenACCReductionRecipe(R);
-      ++I;
+public:
+  ~OpenACCReductionClause() {
+    for (unsigned I = 0; I < getExprs().size(); ++I) {
+      getTrailingObjects<OpenACCReductionRecipe>()[I].~OpenACCReductionRecipe();
     }
   }
 
-public:
   static bool classof(const OpenACCClause *C) {
     return C->getClauseKind() == OpenACCClauseKind::Reduction;
   }


        


More information about the cfe-commits mailing list