aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2020-09-25 14:29:35 +0100
committerGary Benson <gbenson@redhat.com>2020-09-25 14:29:35 +0100
commit68d654afdfcff840ebb3ae432ed72dca0521d670 (patch)
treeadbc11d735563e1c04d45a93be13566a4d4ead9a
parent5a805384b831e5946cc8dae13a75617cb4b9c080 (diff)
downloadgdb-68d654afdfcff840ebb3ae432ed72dca0521d670.zip
gdb-68d654afdfcff840ebb3ae432ed72dca0521d670.tar.gz
gdb-68d654afdfcff840ebb3ae432ed72dca0521d670.tar.bz2
Fix compilation of .c files as C++ when using Clang
In commit 221db974e653659edb280787af1b3efdd1615083, this patch: 2020-06-24 Pedro Alves <palves@redhat.com> * lib/gdb.exp (gdb_compile): Pass "-x c++" explicitly when compiling C++ programs. attempted to fix problems with testcases that compile .c files with the C++ compiler. They pass the "c++" option to gdb_compile, resulting in the following error when using Clang: gdb compile failed, clang-10: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] This fix did not work for gdb.base/infcall-nested-structs-c++.exp, however: the "-x c++" appeared in the compiler's commandline after the .c file, so the option was not enabled for that file. The previous files fixed all used build_executable_from_specs, which compiles and links in separate steps, using gdb_compile: the compile step passes $type=object to gdb_compile, while the link step passes $type=executable. gdb.base/infcall-nested-structs-c++.exp uses gdb_compile directly instead, and it passes $type=executable to compile and link all in one step. Pedro found that DejaGnu's default_target_compile adds the sources at the end when $type=object, but at the beginning when $type=executable: # This is obscure: we put SOURCES at the end when building an # object, because otherwise, in some situations, libtool will # become confused about the name of the actual source file. if {$type == "object"} { set opts "$add_flags $sources" } else { set opts "$sources $add_flags" } This commit moves the "-x c++" earlier in the compiler's commandline. Unfortunately this then broke the testcase that required the original fix, gdb.compile/compile-cplus.exp: the "-x c++" was being parsed for the linker pass, causing the compiler to attempt to parse the .o files as C++. This commit makes passing "-x c++" conditional on the source being a .c file. gdb/testsuite/ChangeLog: * lib/gdb.exp (gdb_compile): Pass "-x c++" earlier, and only for .c files.
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/lib/gdb.exp5
2 files changed, 8 insertions, 2 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 4184975..a19af88 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-09-25 Gary Benson <gbenson@redhat.com>
+
+ * lib/gdb.exp (gdb_compile): Pass "-x c++" earlier, and only
+ for .c files.
+
2020-09-24 Tom Tromey <tromey@adacore.com>
PR tui/26638:
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 59439f8..6084699 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3944,8 +3944,9 @@ proc gdb_compile {source dest type options} {
# 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++
+ && [string match *.c $source] != 0
+ && [test_compiler_info "clang-*"] } {
+ lappend new_options early_flags=-x\ c++
}
# Place (and look for) Fortran `.mod` files in the output