public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Avoid default-initializing auto_vec<T, N> storage
@ 2023-02-23 12:54 Richard Biener
  2023-02-23 13:56 ` Jakub Jelinek
  0 siblings, 1 reply; 15+ messages in thread
From: Richard Biener @ 2023-02-23 12:54 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

The following avoids default-initializing auto_vec storage for
non-POD T since that's not what the allocated storage fallback
will do and it's also not expected for existing cases like

  auto_vec<std::pair<unsigned, unsigned>, 64> elts;

which exist to optimize the allocation.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

It saves around 1kB of text size for cc1.

OK for trunk?

Thanks,
Richard.

	* vec.h (auto_vec<T, N>): Turn m_data storage into
	uninitialized unsigned char.
---
 gcc/vec.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/vec.h b/gcc/vec.h
index a536b68732d..cee96254a31 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -1584,7 +1584,7 @@ public:
 
 private:
   vec<T, va_heap, vl_embed> m_auto;
-  T m_data[MAX (N - 1, 1)];
+  alignas(T) unsigned char m_data[sizeof (T) * MAX (N - 1, 1)];
 };
 
 /* auto_vec is a sub class of vec whose storage is released when it is
-- 
2.35.3

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-02-24 11:04 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-23 12:54 [PATCH] Avoid default-initializing auto_vec<T, N> storage Richard Biener
2023-02-23 13:56 ` Jakub Jelinek
2023-02-23 15:02   ` Richard Biener
2023-02-23 15:20     ` Jakub Jelinek
2023-02-24  9:02       ` Richard Biener
2023-02-24  9:34         ` Richard Biener
2023-02-24  9:48           ` Jakub Jelinek
2023-02-24  9:50             ` Jonathan Wakely
2023-02-24  9:55               ` Jakub Jelinek
2023-02-24  9:55               ` Jonathan Wakely
2023-02-24 10:02                 ` Jakub Jelinek
2023-02-24 10:24                   ` Jakub Jelinek
2023-02-24 10:30                     ` Jonathan Wakely
2023-02-24 10:59                       ` Jakub Jelinek
2023-02-24 11:04                         ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).