diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index be14e5a433a..330a5eb79ee 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-11-02 Gary Benson + + * lib/gdb.exp (gdb_compile): Inhibit passing "-x c++" + for .c files compiled as C++ with Clang if any shared + libraries are specified. + 2020-11-02 Gary Benson * lib/attributes.h: New header. diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 003bd3069ec..6c98ae0729b 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -3960,9 +3960,20 @@ proc gdb_compile {source dest type options} { # explicitly force C++ language. if { [lsearch -exact $options getting_compiler_info] == -1 && [lsearch -exact $options c++] != -1 - && [string match *.c $source] != 0 - && [test_compiler_info "clang-*"] } { - lappend new_options early_flags=-x\ c++ + && [string match *.c $source] != 0 } { + + # gdb_compile cannot handle this combination of options, the + # result is a command like "clang -x c++ foo.c bar.so -o baz" + # which tells Clang to treat bar.so as C++. The solution is + # to call gdb_compile twice--once to compile, once to link-- + # either directly, or via build_executable_from_specs. + if { [lsearch $options shlib=*] != -1 } { + error "incompatible gdb_compile options" + } + + if {[test_compiler_info "clang-*"]} { + lappend new_options early_flags=-x\ c++ + } } # Place (and look for) Fortran `.mod` files in the output