Re: (reposted) Fix -fprofile-use warnings/errors.

Pedro Alves
2010-11-19T17:46:55Z

On Friday 19 November 2010 16:13:30, Phil Muldoon wrote:
> Phil Muldoon <pmuldoon@redhat.com> writes:
>
> > Phil Muldoon <pmuldoon@redhat.com> writes:
> >
> >> This patch corrects (and in some cases, appeases) compiler warnings
> >> generated through the use of -fprofile-use. We've had a variant patch
> >> for sometime in the Fedora GDB. This updates HEAD.
> >
> > And just as soon as I post the patch I realize some of the profile data
> > was stale. Sorry for the noise, but I will post another (larger) patch
> > very shortly.
>
> Here is an updated patch

Interesting,

$ make CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -mtune=generic -fprofile-use" -j4 -k

only shows these for me:

../../src/gdb/remote-m32r-sdi.c: In function 'm32r_can_use_hw_watchpoint':
../../src/gdb/remote-m32r-sdi.c:1699: note: file /home/pedro/gdb/baseline/build-profile-use/gdb/remote-m32r-sdi.gcda not found, execution counts estimated
cc1: warnings being treated as errors
../../src/gdb/macroexp.c: In function 'expand':
../../src/gdb/macroexp.c:1184: error: 'va_arg_name.len' may be used uninitialized in this function
../../src/gdb/macroexp.c:1184: error: 'va_arg_name.text' may be used uninitialized in this function
make: *** [macroexp.o] Error 1
cc1: warnings being treated as errors
../../src/gdb/remote-m32r-sdi.c: In function 'm32r_open':
../../src/gdb/remote-m32r-sdi.c:276: error: 'val' may be used uninitialized in this function
../../src/gdb/remote-m32r-sdi.c:276: note: 'val' was declared here
../../src/gdb/remote-m32r-sdi.c:276: error: 'val' may be used uninitialized in this function
../../src/gdb/remote-m32r-sdi.c:276: note: 'val' was declared here
make: *** [remote-m32r-sdi.o] Error 1
make: Target `all' not remade because of errors.

(ubuntu 10.4's gcc 4.4.3)

> gdbserver:
>
> 2010-11-19 Phil Muldoon <pmuldoon@redhat.com>
>
> * linux-x86-low.c (ATTR_NOINLINE_NOCLONE): Define.
> (add_insns): Use ATTR_NOLINE_NOCLONE.

Hmm, what's the warning like? (In fact, it's always a good
idea to paste the warnings log being fixed for patches like these.
Makes it oh so much easier to review.)

> diff --git a/gdb/remote-m32r-sdi.c b/gdb/remote-m32r-sdi.c
> index 2b67927..bd06950 100644
> --- a/gdb/remote-m32r-sdi.c
> +++ b/gdb/remote-m32r-sdi.c
> @@ -273,7 +273,7 @@ send_three_arg_cmd (unsigned char cmd, unsigned long arg1, unsigned long arg2,
> static unsigned char
> recv_char_data (void)
> {
> - unsigned char val;
> + unsigned char val = 0; /* GCC -fprofile-use warning. */
>
> recv_data (&val, 1);
> return val;
> diff --git a/gdb/symfile.c b/gdb/symfile.c
> index f1c2941..098962b 100644

I only took a look at this one, but the warning looks
correct to me. When recv_data returns -1, &val is not set.

So, this pacifies the warning,

Index: src/gdb/remote-m32r-sdi.c
===================================================================
--- src.orig/gdb/remote-m32r-sdi.c 2010-10-19 19:54:31.000000000 +0100
+++ src/gdb/remote-m32r-sdi.c 2010-11-19 17:36:06.000000000 +0000
@@ -275,7 +275,9 @@ recv_char_data (void)
{
unsigned char val;

- recv_data (&val, 1);
+ if (recv_data (&val, 1) < 0)
+ return 0;
+
return val;
}

but in wrapper functions that don't have an error
return, we usually throw an error instead of returning
a garbage value (0). It may be better in this case,
it may not.

In any case, I didn't look at the other cases, but
I'd be better if we knew we were silencing real bogus warnings,
instead of blindingly shutting them up, and papering
over bugs. Can you clarify whether you investigated
the warnings?

--
Pedro Alves