From 0f6bfc8b3b95065927fc26fb1bb20afb9672e744 Mon Sep 17 00:00:00 2001 From: Diachkov Ilia Date: Thu, 8 Dec 2022 04:36:01 +0800 Subject: [PATCH 25/26] Fix an error in memory allocation/deallocation --- gcc/symbol-summary.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/gcc/symbol-summary.h b/gcc/symbol-summary.h index 1e7341b24..2f7b1a348 100644 --- a/gcc/symbol-summary.h +++ b/gcc/symbol-summary.h @@ -59,15 +59,15 @@ protected: /* Allocates new data that are stored within map. */ T* allocate_new () { - /* In structure optimizatons, we call new to ensure that - the allocated memory is initialized to 0. */ - if (flag_ipa_struct_reorg) - return is_ggc () ? new (ggc_internal_alloc (sizeof (T))) T () - : new T (); /* Call gcc_internal_because we do not want to call finalizer for a type T. We call dtor explicitly. */ - return is_ggc () ? new (ggc_internal_alloc (sizeof (T))) T () - : m_allocator.allocate () ; + T* allocated = is_ggc () ? new (ggc_internal_alloc (sizeof (T))) T () + : m_allocator.allocate (); + /* In structure optimizatons, we call memset to ensure that + the allocated memory is initialized to 0. */ + if (flag_ipa_struct_layout || flag_ipa_struct_reorg) + memset (allocated, 0, sizeof (T)); + return allocated; } /* Release an item that is stored within map. */ @@ -76,12 +76,7 @@ protected: if (is_ggc ()) ggc_delete (item); else - { - if (flag_ipa_struct_reorg) - delete item; - else - m_allocator.remove (item); - } + m_allocator.remove (item); } /* Unregister all call-graph hooks. */ -- 2.27.0