W/ Clang, compile/link C++ test programs with "-x c++"
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 testcases want to compile .c files with a C++ compiler.  So they
pass the "c++" option to gdb_compile.  That works fine with GCC, but
with Clang, it results in:

  gdb compile failed, clang-5.0: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]

and the testcase is skipped with UNTESTED.

A previous patch fixed a case like that in
gdb.compile/compile-cplus.exp, by adding -Wno-deprecated to the build
options.  However, there are other testcases that use the same
pattern, and all fail for the same reason.  For example:

 gdb.base/info-types-c++.exp
 gdb.base/max-depth-c++.exp
 gdb.base/msym-lang.exp
 gdb.base/whatis-ptype-typedefs.exp
 gdb.btrace/rn-dl-bind.exp

Fix this in a central place, within gdb_compile, by passing "-x c++"
to the compiler driver when we're compiling/linking C++.

This revealed that gdb.compile/compile-cplus.exp and
gdb.arch/amd64-entry-value-paramref.exp tests are compiling an
assembly file with the "c++" option, which would now fail to compile,
with the C++ compiler not grokking the assembly, of course.  We just
need to not pass "c++" and all the other related C++ options when
compiling an assembly file.

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

* gdb.arch/amd64-entry-value-paramref.exp: Use
prepare_for_testing_full and don't pass "c++" for the .S file
build spec.
* gdb.compile/compile-cplus.exp: Don't compile $srcfile3 with
$options, since it's an assembly file.  Remove -Wno-deprecated.
* lib/gdb.exp (gdb_compile): Pass "-x c++" explicitly when
compiling C++ programs.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.arch/amd64-entry-value-paramref.exp
gdb/testsuite/gdb.compile/compile-cplus.exp
gdb/testsuite/lib/gdb.exp

index 6f4d99d39023c266377bec4ef6bbea74134ff517..1b77459bce3aa0208b30b8d4a9d73cc15f3fd28a 100644 (file)
@@ -1,3 +1,13 @@
+2020-06-24  Pedro Alves  <palves@redhat.com>
+
+       * gdb.arch/amd64-entry-value-paramref.exp: Use
+       prepare_for_testing_full and don't pass "c++" for the .S file
+       build spec.
+       * gdb.compile/compile-cplus.exp: Don't compile $srcfile3 with
+       $options, since it's an assembly file.  Remove -Wno-deprecated.
+       * lib/gdb.exp (gdb_compile): Pass "-x c++" explicitly when
+       compiling C++ programs.
+
 2020-06-24  Pedro Alves  <palves@redhat.com>
 
        * lib/gdb.exp (gdb_compile): Update intro comment.  If C/C++ with
index be60e2554d70530ccdad955326ddd93225258be9..cbb69f46b816f7f3dc4080e4f9d3745ce92ad7c3 100644 (file)
@@ -20,7 +20,8 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
     return
 }
 
-if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} "c++"] } {
+if { [prepare_for_testing_full "failed to prepare" \
+         [list $testfile "c++" $srcfile {}]] } {
     return -1
 }
 
index 85b2f20a8fad20cf5155789c52c22d96cd22df73..f794e5a143919050d3d12316ba1f9c82cd5e0c46 100644 (file)
@@ -24,11 +24,6 @@ if { [test_compiler_info gcc*] || [test_compiler_info clang*] } {
     lappend options additional_flags=-std=gnu++11
     lappend options c++
 }
-if [test_compiler_info clang*] {
-    # Treating C input as C++ is deprecated in Clang, so
-    # the build will fail without disabling -Wdeprecated.
-    lappend options additional_flags=-Wno-deprecated
-}
 
 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
     verbose "Skipping x86_64 LOC_CONST test."
@@ -37,14 +32,9 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
 
 set srcfilesoptions [list ${srcfile} ${options}]
 if { $srcfile3 != "" } {
-    lappend srcfilesoptions $srcfile3 ${options}
+    lappend srcfilesoptions $srcfile3 {}
 }
 set srcfile4options "nodebug c++"
-if [test_compiler_info clang*] {
-    # Treating C input as C++ is deprecated in Clang, so
-    # the build will fail without disabling -Wdeprecated.
-    set srcfile4options "$srcfile4options additional_flags=-Wno-deprecated"
-}
 lappend srcfilesoptions $srcfile4 $srcfile4options
 if { [eval build_executable_from_specs ${testfile}.exp $testfile {$options} ${srcfilesoptions}] } {
     return -1
index 6b4f71be58822bac0ef87eb938c8fbc2d0c30694..8dbfa7e7a9489c224b9ad1b36140ac4537c45d36 100644 (file)
@@ -3868,6 +3868,14 @@ proc gdb_compile {source dest type options} {
        lappend new_options "additional_flags=-Wno-unknown-warning-option"
     }
 
+    # Treating .c input files as C++ is deprecated in Clang, so
+    # explicitly force C++ language.
+    if { [lsearch -exact $options getting_compiler_info] == -1
+        && [lsearch -exact $options c++] != -1
+        && [test_compiler_info "clang-*"]} {
+       lappend new_options additional_flags=-x\ c++
+    }
+
     # 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.042069 seconds and 4 git commands to generate.