public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [COMMITTED PATCH] [aarch64] Avoid initializers for VLAs
@ 2023-02-09 19:06 Roland McGrath
  2023-02-09 19:13 ` Simon Marchi
  2023-02-09 22:51 ` Luis Machado
  0 siblings, 2 replies; 3+ messages in thread
From: Roland McGrath @ 2023-02-09 19:06 UTC (permalink / raw)
  To: GDB

C99 does not permit initializers for variable length arrays, and Clang
now enforces this.
Committed as obvious enough.

Thanks,
Roland

commit b695fdd9b2494a64db1fb8e584753a1a5afec494 (HEAD -> master)
Author: Roland McGrath <mcgrathr@google.com>
Date:   Thu Feb 9 10:47:17 2023 -0800

    [aarch64] Avoid initializers for VLAs

    Clang doesn't accept initializer syntax for variable-length
    arrays in C. Just use memset instead.

diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index e4158236db2..ecb2eeb9540 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -56,6 +56,8 @@

 #include "nat/aarch64-mte-linux-ptrace.h"

+#include <string.h>
+
 #ifndef TRAP_HWBKPT
 #define TRAP_HWBKPT 0x0004
 #endif
@@ -445,7 +447,9 @@ fetch_tlsregs_from_thread (struct regcache *regcache)
   gdb_assert (regno != -1);
   gdb_assert (tdep->tls_register_count > 0);

-  uint64_t tpidrs[tdep->tls_register_count] = { 0 };
+  uint64_t tpidrs[tdep->tls_register_count];
+  memset(tpidrs, 0, sizeof(tpidrs));
+
   struct iovec iovec;
   iovec.iov_base = tpidrs;
   iovec.iov_len = sizeof (tpidrs);
@@ -471,7 +475,8 @@ store_tlsregs_to_thread (struct regcache *regcache)
   gdb_assert (regno != -1);
   gdb_assert (tdep->tls_register_count > 0);

