W/ Clang, compile C/C++ testcases with -Wno-unknown-warning-option
authorPedro Alves <palves@redhat.com>
Wed, 24 Jun 2020 22:18:19 +0000 (23:18 +0100)
committerPedro Alves <palves@redhat.com>
Wed, 24 Jun 2020 22:18:19 +0000 (23:18 +0100)
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
gdb/testsuite/lib/gdb.exp

index 26284dabb2507b8dbfd4860c95de74e51ef078ae..6f4d99d39023c266377bec4ef6bbea74134ff517 100644 (file)
@@ -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.
index 7b243f5fff3c7f1a6a5c72ab6aa7e5c4f6c38f98..6b4f71be58822bac0ef87eb938c8fbc2d0c30694 100644 (file)
@@ -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 \
This page took 0.045823 seconds and 4 git commands to generate.