public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison
@ 2020-05-29 13:03 Gary Benson
  2020-05-29 18:08 ` Tom Tromey
  0 siblings, 1 reply; 11+ messages in thread
From: Gary Benson @ 2020-05-29 13:03 UTC (permalink / raw)
  To: gdb-patches

Clang fails to compile two testcases with the following error:
  warning: equality comparison result unused [-Wunused-comparison]

This prevents the following testcases from executing:
  gdb.cp/koenig.exp
  gdb.cp/operator.exp

This commit builds those testcases with -Wno-unused-comparison, to
avoid the failure.  Note that this commit reveals a new failure,
"FAIL: gdb.cp/koenig.exp: p foo (p_union)" when the testsuite is
compiled using clang.

gdb/testsuite/ChangeLog:

	* gdb.cp/koenig.exp (prepare_for_testing): Add
	additional_flags=-Wno-unused-comparison.
	* gdb.cp/operator.exp (prepare_for_testing): Likewise.
---
 gdb/testsuite/ChangeLog           | 6 ++++++
 gdb/testsuite/gdb.cp/koenig.exp   | 3 ++-
 gdb/testsuite/gdb.cp/operator.exp | 3 ++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.cp/koenig.exp b/gdb/testsuite/gdb.cp/koenig.exp
index b40ee43..25be2e5 100644
--- a/gdb/testsuite/gdb.cp/koenig.exp
+++ b/gdb/testsuite/gdb.cp/koenig.exp
@@ -15,7 +15,8 @@
 
 standard_testfile .cc
 
-if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug c++}] } {
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
+      {debug c++ additional_flags=-Wno-unused-comparison}] } {
      return -1
 }
 
diff --git a/gdb/testsuite/gdb.cp/operator.exp b/gdb/testsuite/gdb.cp/operator.exp
index c2d2bdf..b48cd44 100644
--- a/gdb/testsuite/gdb.cp/operator.exp
+++ b/gdb/testsuite/gdb.cp/operator.exp
@@ -15,7 +15,8 @@
 
 standard_testfile .cc
 
-if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug c++}] } {
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
+	  {debug c++ additional_flags=-Wno-unused-comparison}] } {
     return -1
 }
 
-- 
1.8.3.1


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

* Re: [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison
  2020-05-29 13:03 [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison Gary Benson
@ 2020-05-29 18:08 ` Tom Tromey
  2020-05-29 18:31   ` Pedro Alves
  2020-06-16 12:38   ` [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison Gary Benson
  0 siblings, 2 replies; 11+ messages in thread
From: Tom Tromey @ 2020-05-29 18:08 UTC (permalink / raw)
  To: Gary Benson via Gdb-patches

>>>>> "Gary" == Gary Benson via Gdb-patches <gdb-patches@sourceware.org> writes:

Gary> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
Gary> +      {debug c++ additional_flags=-Wno-unused-comparison}] } {

Won't this cause build (and therefore test) failures if the compiler
does not accept this option?

I wonder if there's a way to fix the warning in the C++ source file
instead.

Tom

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

* Re: [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison
  2020-05-29 18:08 ` Tom Tromey
@ 2020-05-29 18:31   ` Pedro Alves
  2020-06-16 12:42     ` Gary Benson
  2020-06-16 12:38   ` [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison Gary Benson
  1 sibling, 1 reply; 11+ messages in thread
From: Pedro Alves @ 2020-05-29 18:31 UTC (permalink / raw)
  To: Tom Tromey, Gary Benson via Gdb-patches

On 5/29/20 7:08 PM, Tom Tromey wrote:
>>>>>> "Gary" == Gary Benson via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Gary> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
> Gary> +      {debug c++ additional_flags=-Wno-unused-comparison}] } {
> 
> Won't this cause build (and therefore test) failures if the compiler
> does not accept this option?

I think that by design, while GCC errors out about unknown -Wfoo warnings,
it ignores -Wno-foo, so that you can disable newer warnings without worrying
about older compilers:

 $ gcc main.c -o main -g3 -O0 -Wfoo
 gcc: error: unrecognized command line option ‘-Wfoo’
 $ gcc main.c -o main -g3 -O0 -Wno-foo

However, Clang seems to output a warning in either case:

 $ clang main.c -o main -g3 -O0 -Wfoo
 warning: unknown warning option '-Wfoo' [-Wunknown-warning-option]
 1 warning generated.
 $ clang main.c -o main -g3 -O0 -Wno-foo
 warning: unknown warning option '-Wno-foo' [-Wunknown-warning-option]
 1 warning generated.

(This was clang 5.0.2)

So that new option can break tests with older Clangs that don't
know about the option.  I guess to prevent this sort of thing going
forward, we could make gcc_compile always add -Wno-unknown-warning-option
to the build flags.  I don't know when was that option added to Clang,
but maybe it's ancient enough.

I don't know about other compilers, though.

> I wonder if there's a way to fix the warning in the C++ source file
> instead.

Yeah, me too.  Though the idea above could be helpful for other
tests/cases.

Thanks,
Pedro Alves


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

* Re: [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison
  2020-05-29 18:08 ` Tom Tromey
  2020-05-29 18:31   ` Pedro Alves
@ 2020-06-16 12:38   ` Gary Benson
  1 sibling, 0 replies; 11+ messages in thread
From: Gary Benson @ 2020-06-16 12:38 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Tom Tromey wrote:
> >>>>> "Gary" == Gary Benson via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Gary> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
> Gary> +      {debug c++ additional_flags=-Wno-unused-comparison}] } {
> 
> Won't this cause build (and therefore test) failures if the compiler
> does not accept this option?
> 
> I wonder if there's a way to fix the warning in the C++ source file
> instead.

Yes, ideally, but by no means always.  I'm working my way through
these failures, and in many cases the "issue" the warning caught
was intended, some weird thing placed specifically to test some
functionality of GDB.  For example:

  Running /gdbtest/build/gdb/testsuite/../../../src/gdb/testsuite/gdb.cp/ambiguous.exp ...
  gdb compile failed, /gdbtest/build/gdb/testsuite/../../../src/gdb/testsuite/gdb.cp/ambiguous.cc:70:36:
  warning: direct base 'A1' is inaccessible due to ambiguity:
      class JVA1 -> class KV -> class A1
      class JVA1 -> class A1 [-Winaccessible-base]
  class JVA1 : public KV, public LV, public A1 {
                                     ^~~~~~~~~
  1 warning generated.

This one's obviously intentional, gdb.cp/abmigiuous.exp contains
"tests relating to ambiguous class members".  But a lot of these
cases aren't obvious, at least not to me.  Is something a mistake?
Some piece of K&R C from 1988 that was machine-converted in 1994?
Or some real thing put there to stop GCC optimizing something out?
I'm very much NOT someone to ask about code generation nuances!
If something's obvious or (ha!) documented I can fix the source;
places I've disabled warnings are where I couldn't tell what was
intended/expected.

Cheers,
Gary


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

* Re: [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison
  2020-05-29 18:31   ` Pedro Alves
@ 2020-06-16 12:42     ` Gary Benson
  2020-06-16 15:11       ` Pedro Alves
  0 siblings, 1 reply; 11+ messages in thread
From: Gary Benson @ 2020-06-16 12:42 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

Pedro Alves wrote:
> On 5/29/20 7:08 PM, Tom Tromey wrote:
> >>>>>> "Gary" == Gary Benson via Gdb-patches <gdb-patches@sourceware.org> writes:
> > 
> > Gary> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
> > Gary> +      {debug c++ additional_flags=-Wno-unused-comparison}] } {
> > 
> > Won't this cause build (and therefore test) failures if the compiler
> > does not accept this option?
> 
> I think that by design, while GCC errors out about unknown -Wfoo warnings,
> it ignores -Wno-foo, so that you can disable newer warnings without worrying
> about older compilers:
> 
>  $ gcc main.c -o main -g3 -O0 -Wfoo
>  gcc: error: unrecognized command line option ‘-Wfoo’
>  $ gcc main.c -o main -g3 -O0 -Wno-foo

Nice.

> However, Clang seems to output a warning in either case:
> 
>  $ clang main.c -o main -g3 -O0 -Wfoo
>  warning: unknown warning option '-Wfoo' [-Wunknown-warning-option]
>  1 warning generated.
>  $ clang main.c -o main -g3 -O0 -Wno-foo
>  warning: unknown warning option '-Wno-foo' [-Wunknown-warning-option]
>  1 warning generated.
> 
> (This was clang 5.0.2)
> 
> So that new option can break tests with older Clangs that don't
> know about the option.

Ugh.

clang 9.0.1 behaves the same too:

 $ clang -Werror -Wno-step-on-grass test.c
 error: unknown warning option '-Wno-step-on-grass' [-Werror,-Wunknown-warning-option]

> I guess to prevent this sort of thing going forward, we could make
> gcc_compile always add -Wno-unknown-warning-option to the build
> flags.  I don't know when was that option added to Clang, but maybe
> it's ancient enough.

Does this buy us much?  Any test with a warning I disable for clang is
a test that didn't compile with clang anyway.

Cheers,
Gary


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

* Re: [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison
  2020-06-16 12:42     ` Gary Benson
@ 2020-06-16 15:11       ` Pedro Alves
  2020-06-17 17:29         ` Gary Benson
  0 siblings, 1 reply; 11+ messages in thread
From: Pedro Alves @ 2020-06-16 15:11 UTC (permalink / raw)
  To: Gary Benson; +Cc: Tom Tromey, gdb-patches

On 6/16/20 1:42 PM, Gary Benson wrote:
> Pedro Alves wrote:
>> On 5/29/20 7:08 PM, Tom Tromey wrote:
>>>>>>>> "Gary" == Gary Benson via Gdb-patches <gdb-patches@sourceware.org> writes:
>>>
>>> Gary> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
>>> Gary> +      {debug c++ additional_flags=-Wno-unused-comparison}] } {
>>>
>>> Won't this cause build (and therefore test) failures if the compiler
>>> does not accept this option?
>>
>> I think that by design, while GCC errors out about unknown -Wfoo warnings,
>> it ignores -Wno-foo, so that you can disable newer warnings without worrying
>> about older compilers:
>>
>>  $ gcc main.c -o main -g3 -O0 -Wfoo
>>  gcc: error: unrecognized command line option ‘-Wfoo’
>>  $ gcc main.c -o main -g3 -O0 -Wno-foo
> 
> Nice.
> 
>> However, Clang seems to output a warning in either case:
>>
>>  $ clang main.c -o main -g3 -O0 -Wfoo
>>  warning: unknown warning option '-Wfoo' [-Wunknown-warning-option]
>>  1 warning generated.
>>  $ clang main.c -o main -g3 -O0 -Wno-foo
>>  warning: unknown warning option '-Wno-foo' [-Wunknown-warning-option]
>>  1 warning generated.
>>
>> (This was clang 5.0.2)
>>
>> So that new option can break tests with older Clangs that don't
>> know about the option.
> 
> Ugh.
> 
> clang 9.0.1 behaves the same too:
> 
>  $ clang -Werror -Wno-step-on-grass test.c
>  error: unknown warning option '-Wno-step-on-grass' [-Werror,-Wunknown-warning-option]
> 
>> I guess to prevent this sort of thing going forward, we could make
>> gcc_compile always add -Wno-unknown-warning-option to the build
>> flags.  I don't know when was that option added to Clang, but maybe
>> it's ancient enough.
> 
> Does this buy us much?  Any test with a warning I disable for clang is
> a test that didn't compile with clang anyway.

It didn't compile with the version you tested.  Do you know whether
it compiled with older clang versions?

In general, the problematic sequence is something like this:

#1 - A testcase compiles successfully with clang version X.
#2 - clang version "X + 1" adds a new warning, enabled by default,
     which breaks the test.
#3 - We add -Wno-newwarning, fixing the testcase with clang "X + 1"
#4 - Now building the test with clang version X no longer works,
     due to "unknown warning option".

Making gcc_compile always add -Wno-unknown-warning-option to the
build flags fixes this problem for good.  At least with clang.

Pedro Alves


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

* Re: [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison
  2020-06-16 15:11       ` Pedro Alves
@ 2020-06-17 17:29         ` Gary Benson
  2020-06-17 19:53           ` [PATCH] W/ Clang, compile C/C++ testcases with -Wno-unknown-warning-option Pedro Alves
  0 siblings, 1 reply; 11+ messages in thread
From: Gary Benson @ 2020-06-17 17:29 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

Pedro Alves wrote:
> On 6/16/20 1:42 PM, Gary Benson wrote:
> > Pedro Alves wrote:
> >> On 5/29/20 7:08 PM, Tom Tromey wrote:
> >>>>>>>> "Gary" == Gary Benson via Gdb-patches <gdb-patches@sourceware.org> writes:
> >>>
> >>> Gary> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
> >>> Gary> +      {debug c++ additional_flags=-Wno-unused-comparison}] } {
> >>>
> >>> Won't this cause build (and therefore test) failures if the compiler
> >>> does not accept this option?
> >>
> >> I think that by design, while GCC errors out about unknown -Wfoo warnings,
> >> it ignores -Wno-foo, so that you can disable newer warnings without worrying
> >> about older compilers:
> >>
> >>  $ gcc main.c -o main -g3 -O0 -Wfoo
> >>  gcc: error: unrecognized command line option ‘-Wfoo’
> >>  $ gcc main.c -o main -g3 -O0 -Wno-foo
> > 
> > Nice.
> > 
> >> However, Clang seems to output a warning in either case:
> >>
> >>  $ clang main.c -o main -g3 -O0 -Wfoo
> >>  warning: unknown warning option '-Wfoo' [-Wunknown-warning-option]
> >>  1 warning generated.
> >>  $ clang main.c -o main -g3 -O0 -Wno-foo
> >>  warning: unknown warning option '-Wno-foo' [-Wunknown-warning-option]
> >>  1 warning generated.
> >>
> >> (This was clang 5.0.2)
> >>
> >> So that new option can break tests with older Clangs that don't
> >> know about the option.
> > 
> > Ugh.
> > 
> > clang 9.0.1 behaves the same too:
> > 
> >  $ clang -Werror -Wno-step-on-grass test.c
> >  error: unknown warning option '-Wno-step-on-grass' [-Werror,-Wunknown-warning-option]
> > 
> >> I guess to prevent this sort of thing going forward, we could make
> >> gcc_compile always add -Wno-unknown-warning-option to the build
> >> flags.  I don't know when was that option added to Clang, but maybe
> >> it's ancient enough.
> > 
> > Does this buy us much?  Any test with a warning I disable for clang is
> > a test that didn't compile with clang anyway.
> 
> It didn't compile with the version you tested.  Do you know whether
> it compiled with older clang versions?

No. 

> In general, the problematic sequence is something like this:
> 
> #1 - A testcase compiles successfully with clang version X.
> #2 - clang version "X + 1" adds a new warning, enabled by default,
>      which breaks the test.
> #3 - We add -Wno-newwarning, fixing the testcase with clang "X + 1"
> #4 - Now building the test with clang version X no longer works,
>      due to "unknown warning option".
> 
> Making gcc_compile always add -Wno-unknown-warning-option to the
> build flags fixes this problem for good.  At least with clang.

Right.

First, I'm assuming you mean gdb_compile, not gcc_compile?

Second, it's not clear whether you mean to add it always, or just
if the compiler is clang?

Third, is this something you could easily do?  Because I've spent
nearly an hour on this already, gdb_compile is nearly 250 lines of
special cases and I'm no closer to figuring out where I wouldn't
break something.

Cheers,
Gary


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

* [PATCH] W/ Clang, compile C/C++ testcases with -Wno-unknown-warning-option
  2020-06-17 17:29         ` Gary Benson
@ 2020-06-17 19:53           ` Pedro Alves
  2020-06-18 16:18             ` Gary Benson
  0 siblings, 1 reply; 11+ messages in thread
From: Pedro Alves @ 2020-06-17 19:53 UTC (permalink / raw)
  To: Gary Benson; +Cc: Tom Tromey, gdb-patches

On 6/17/20 6:29 PM, Gary Benson via Gdb-patches wrote:
> Pedro Alves wrote:

>> In general, the problematic sequence is something like this:
>>
>> #1 - A testcase compiles successfully with clang version X.
>> #2 - clang version "X + 1" adds a new warning, enabled by default,
>>      which breaks the test.
>> #3 - We add -Wno-newwarning, fixing the testcase with clang "X + 1"
>> #4 - Now building the test with clang version X no longer works,
>>      due to "unknown warning option".
>>
>> Making gcc_compile always add -Wno-unknown-warning-option to the
>> build flags fixes this problem for good.  At least with clang.
> 
> Right.
> 
> First, I'm assuming you mean gdb_compile, not gcc_compile?

Yes.

> 
> Second, it's not clear whether you mean to add it always, or just
> if the compiler is clang?

For Clang.

> 
> Third, is this something you could easily do?  Because I've spent
> nearly an hour on this already, gdb_compile is nearly 250 lines of
> special cases and I'm no closer to figuring out where I wouldn't
> break something.

Sure.  Like this.

I tried adding -Wno-foo to a testcase and checked that without
the patch it failed due to the "unknown option" warning, and
passed with the patch.

From 79f1cfddeea957a778c856c879a386901a96609b Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Wed, 17 Jun 2020 19:29:37 +0100
Subject: [PATCH] W/ Clang, compile C/C++ testcases with
 -Wno-unknown-warning-option

Some C/C++ testcases unconditionally pass -Wno-foo as additional
options to disable some warning.  That is OK with GCC, because GCC
accepts -Wno-foo silently even if it doesn't support -Wfoo.  This is a
feature which allows disabling warnings with newer compilers without
breaking builds with older compilers.  Clang however warns about
unknown -Wno-foo by default, unless you pass
-Wno-unknown-warning-option as well:

 $ gcc -Wno-foo test.c
 * nothing, compiles successfuly *

 $ clang -Wno-foo test.c
 warning: unknown warning option '-Wno-foo [-Wunknown-warning-option]

This commit adds -Wunknown-warning-option centrally in gdb_compile, so
that individual testcases don't have to worry about breaking older
Clangs.

IOW, this avoids this problematic scenario:

#1 - A testcase compiles successfully with Clang version X.
#2 - Clang version "X + 1" adds a new warning, enabled by default,
     which breaks the test.
#3 - We add -Wno-newwarning to the testcase, fixing the testcase with
     clang "X + 1".
#4 - Now building the test with Clang version X no longer works, due
     to "unknown warning option".

gdb/testsuite/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_compile): Update intro comment.  If C/C++ with
	Clang, add "-Wno-unknown-warning-option" to the options.
---
 gdb/testsuite/lib/gdb.exp | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index f502eb157d8..bbc940a4512 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3826,7 +3826,8 @@ set gdb_saved_set_unbuffered_mode_obj ""
 #   - ldflags=flag: Add FLAG to the linker flags.
 #   - incdir=path: Add PATH to the searched include directories.
 #   - libdir=path: Add PATH to the linker searched directories.
-#   - ada, c++, f77: Compile the file as Ada, C++ or Fortran.
+#   - ada, c++, f77, f90, rust: Compile the file as Ada, C++,
+#     Fortran 77, Fortran 90 or Rust.
 #   - debug: Build with debug information.
 #   - optimize: Build with optimization.
 
@@ -3850,6 +3851,22 @@ proc gdb_compile {source dest type options} {
 	set new_options [universal_compile_options]
     }
 
+    # Some C/C++ testcases unconditionally pass -Wno-foo as additional
+    # options to disable some warning.  That is OK with GCC, because
+    # by design, GCC accepts any -Wno-foo option, even if it doesn't
+    # support -Wfoo.  Clang however warns about unknown -Wno-foo by
+    # default, unless you pass -Wno-unknown-warning-option as well.
+    # We do that here, so that individual testcases don't have to
+    # worry about it.
+    if {[lsearch -exact $options getting_compiler_info] == -1
+	&& [lsearch -exact $options rust] == -1
+	&& [lsearch -exact $options ada] == -1
+	&& [lsearch -exact $options f77] == -1
+	&& [lsearch -exact $options f90] == -1
+	&& [test_compiler_info "clang-*"]} {
+	lappend new_options "additional_flags=-Wno-unknown-warning-option"
+    }
+
     # Place (and look for) Fortran `.mod` files in the output
     # directory for this specific test.
     if {[lsearch -exact $options f77] != -1 \

base-commit: 669203174311c5be76744a879563c697cd479853
-- 
2.14.5


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

* Re: [PATCH] W/ Clang, compile C/C++ testcases with -Wno-unknown-warning-option
  2020-06-17 19:53           ` [PATCH] W/ Clang, compile C/C++ testcases with -Wno-unknown-warning-option Pedro Alves
@ 2020-06-18 16:18             ` Gary Benson
  2020-06-24 22:26               ` Pedro Alves
  0 siblings, 1 reply; 11+ messages in thread
From: Gary Benson @ 2020-06-18 16:18 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

Pedro Alves wrote:
> From 79f1cfddeea957a778c856c879a386901a96609b Mon Sep 17 00:00:00 2001
> From: Pedro Alves <palves@redhat.com>
> Date: Wed, 17 Jun 2020 19:29:37 +0100
> Subject: [PATCH] W/ Clang, compile C/C++ testcases with
>  -Wno-unknown-warning-option
> 
> Some C/C++ testcases unconditionally pass -Wno-foo as additional
> options to disable some warning.  That is OK with GCC, because GCC
> accepts -Wno-foo silently even if it doesn't support -Wfoo.  This is a
> feature which allows disabling warnings with newer compilers without
> breaking builds with older compilers.  Clang however warns about
> unknown -Wno-foo by default, unless you pass
> -Wno-unknown-warning-option as well:
> 
>  $ gcc -Wno-foo test.c
>  * nothing, compiles successfuly *
> 
>  $ clang -Wno-foo test.c
>  warning: unknown warning option '-Wno-foo [-Wunknown-warning-option]
> 
> This commit adds -Wunknown-warning-option centrally in gdb_compile, so
> that individual testcases don't have to worry about breaking older
> Clangs.
> 
> IOW, this avoids this problematic scenario:
> 
> #1 - A testcase compiles successfully with Clang version X.
> #2 - Clang version "X + 1" adds a new warning, enabled by default,
>      which breaks the test.
> #3 - We add -Wno-newwarning to the testcase, fixing the testcase with
>      clang "X + 1".
> #4 - Now building the test with Clang version X no longer works, due
>      to "unknown warning option".
> 
> gdb/testsuite/ChangeLog:
> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
> 
> 	* lib/gdb.exp (gdb_compile): Update intro comment.  If C/C++ with
> 	Clang, add "-Wno-unknown-warning-option" to the options.
> ---
>  gdb/testsuite/lib/gdb.exp | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index f502eb157d8..bbc940a4512 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -3826,7 +3826,8 @@ set gdb_saved_set_unbuffered_mode_obj ""
>  #   - ldflags=flag: Add FLAG to the linker flags.
>  #   - incdir=path: Add PATH to the searched include directories.
>  #   - libdir=path: Add PATH to the linker searched directories.
> -#   - ada, c++, f77: Compile the file as Ada, C++ or Fortran.
> +#   - ada, c++, f77, f90, rust: Compile the file as Ada, C++,
> +#     Fortran 77, Fortran 90 or Rust.
>  #   - debug: Build with debug information.
>  #   - optimize: Build with optimization.
>  
> @@ -3850,6 +3851,22 @@ proc gdb_compile {source dest type options} {
>  	set new_options [universal_compile_options]
>      }
>  
> +    # Some C/C++ testcases unconditionally pass -Wno-foo as additional
> +    # options to disable some warning.  That is OK with GCC, because
> +    # by design, GCC accepts any -Wno-foo option, even if it doesn't
> +    # support -Wfoo.  Clang however warns about unknown -Wno-foo by
> +    # default, unless you pass -Wno-unknown-warning-option as well.
> +    # We do that here, so that individual testcases don't have to
> +    # worry about it.
> +    if {[lsearch -exact $options getting_compiler_info] == -1
> +	&& [lsearch -exact $options rust] == -1
> +	&& [lsearch -exact $options ada] == -1
> +	&& [lsearch -exact $options f77] == -1
> +	&& [lsearch -exact $options f90] == -1
> +	&& [test_compiler_info "clang-*"]} {
> +	lappend new_options "additional_flags=-Wno-unknown-warning-option"
> +    }
> +
>      # Place (and look for) Fortran `.mod` files in the output
>      # directory for this specific test.
>      if {[lsearch -exact $options f77] != -1 \
> 
> base-commit: 669203174311c5be76744a879563c697cd479853
> -- 
> 2.14.5

Oh, thanks, that looks great.  Could you commit it please?

Cheers,
Gary

-- 
Gary Benson - he / him / his
Principal Software Engineer, Red Hat


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

* Re: [PATCH] W/ Clang, compile C/C++ testcases with -Wno-unknown-warning-option
  2020-06-18 16:18             ` Gary Benson
@ 2020-06-24 22:26               ` Pedro Alves
  2020-07-02 10:02                 ` Gary Benson
  0 siblings, 1 reply; 11+ messages in thread
From: Pedro Alves @ 2020-06-24 22:26 UTC (permalink / raw)
  To: Gary Benson; +Cc: Tom Tromey, gdb-patches

On 6/18/20 5:18 PM, Gary Benson via Gdb-patches wrote:
> Pedro Alves wrote:
>> From 79f1cfddeea957a778c856c879a386901a96609b Mon Sep 17 00:00:00 2001
>> From: Pedro Alves <palves@redhat.com>
>> Date: Wed, 17 Jun 2020 19:29:37 +0100
>> Subject: [PATCH] W/ Clang, compile C/C++ testcases with
>>  -Wno-unknown-warning-option
>>
>> Some C/C++ testcases unconditionally pass -Wno-foo as additional
>> options to disable some warning.  That is OK with GCC, because GCC
>> accepts -Wno-foo silently even if it doesn't support -Wfoo.  This is a
>> feature which allows disabling warnings with newer compilers without
>> breaking builds with older compilers.  Clang however warns about
>> unknown -Wno-foo by default, unless you pass
>> -Wno-unknown-warning-option as well:
>>
>>  $ gcc -Wno-foo test.c
>>  * nothing, compiles successfuly *
>>
>>  $ clang -Wno-foo test.c
>>  warning: unknown warning option '-Wno-foo [-Wunknown-warning-option]
>>
>> This commit adds -Wunknown-warning-option centrally in gdb_compile, so
>> that individual testcases don't have to worry about breaking older
>> Clangs.
>>
>> IOW, this avoids this problematic scenario:
>>
>> #1 - A testcase compiles successfully with Clang version X.
>> #2 - Clang version "X + 1" adds a new warning, enabled by default,
>>      which breaks the test.
>> #3 - We add -Wno-newwarning to the testcase, fixing the testcase with
>>      clang "X + 1".
>> #4 - Now building the test with Clang version X no longer works, due
>>      to "unknown warning option".
>>
>> gdb/testsuite/ChangeLog:
>> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
>>
>> 	* lib/gdb.exp (gdb_compile): Update intro comment.  If C/C++ with
>> 	Clang, add "-Wno-unknown-warning-option" to the options.
>> ---
>>  gdb/testsuite/lib/gdb.exp | 19 ++++++++++++++++++-
>>  1 file changed, 18 insertions(+), 1 deletion(-)
>>
>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>> index f502eb157d8..bbc940a4512 100644
>> --- a/gdb/testsuite/lib/gdb.exp
>> +++ b/gdb/testsuite/lib/gdb.exp
>> @@ -3826,7 +3826,8 @@ set gdb_saved_set_unbuffered_mode_obj ""
>>  #   - ldflags=flag: Add FLAG to the linker flags.
>>  #   - incdir=path: Add PATH to the searched include directories.
>>  #   - libdir=path: Add PATH to the linker searched directories.
>> -#   - ada, c++, f77: Compile the file as Ada, C++ or Fortran.
>> +#   - ada, c++, f77, f90, rust: Compile the file as Ada, C++,
>> +#     Fortran 77, Fortran 90 or Rust.
>>  #   - debug: Build with debug information.
>>  #   - optimize: Build with optimization.
>>  
>> @@ -3850,6 +3851,22 @@ proc gdb_compile {source dest type options} {
>>  	set new_options [universal_compile_options]
>>      }
>>  
>> +    # Some C/C++ testcases unconditionally pass -Wno-foo as additional
>> +    # options to disable some warning.  That is OK with GCC, because
>> +    # by design, GCC accepts any -Wno-foo option, even if it doesn't
>> +    # support -Wfoo.  Clang however warns about unknown -Wno-foo by
>> +    # default, unless you pass -Wno-unknown-warning-option as well.
>> +    # We do that here, so that individual testcases don't have to
>> +    # worry about it.
>> +    if {[lsearch -exact $options getting_compiler_info] == -1
>> +	&& [lsearch -exact $options rust] == -1
>> +	&& [lsearch -exact $options ada] == -1
>> +	&& [lsearch -exact $options f77] == -1
>> +	&& [lsearch -exact $options f90] == -1
>> +	&& [test_compiler_info "clang-*"]} {
>> +	lappend new_options "additional_flags=-Wno-unknown-warning-option"
>> +    }
>> +
>>      # Place (and look for) Fortran `.mod` files in the output
>>      # directory for this specific test.
>>      if {[lsearch -exact $options f77] != -1 \
>>
>> base-commit: 669203174311c5be76744a879563c697cd479853
>> -- 
>> 2.14.5
> 
> Oh, thanks, that looks great.  Could you commit it please?

I've pushed this now, with just a tweak to also list "go".

From 331733cd4e2f2fe76c0b7b6fdd81e54724572354 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Wed, 24 Jun 2020 23:18:19 +0100
Subject: [PATCH] W/ Clang, compile C/C++ testcases with
 -Wno-unknown-warning-option

Some C/C++ testcases unconditionally pass -Wno-foo as additional
options to disable some warning.  That is OK with GCC, because GCC
accepts -Wno-foo silently even if it doesn't support -Wfoo.  This is a
feature which allows disabling warnings with newer compilers without
breaking builds with older compilers.  Clang however warns about
unknown -Wno-foo by default, unless you pass
-Wno-unknown-warning-option as well:

 $ gcc -Wno-foo test.c
 * nothing, compiles successfuly *

 $ clang -Wno-foo test.c
 warning: unknown warning option '-Wno-foo [-Wunknown-warning-option]

This commit adds -Wunknown-warning-option centrally in gdb_compile, so
that individual testcases don't have to worry about breaking older
Clangs.

IOW, this avoids this problematic scenario:

#1 - A testcase compiles successfully with Clang version X.
#2 - Clang version "X + 1" adds a new warning, enabled by default,
     which breaks the test.
#3 - We add -Wno-newwarning to the testcase, fixing the testcase with
     clang "X + 1".
#4 - Now building the test with Clang version X no longer works, due
     to "unknown warning option".

gdb/testsuite/ChangeLog:
2020-06-24  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_compile): Update intro comment.  If C/C++ with
	Clang, add "-Wno-unknown-warning-option" to the options.
---
 gdb/testsuite/ChangeLog   |  5 +++++
 gdb/testsuite/lib/gdb.exp | 20 +++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 26284dabb25..6f4d99d3902 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-06-24  Pedro Alves  <palves@redhat.com>
+
+	* lib/gdb.exp (gdb_compile): Update intro comment.  If C/C++ with
+	Clang, add "-Wno-unknown-warning-option" to the options.
+
 2020-06-23  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* gdb.xml/tdesc-reload.c: New file.
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 7b243f5fff3..6b4f71be588 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3826,7 +3826,8 @@ set gdb_saved_set_unbuffered_mode_obj ""
 #   - ldflags=flag: Add FLAG to the linker flags.
 #   - incdir=path: Add PATH to the searched include directories.
 #   - libdir=path: Add PATH to the linker searched directories.
-#   - ada, c++, f77: Compile the file as Ada, C++ or Fortran.
+#   - ada, c++, f77, f90, go, rust: Compile the file as Ada, C++,
+#     Fortran 77, Fortran 90, Go or Rust.
 #   - debug: Build with debug information.
 #   - optimize: Build with optimization.
 
@@ -3850,6 +3851,23 @@ proc gdb_compile {source dest type options} {
 	set new_options [universal_compile_options]
     }
 
+    # Some C/C++ testcases unconditionally pass -Wno-foo as additional
+    # options to disable some warning.  That is OK with GCC, because
+    # by design, GCC accepts any -Wno-foo option, even if it doesn't
+    # support -Wfoo.  Clang however warns about unknown -Wno-foo by
+    # default, unless you pass -Wno-unknown-warning-option as well.
+    # We do that here, so that individual testcases don't have to
+    # worry about it.
+    if {[lsearch -exact $options getting_compiler_info] == -1
+	&& [lsearch -exact $options rust] == -1
+	&& [lsearch -exact $options ada] == -1
+	&& [lsearch -exact $options f77] == -1
+	&& [lsearch -exact $options f90] == -1
+	&& [lsearch -exact $options go] == -1
+	&& [test_compiler_info "clang-*"]} {
+	lappend new_options "additional_flags=-Wno-unknown-warning-option"
+    }
+
     # Place (and look for) Fortran `.mod` files in the output
     # directory for this specific test.
     if {[lsearch -exact $options f77] != -1 \

base-commit: a8654e7d784980cb4596f685964200fcc1164c78
-- 
2.14.5


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

* Re: [PATCH] W/ Clang, compile C/C++ testcases with -Wno-unknown-warning-option
  2020-06-24 22:26               ` Pedro Alves
@ 2020-07-02 10:02                 ` Gary Benson
  0 siblings, 0 replies; 11+ messages in thread
From: Gary Benson @ 2020-07-02 10:02 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

Pedro Alves wrote:
> On 6/18/20 5:18 PM, Gary Benson via Gdb-patches wrote:
> > Pedro Alves wrote:
> > > gdb/testsuite/ChangeLog:
> > > 	* lib/gdb.exp (gdb_compile): Update intro comment.  If C/C++
> > > 	with Clang, add "-Wno-unknown-warning-option" to the options.
> > 
> > Oh, thanks, that looks great.  Could you commit it please?
> 
> I've pushed this now, with just a tweak to also list "go".

Thanks Pedro, I was lost in all the special cases in there!

Cheers,
Gary

-- 
Gary Benson - he / him / his
Principal Software Engineer, Red Hat


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

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

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29 13:03 [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison Gary Benson
2020-05-29 18:08 ` Tom Tromey
2020-05-29 18:31   ` Pedro Alves
2020-06-16 12:42     ` Gary Benson
2020-06-16 15:11       ` Pedro Alves
2020-06-17 17:29         ` Gary Benson
2020-06-17 19:53           ` [PATCH] W/ Clang, compile C/C++ testcases with -Wno-unknown-warning-option Pedro Alves
2020-06-18 16:18             ` Gary Benson
2020-06-24 22:26               ` Pedro Alves
2020-07-02 10:02                 ` Gary Benson
2020-06-16 12:38   ` [OB PATCH] Build two gdb.cp testcases with -Wno-unused-comparison 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).