[OB PATCH] Fix build errors in with clang in gdb.compile/compile-cplus.c

Gary Benson gbenson@redhat.com
Fri Jun 19 13:49:46 GMT 2020


Pedro Alves wrote:
> On 5/29/20 5:43 PM, Gary Benson via Gdb-patches wrote:
> > Clang fails to compile the file, with the following error:
> >   fatal error: 'iostream' file not found
> > 
> > This prevents the following testcase from executing:
> >   gdb.compile/compile-cplus.exp
> > 
> > The testcase sets additional_flags when building with GCC, which
> > this commit causes to also be set when building with clang.  This
> > makes the testcase fail to build with a different error:
> >   warning: treating 'c' input as 'c++' when in C++ mode, this behavior
> >   is deprecated [-Wdeprecated]
> > so this commit adds -Wno-deprecated in two places to sidestep this.
> > Note that, while allowing the testcase to build, this commit reveals
> > failures when the testsuite is built using clang.
> > 
> > gdb/testsuite/ChangeLog:
> > 
> > 	* gdb.compile/compile-cplus.exp (additional_flags): Also
> > 	set when building with clang.
> > 	(additional_flags, srcfilesoptions): Pass -Wno-deprecated
> > 	when building with clang.
> > ---
> >  gdb/testsuite/ChangeLog                     |  7 +++++++
> >  gdb/testsuite/gdb.compile/compile-cplus.exp | 15 +++++++++++++--
> >  2 files changed, 20 insertions(+), 2 deletions(-)
> > 
> > diff --git a/gdb/testsuite/gdb.compile/compile-cplus.exp b/gdb/testsuite/gdb.compile/compile-cplus.exp
> > index cca5b20..85b2f20 100644
> > --- a/gdb/testsuite/gdb.compile/compile-cplus.exp
> > +++ b/gdb/testsuite/gdb.compile/compile-cplus.exp
> > @@ -19,11 +19,16 @@ standard_testfile .c compile-shlib.c compile-constvar.S compile-nodebug.c
> >  
> >  get_compiler_info
> >  set options {}
> > -if [test_compiler_info gcc*] {
> > +if { [test_compiler_info gcc*] || [test_compiler_info clang*] } {
> >      lappend options additional_flags=-g3
> >      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
> > +}
> 
> I think
> 
>  lappend options "additional_flags=-x c++"
> 
> in the previous "if" would be better.

[i'm replying to this out-of-order]

> Even better would be to tweak gdb_compile or thereabouts to make the
> "c++" option automatically add "-x c++" to the compiler options with
> clang.  That would handle everywhere this could be an issue all at
> once.  WDYT?

I disagree with adding global support for this, for these reasons:

1) It only affects this testcase.

2) This testcase is one big hack, afaict.  It's a copy of (one/some
   of?) the original C-language testcases, with some stuff at the
   start to force the C sources through the C++ compiler, and to force
   GDB to recognise the result as C++. Force force force.

3) Clang is warning that compiling C as C++ is deprecated.  Deprecated,
   as in, the support is there now, but don't count on it being there
   forever.  We should not add global support for testcases to do
   deprecated things.

In terms of fixing this locally:
> I think
> 
>  lappend options "additional_flags=-x c++"
> 
> in the previous "if" would be better.

It doesn't work, one of the sources is assembler.  I tried adding it
to the other sources individually, but I couldn't make that work
either,

a) There's some quoting issue, I had to do:
     lappend options "additional_flags=-x"
     lappend options "additional_flags=c++"
   (I'm assuming there's a better way, but I don't know it)

b) There's $srcfile3, $srcfile4, but I couldn't figure out how to
   apply the additional flags to the first srcfile.

> BTW, it looks like a bug that appending the "c++" option is inside
> the if, rather than outside.

Maybe. I don't know.  I doubt it's ever been run other than with GCC
as the testcase compiler, the testcase is testing GDB using GCC to
compile code for injection after all.

Let me know what to do with this testcase.  How important is it to
not have -Wno-deprecated in there?  I've probably spent close to
three hours on this issue now fwiw :(

Cheers,
Gary

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



More information about the Gdb-patches mailing list