public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/testsuite] Fix gdb.cp/align.exp with gcc 12.1 / 11.3
@ 2022-05-02 15:08 Tom de Vries
  2022-05-02 16:43 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2022-05-02 15:08 UTC (permalink / raw)
  To: gdb-patches

Hi,

Starting with gcc 12.1 / gcc 11.3, for test-case gdb.cp/align.exp we run into:
...
align.cc:29:23: error: invalid application of 'alignof' to a void type^M
   29 |     unsigned a_void = alignof (void);^M
      |                       ^~~~~~~~~~~~~~^M
...

Fix this by using __alignof__ instead.

Tested on x86_64-linux, with gcc 7.5.0, gcc 12.1 and clang 12.0.1.

Any comments?

Thanks,
- Tom

[gdb/testsuite] Fix gdb.cp/align.exp with gcc 12.1 / 11.3

---
 gdb/testsuite/gdb.cp/align.exp | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/gdb/testsuite/gdb.cp/align.exp b/gdb/testsuite/gdb.cp/align.exp
index 6cda04798e8..018a297cde9 100644
--- a/gdb/testsuite/gdb.cp/align.exp
+++ b/gdb/testsuite/gdb.cp/align.exp
@@ -80,8 +80,19 @@ puts $outfile {
 
     unsigned a_int3 = alignof (int[3]);
 
-#if !defined (__clang__)
-    unsigned a_void = alignof (void);
+#if defined __GNUC__ && !defined __clang__
+    /* As a GNU C extension, GCC allows void pointer arithmetic, with
+       sizeof (void) == 1.
+       Another GNU C extension is __alignof__, which can be used to get
+       __alignof__ (void), which is also 1.  This is unavailabe on clang.
+       GCC used to only warn for alignof (void), but starting with GCC 12.1,
+       as well as GCC 11.3, it will generate an error (note that using
+       -std=gnu++11 does not prevent the error).
+       So we avoid using alignof, and use __alignof__ instead.  */
+    unsigned a_void = __alignof__ (void);
+#else
+    /* No support for __alignof__ (void), hardcode value.  */
+    unsigned a_void = 1;
 #endif
 
     struct base { char c; };
@@ -173,13 +184,5 @@ foreach type $typelist {
 set expected [get_integer_valueof a_int3 0]
 gdb_test "print alignof(int\[3\])" " = $expected"
 
-# As an extension, GCC allows void pointer arithmetic, with
-# sizeof(void) and alignof(void) both 1.  This test checks
-# GDB's support of GCC's extension.
-if [test_compiler_info clang*] {
-    # Clang doesn't support GCC's extension.
-    set expected 1
-} else {
-    set expected [get_integer_valueof a_void 0]
-}
+set expected [get_integer_valueof a_void 0]
 gdb_test "print alignof(void)" " = $expected"

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

* Re: [PATCH][gdb/testsuite] Fix gdb.cp/align.exp with gcc 12.1 / 11.3
  2022-05-02 15:08 [PATCH][gdb/testsuite] Fix gdb.cp/align.exp with gcc 12.1 / 11.3 Tom de Vries
@ 2022-05-02 16:43 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2022-05-02 16:43 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches

>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> Hi,
Tom> Starting with gcc 12.1 / gcc 11.3, for test-case gdb.cp/align.exp we run into:
Tom> ...
Tom> align.cc:29:23: error: invalid application of 'alignof' to a void type^M
Tom>    29 |     unsigned a_void = alignof (void);^M
Tom>       |                       ^~~~~~~~~~~~~~^M
Tom> ...

Tom> Fix this by using __alignof__ instead.

Tom> Tested on x86_64-linux, with gcc 7.5.0, gcc 12.1 and clang 12.0.1.

Tom> Any comments?

This seems fine to me.

Tom

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

end of thread, other threads:[~2022-05-02 16:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-02 15:08 [PATCH][gdb/testsuite] Fix gdb.cp/align.exp with gcc 12.1 / 11.3 Tom de Vries
2022-05-02 16:43 ` Tom Tromey

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