-  uint64_t tpidrs[tdep->tls_register_count] = { 0 };
+  uint64_t tpidrs[tdep->tls_register_count];
+  memset(tpidrs, 0, sizeof(tpidrs));

   for (int i = 0; i < tdep->tls_register_count; i++)
     {

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

* Re: [COMMITTED PATCH] [aarch64] Avoid initializers for VLAs
  2023-02-09 19:06 [COMMITTED PATCH] [aarch64] Avoid initializers for VLAs Roland McGrath
@ 2023-02-09 19:13 ` Simon Marchi
  2023-02-09 22:51 ` Luis Machado
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2023-02-09 19:13 UTC (permalink / raw)
  To: Roland McGrath, GDB

On 2/9/23 14:06, Roland McGrath via Gdb-patches wrote:
> C99 does not permit initializers for variable length arrays, and Clang
> now enforces this.
> Committed as obvious enough.
>
> commit b695fdd9b2494a64db1fb8e584753a1a5afec494 (HEAD -> master)
> Author: Roland McGrath <mcgrathr@google.com>
> Date:   Thu Feb 9 10:47:17 2023 -0800
> 
>     [aarch64] Avoid initializers for VLAs
> 
>     Clang doesn't accept initializer syntax for variable-length
>     arrays in C. Just use memset instead.

"C99" and "C" don't really make sense, since this is C++.  Perhaps it's
the same error in C++, but the message is a bit misleading.

It's too late for this one, but when fixing a compilation error, please
put the compiler error in the commit message.

> 
> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
> index e4158236db2..ecb2eeb9540 100644
> --- a/gdb/aarch64-linux-nat.c
> +++ b/gdb/aarch64-linux-nat.c
> @@ -56,6 +56,8 @@
> 
>  #include "nat/aarch64-mte-linux-ptrace.h"
> 
> +#include <string.h>
> +
>  #ifndef TRAP_HWBKPT
>  #define TRAP_HWBKPT 0x0004
>  #endif
> @@ -445,7 +447,9 @@ fetch_tlsregs_from_thread (struct regcache *regcache)
>    gdb_assert (regno != -1);
>    gdb_assert (tdep->tls_register_count > 0);
> 
> -  uint64_t tpidrs[tdep->tls_register_count] = { 0 };
> +  uint64_t tpidrs[tdep->tls_register_count];
> +  memset(tpidrs, 0, sizeof(tpidrs));

Missing space before parentheses.

> +
>    struct iovec iovec;
>    iovec.iov_base = tpidrs;
>    iovec.iov_len = sizeof (tpidrs);
> @@ -471,7 +475,8 @@ store_tlsregs_to_thread (struct regcache *regcache)
>    gdb_assert (regno != -1);
>    gdb_assert (tdep->tls_register_count > 0);
> 
> -  uint64_t tpidrs[tdep->tls_register_count] = { 0 };
> +  uint64_t tpidrs[tdep->tls_register_count];
> +  memset(tpidrs, 0, sizeof(tpidrs));

Same.

Simon

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

* Re: [COMMITTED PATCH] [aarch64] Avoid initializers for VLAs
  2023-02-09 19:06 [COMMITTED PATCH] [aarch64] Avoid initializers for VLAs Roland McGrath
  2023-02-09 19:13 ` Simon Marchi
@ 2023-02-09 22:51 ` Luis Machado
  1 sibling, 0 replies; 3+ messages in thread
From: Luis Machado @ 2023-02-09 22:51 UTC (permalink / raw)
  To: Roland McGrath, GDB

On 2/9/23 19:06, Roland McGrath via Gdb-patches wrote:
> C99 does not permit initializers for variable length arrays, and Clang
> now enforces this.
> Committed as obvious enough.

Yep. Thanks for patching this up.

> 
> Thanks,
> Roland
> 
> commit b695fdd9b2494a64db1fb8e584753a1a5afec494 (HEAD -> master)
> Author: Roland McGrath <mcgrathr@google.com>
> Date:   Thu Feb 9 10:47:17 2023 -0800
> 
>      [aarch64] Avoid initializers for VLAs
> 
>      Clang doesn't accept initializer syntax for variable-length
>      arrays in C. Just use memset instead.
> 
> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
> index e4158236db2..ecb2eeb9540 100644
> --- a/gdb/aarch64-linux-nat.c
> +++ b/gdb/aarch64-linux-nat.c
> @@ -56,6 +56,8 @@
> 
>   #include "nat/aarch64-mte-linux-ptrace.h"
> 
> +#include <string.h>
> +
>   #ifndef TRAP_HWBKPT
>   #define TRAP_HWBKPT 0x0004
>   #endif
> @@ -445,7 +447,9 @@ fetch_tlsregs_from_thread (struct regcache *regcache)
>     gdb_assert (regno != -1);
>     gdb_assert (tdep->tls_register_count > 0);
> 
> -  uint64_t tpidrs[tdep->tls_register_count] = { 0 };
> +  uint64_t tpidrs[tdep->tls_register_count];
> +  memset(tpidrs, 0, sizeof(tpidrs));
> +
>     struct iovec iovec;
>     iovec.iov_base = tpidrs;
>     iovec.iov_len = sizeof (tpidrs);
> @@ -471,7 +475,8 @@ store_tlsregs_to_thread (struct regcache *regcache)
>     gdb_assert (regno != -1);
>     gdb_assert (tdep->tls_register_count > 0);
> 
> -  uint64_t tpidrs[tdep->tls_register_count] = { 0 };
> +  uint64_t tpidrs[tdep->tls_register_count];
> +  memset(tpidrs, 0, sizeof(tpidrs));
> 
>     for (int i = 0; i < tdep->tls_register_count; i++)
>       {


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

end of thread, other threads:[~2023-02-09 22:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09 19:06 [COMMITTED PATCH] [aarch64] Avoid initializers for VLAs Roland McGrath
2023-02-09 19:13 ` Simon Marchi
2023-02-09 22:51 ` Luis Machado

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).