public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Skip tests requiring "alignof (void)" when compiling using clang
@ 2020-06-30 15:03 Gary Benson
  2020-06-30 17:10 ` Luis Machado
  2020-07-02 20:49 ` Pedro Alves
  0 siblings, 2 replies; 7+ messages in thread
From: Gary Benson @ 2020-06-30 15:03 UTC (permalink / raw)
  To: gdb-patches

Hi all,

Clang fails to compile the generated output of gdb.cp/align.exp with
the following error: invalid application of 'alignof' to an incomplete
type 'void'.  This patch adds preprocessor conditionals to the
generated output, to avoid the offending code, and causes the tests
that require it to be skipped.

Checked on Fedora 31 x86_64, GCC and clang.  Ok to commit?

Cheers,
Gary

--
gdb/testsuite/ChangeLog:

	* gdb.cp/align.exp: Skip tests requiring "alignof (void)"
	when compiling using clang.
---
 gdb/testsuite/ChangeLog        | 5 +++++
 gdb/testsuite/gdb.cp/align.exp | 9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.cp/align.exp b/gdb/testsuite/gdb.cp/align.exp
index 0905a27..65ffb3b 100644
--- a/gdb/testsuite/gdb.cp/align.exp
+++ b/gdb/testsuite/gdb.cp/align.exp
@@ -80,7 +80,9 @@ puts $outfile {
 
     unsigned a_int3 = alignof (int[3]);
 
+#if !defined(__clang__)
     unsigned a_void = alignof (void);
+#endif
 
     struct base { char c; };
     struct derived : public virtual base { int i; };
@@ -170,5 +172,8 @@ foreach type $typelist {
 
 set expected [get_integer_valueof a_int3 0]
 gdb_test "print alignof(int\[3\])" " = $expected"
-set expected [get_integer_valueof a_void 0]
-gdb_test "print alignof(void)" " = $expected"
+
+if ![test_compiler_info clang*] {
+    set expected [get_integer_valueof a_void 0]
+    gdb_test "print alignof(void)" " = $expected"
+}
-- 
1.8.3.1


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

* Re: [PATCH] Skip tests requiring "alignof (void)" when compiling using clang
  2020-06-30 15:03 [PATCH] Skip tests requiring "alignof (void)" when compiling using clang Gary Benson
@ 2020-06-30 17:10 ` Luis Machado
  2020-07-02 20:50   ` Pedro Alves
  2020-07-02 20:49 ` Pedro Alves
  1 sibling, 1 reply; 7+ messages in thread
From: Luis Machado @ 2020-06-30 17:10 UTC (permalink / raw)
  To: Gary Benson, gdb-patches

Hi,

On 6/30/20 12:03 PM, Gary Benson via Gdb-patches wrote:
> Hi all,
> 
> Clang fails to compile the generated output of gdb.cp/align.exp with
> the following error: invalid application of 'alignof' to an incomplete
> type 'void'.  This patch adds preprocessor conditionals to the
> generated output, to avoid the offending code, and causes the tests
> that require it to be skipped.
> 
> Checked on Fedora 31 x86_64, GCC and clang.  Ok to commit?
> 
> Cheers,
> Gary
> 
> --
> gdb/testsuite/ChangeLog:
> 
> 	* gdb.cp/align.exp: Skip tests requiring "alignof (void)"
> 	when compiling using clang.
> ---
>   gdb/testsuite/ChangeLog        | 5 +++++
>   gdb/testsuite/gdb.cp/align.exp | 9 +++++++--
>   2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.cp/align.exp b/gdb/testsuite/gdb.cp/align.exp
> index 0905a27..65ffb3b 100644
> --- a/gdb/testsuite/gdb.cp/align.exp
> +++ b/gdb/testsuite/gdb.cp/align.exp
> @@ -80,7 +80,9 @@ puts $outfile {
>   
>       unsigned a_int3 = alignof (int[3]);
>   
> +#if !defined(__clang__)
>       unsigned a_void = alignof (void);
> +#endif
>   
>       struct base { char c; };
>       struct derived : public virtual base { int i; };
> @@ -170,5 +172,8 @@ foreach type $typelist {
>   
>   set expected [get_integer_valueof a_int3 0]
>   gdb_test "print alignof(int\[3\])" " = $expected"
> -set expected [get_integer_valueof a_void 0]
> -gdb_test "print alignof(void)" " = $expected"
> +
> +if ![test_compiler_info clang*] {
> +    set expected [get_integer_valueof a_void 0]
> +    gdb_test "print alignof(void)" " = $expected"
> +}
> 

Instead of adding such pre-processing blocks, should we fix the code 
instead, to be more portable across compilers?

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

* Re: [PATCH] Skip tests requiring "alignof (void)" when compiling using clang
  2020-06-30 15:03 [PATCH] Skip tests requiring "alignof (void)" when compiling using clang Gary Benson
  2020-06-30 17:10 ` Luis Machado
@ 2020-07-02 20:49 ` Pedro Alves
  2020-07-02 20:52   ` Simon Marchi
  2020-07-20 14:10   ` [PUSHED] " Gary Benson
  1 sibling, 2 replies; 7+ messages in thread
From: Pedro Alves @ 2020-07-02 20:49 UTC (permalink / raw)
  To: Gary Benson, gdb-patches

On 6/30/20 4:03 PM, Gary Benson via Gdb-patches wrote:
> Hi all,
> 
> Clang fails to compile the generated output of gdb.cp/align.exp with
> the following error: invalid application of 'alignof' to an incomplete
> type 'void'.  This patch adds preprocessor conditionals to the
> generated output, to avoid the offending code, and causes the tests
> that require it to be skipped.
> 
> Checked on Fedora 31 x86_64, GCC and clang.  Ok to commit?
> 
> Cheers,
> Gary
> 
> --
> gdb/testsuite/ChangeLog:
> 
> 	* gdb.cp/align.exp: Skip tests requiring "alignof (void)"
> 	when compiling using clang.
> ---
>  gdb/testsuite/ChangeLog        | 5 +++++
>  gdb/testsuite/gdb.cp/align.exp | 9 +++++++--
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.cp/align.exp b/gdb/testsuite/gdb.cp/align.exp
> index 0905a27..65ffb3b 100644
> --- a/gdb/testsuite/gdb.cp/align.exp
> +++ b/gdb/testsuite/gdb.cp/align.exp
> @@ -80,7 +80,9 @@ puts $outfile {
>  
>      unsigned a_int3 = alignof (int[3]);
>  
> +#if !defined(__clang__)
>      unsigned a_void = alignof (void);
> +#endif

Space before parens:

  #if !defined (__clang__)

Or:

  #ifndef __clang__

>  
>      struct base { char c; };
>      struct derived : public virtual base { int i; };
> @@ -170,5 +172,8 @@ foreach type $typelist {
>  
>  set expected [get_integer_valueof a_int3 0]
>  gdb_test "print alignof(int\[3\])" " = $expected"
> -set expected [get_integer_valueof a_void 0]
> -gdb_test "print alignof(void)" " = $expected"
> +
> +if ![test_compiler_info clang*] {
> +    set expected [get_integer_valueof a_void 0]
> +    gdb_test "print alignof(void)" " = $expected"
> +}

I think this should still test GDB's support.  And a
comment would be helpful.  Like:

# As an extension, GCC allows void pointer arithmetic, with
# sizeof(void) and alignof(void) both 1.  GDB supports GCC's
# extension.  Clang does not.
if ![test_compiler_info clang*] {
    set expected [get_integer_valueof a_void 0]
    gdb_test "print alignof(void)" " = $expected"
} else {
    gdb_test "print alignof(void)" " = 1"
}

OK with those changes, and the commit log adjusted accordingly.

Pedro Alves

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

* Re: [PATCH] Skip tests requiring "alignof (void)" when compiling using clang
  2020-06-30 17:10 ` Luis Machado
@ 2020-07-02 20:50   ` Pedro Alves
  0 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2020-07-02 20:50 UTC (permalink / raw)
  To: Luis Machado, Gary Benson, gdb-patches

On 6/30/20 6:10 PM, Luis Machado via Gdb-patches wrote:

> Instead of adding such pre-processing blocks, should we fix the code instead, to be more portable across compilers?

Not in this case -- we're testing that GDB supports the GCC extension too.

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

* Re: [PATCH] Skip tests requiring "alignof (void)" when compiling using clang
  2020-07-02 20:49 ` Pedro Alves
@ 2020-07-02 20:52   ` Simon Marchi
  2020-07-02 21:08     ` Pedro Alves
  2020-07-20 14:10   ` [PUSHED] " Gary Benson
  1 sibling, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2020-07-02 20:52 UTC (permalink / raw)
  To: Pedro Alves, Gary Benson, gdb-patches

On 2020-07-02 4:49 p.m., Pedro Alves wrote:
> I think this should still test GDB's support.  And a
> comment would be helpful.  Like:
> 
> # As an extension, GCC allows void pointer arithmetic, with
> # sizeof(void) and alignof(void) both 1.  GDB supports GCC's
> # extension.  Clang does not.
> if ![test_compiler_info clang*] {
>     set expected [get_integer_valueof a_void 0]
>     gdb_test "print alignof(void)" " = $expected"
> } else {
>     gdb_test "print alignof(void)" " = 1"
> }

Indeed.  Otherwise, let's say that clang gain this feature, it would remain untested
(when testing with clang) and nobody would think of coming here to update the test
case.  Here, if clang gains the feature, then I suppose it would generate a FAIL,
which would prompt us to update the test case.

Simon

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

* Re: [PATCH] Skip tests requiring "alignof (void)" when compiling using clang
  2020-07-02 20:52   ` Simon Marchi
@ 2020-07-02 21:08     ` Pedro Alves
  0 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2020-07-02 21:08 UTC (permalink / raw)
  To: Simon Marchi, Gary Benson, gdb-patches

On 7/2/20 9:52 PM, Simon Marchi wrote:
> On 2020-07-02 4:49 p.m., Pedro Alves wrote:
>> I think this should still test GDB's support.  And a
>> comment would be helpful.  Like:
>>
>> # As an extension, GCC allows void pointer arithmetic, with
>> # sizeof(void) and alignof(void) both 1.  GDB supports GCC's
>> # extension.  Clang does not.
>> if ![test_compiler_info clang*] {
>>     set expected [get_integer_valueof a_void 0]
>>     gdb_test "print alignof(void)" " = $expected"
>> } else {
>>     gdb_test "print alignof(void)" " = 1"
>> }
> 
> Indeed.  Otherwise, let's say that clang gain this feature, it would remain untested
> (when testing with clang) and nobody would think of coming here to update the test
> case.  Here, if clang gains the feature, then I suppose it would generate a FAIL,
> which would prompt us to update the test case.

Actually, if Clang gains the feature, the test would still pass.
GDB's alignof support is builtin, does not depend on what the compiler
outputs.

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

* [PUSHED] Skip tests requiring "alignof (void)" when compiling using clang
  2020-07-02 20:49 ` Pedro Alves
  2020-07-02 20:52   ` Simon Marchi
@ 2020-07-20 14:10   ` Gary Benson
  1 sibling, 0 replies; 7+ messages in thread
From: Gary Benson @ 2020-07-20 14:10 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves, Luis Machado, Simon Marchi

Hi all,

Thanks for the reviews.  This is the version that I pushed.
The last part isn't exactly as Pedro suggested, so I hope
it's ok!

Cheers,
Gary

--
As an extension, GCC allows void pointer arithmetic, with sizeof(void)
and alignof(void) both 1.  GDB supports this extension, but clang does
not, and fails to compile the generated output of gdb.cp/align.exp
with the following error:

 gdb compile failed, /gdbtest/build/gdb/testsuite/outputs/gdb.cp/align/align.cc:28:23:
       error: invalid application of 'alignof' to an incomplete type 'void'
    unsigned a_void = alignof (void);
                      ^       ~~~~~~
 1 error generated.

This commit adds preprocessor conditionals to the generated output, to
omit the unsupported code when using clang, and supplies the expected
value so the test can complete.

gdb/testsuite/ChangeLog:

	* gdb.cp/align.exp: Fix "alignof (void)" tests when compiling
	with clang.
---
 gdb/testsuite/ChangeLog        |  5 +++++
 gdb/testsuite/gdb.cp/align.exp | 13 ++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.cp/align.exp b/gdb/testsuite/gdb.cp/align.exp
index 0905a27..4894de0 100644
--- a/gdb/testsuite/gdb.cp/align.exp
+++ b/gdb/testsuite/gdb.cp/align.exp
@@ -80,7 +80,9 @@ puts $outfile {
 
     unsigned a_int3 = alignof (int[3]);
 
+#if !defined (__clang__)
     unsigned a_void = alignof (void);
+#endif
 
     struct base { char c; };
     struct derived : public virtual base { int i; };
@@ -170,5 +172,14 @@ foreach type $typelist {
 
 set expected [get_integer_valueof a_int3 0]
 gdb_test "print alignof(int\[3\])" " = $expected"
-set expected [get_integer_valueof a_void 0]
+
+# 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]
+}
 gdb_test "print alignof(void)" " = $expected"
-- 
1.8.3.1


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

end of thread, other threads:[~2020-07-20 14:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30 15:03 [PATCH] Skip tests requiring "alignof (void)" when compiling using clang Gary Benson
2020-06-30 17:10 ` Luis Machado
2020-07-02 20:50   ` Pedro Alves
2020-07-02 20:49 ` Pedro Alves
2020-07-02 20:52   ` Simon Marchi
2020-07-02 21:08     ` Pedro Alves
2020-07-20 14:10   ` [PUSHED] " Gary Benson

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