Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] [gdb/build] Fix Wstringop-overflow in selftests::vex2_to_vex3
Date: Wed, 28 Oct 2026 13:54:44 +0100	[thread overview]
Message-ID: <20261028125445.1745119-2-tdevries@suse.de> (raw)
In-Reply-To: <20261028125445.1745119-1-tdevries@suse.de>

When building gdb with -O3 on x86_64-linux, I run into:
...
    inlined from ‘void std::vector<_Tp, _Alloc>::resize(size_type) [with _Tp = unsigned char; _Alloc = gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> >]’ at /usr/include/c++/15/bits/stl_vector.h:1146:21,
    inlined from ‘void selftests::vex2_to_vex3(gdb::byte_vector&, gdb::byte_vector&)’ at /data/vries/gdb/leap-16-0/build/../../src/gdb/amd64-tdep.c:3896:15:
/usr/include/c++/15/bits/new_allocator.h:191:11: warning: writing 8 bytes into a region of size between 1 and 5 [-Wstringop-overflow=]
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

The warning complains about this resize:
...
  vex3.resize (3);
  vex3[0] = 0xc4;
  vex3[1] = (r << 7) | (x << 6) | (b << 5) | m;
  vex3[2] = (vex2[1] & ~0x80) | (w << 7);
...

This is a false positive [1].

Get rid of the warning by using std::vector<gdb_byte> instead.  The only
difference is default initialization, and for small vectors that doesn't
matter.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106093
---
 gdb/amd64-tdep.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 18b8f2a4c0b..27491cb995c 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -3877,12 +3877,15 @@ amd64_target_description (uint64_t xstate_bv, bool segments)
 
 #if GDB_SELF_TEST
 
+/* We're using std::vector<gdb_byte> instead of gdb::byte_vector here to work
+   around Wstringop-overflow false positives (PR gcc/106093).  */
+
 namespace selftests {
 
 /* Recode a vex2 instruction into a vex3 instruction.  */
 
 static void
-vex2_to_vex3 (gdb::byte_vector &vex2, gdb::byte_vector &vex3)
+vex2_to_vex3 (std::vector<gdb_byte> &vex2, std::vector<gdb_byte> &vex3)
 {
   gdb_assert (vex2.size () >= 2);
   gdb_assert (vex2[0] == 0xc5);
@@ -3908,13 +3911,13 @@ static void
 test_vex2_to_vex3 (void)
 {
   /* INSN: vzeroall, vex2 prefix.  */
-  gdb::byte_vector vex2 = { 0xc5, 0xfc, 0x77 };
+  std::vector<gdb_byte> vex2 = { 0xc5, 0xfc, 0x77 };
 
-  gdb::byte_vector vex3;
+  std::vector<gdb_byte> vex3;
   vex2_to_vex3 (vex2, vex3);
 
   /* INSN: vzeroall, vex3 prefix.  */
-  gdb::byte_vector vex3_ref = { 0xc4, 0xe1, 0x7c, 0x77 };
+  std::vector<gdb_byte> vex3_ref = { 0xc4, 0xe1, 0x7c, 0x77 };
   SELF_CHECK (vex3 == vex3_ref);
 }
 
@@ -3924,7 +3927,7 @@ static void
 test_amd64_get_insn_details (void)
 {
   struct amd64_insn details;
-  gdb::byte_vector insn, tmp;
+  std::vector<gdb_byte> insn, tmp;
 
   /* INSN: add %eax,(%rcx).  */
   insn = { 0x01, 0x01 };
@@ -3961,11 +3964,12 @@ test_amd64_get_insn_details (void)
   SELF_CHECK (rip_relative_offset (&details) == 3);
 
   /* INSN: lea 0x1e(%ecx),%rdi, rex prefix.  */
-  gdb::byte_vector updated_insn = { 0x48, 0x8d, 0xb9, 0x1e, 0x00, 0x00, 0x00 };
+  std::vector<gdb_byte> updated_insn
+    = { 0x48, 0x8d, 0xb9, 0x1e, 0x00, 0x00, 0x00 };
   fixup_riprel (details, insn.data (), ECX_REG_NUM);
   SELF_CHECK (insn == updated_insn);
 
-  gdb::byte_vector vex2, vex3;
+  std::vector<gdb_byte> vex2, vex3;
 
   /* INSN: vzeroall, vex2 prefix.  */
   vex2 = { 0xc5, 0xfc, 0x77 };
@@ -4008,7 +4012,7 @@ test_amd64_get_insn_details (void)
   SELF_CHECK (details.modrm_offset == 3);
 
   /* INSN: vmovdqu 0x9(%rcx),%ymm3, vex2 prefix.  */
-  gdb::byte_vector updated_vex2
+  std::vector<gdb_byte> updated_vex2
     = { 0xc5, 0xfe, 0x6f, 0x99, 0x09, 0x00, 0x00, 0x00 };
   tmp = vex2;
   fixup_riprel (details, tmp.data (), ECX_REG_NUM);
@@ -4023,7 +4027,7 @@ test_amd64_get_insn_details (void)
   SELF_CHECK (details.modrm_offset == 4);
 
   /* INSN: vmovdqu 0x9(%rcx),%ymm3, vex3 prefix.  */
-  gdb::byte_vector updated_vex3;
+  std::vector<gdb_byte> updated_vex3;
   vex2_to_vex3 (updated_vex2, updated_vex3);
   tmp = vex3;
   fixup_riprel (details, tmp.data (), ECX_REG_NUM);
-- 
2.51.0


  reply	other threads:[~2026-10-28 12:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 12:54 [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates Tom de Vries
2026-10-28 12:54 ` Tom de Vries [this message]
2026-10-28 12:54 ` [PATCH 2/2] [gdb/build] Add Wno-error=stringop-overflow Tom de Vries
2026-10-28 16:23 ` [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates Tom Tromey
2026-10-28 23:15   ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261028125445.1745119-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox