gdb fails to compile with GCC 4.4.7 (was: [PATCH V4 5/9] New probe type: DTrace USDT probes.)

Message ID 20150327134252.GD13867@adacore.com
State New, archived
Headers

Commit Message

Joel Brobecker March 27, 2015, 1:42 p.m. UTC
  > I think this patch (commit 429e1e811b400f07b5a514ea6b8a70b28e2d7ee9) causes
> gdb's compilation to fail with GCC 4.4.7 (RHEL 6 system compiler) as follows;
> it does work with GCC 5.
> 
> cc1: warnings being treated as errors
> ../../gdb/dtrace-probe.c: In function ‘dtrace_process_dof_probe’:
> ../../gdb/dtrace-probe.c:416: error: ‘expr’ may be used uninitialized in this function
> make[2]: *** [dtrace-probe.o] Error 1
> 
> 
> I think that looks spurious as the code looks fine (i.e. GCC is overzaelous), still,
> a "= NULL" should harm.

Would you mind checking that the attached patch fixes the problem?

gdb/ChangeLog:

        * dtrace-probe.c (dtrace_process_dof_probe): Initialize expr to NULL.

Tested on x86_64-linux by rebuilding GDB.

Thank you,
  

Comments

Tobias Burnus March 27, 2015, 3:17 p.m. UTC | #1
On Fri, Mar 27, 2015 at 06:42:52AM -0700, Joel Brobecker wrote:
> > I think that looks spurious as the code looks fine (i.e. GCC is overzaelous), still,
> > a "= NULL" should harm.
> 
> Would you mind checking that the attached patch fixes the problem?

Yes, it now also compiles with GCC 4.4. Thanks for the fix!

Tobias

>         * dtrace-probe.c (dtrace_process_dof_probe): Initialize expr to NULL.
> ---
>  gdb/dtrace-probe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
> index ff7ce7d..3f2548d 100644
> --- a/gdb/dtrace-probe.c
> +++ b/gdb/dtrace-probe.c
> @@ -413,7 +413,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
>        for (j = 0; j < ret->probe_argc; j++)
>  	{
>  	  struct dtrace_probe_arg arg;
> -	  struct expression *expr;
> +	  struct expression *expr = NULL;
>  
>  	  /* Set arg.expr to ensure all fields in expr are initialized and
>  	     the compiler will not warn when arg is used.  */
> -- 
> 1.9.1
>
  
Joel Brobecker March 27, 2015, 3:27 p.m. UTC | #2
> > Would you mind checking that the attached patch fixes the problem?
> 
> Yes, it now also compiles with GCC 4.4. Thanks for the fix!
> 
> Tobias
> 
> >         * dtrace-probe.c (dtrace_process_dof_probe): Initialize expr to NULL.

Excellent, thanks for reporting the problem and checking the fix
for me. Patch is now in.
  
H.J. Lu March 27, 2015, 4:58 p.m. UTC | #3
On Fri, Mar 27, 2015 at 8:27 AM, Joel Brobecker <brobecker@adacore.com> wrote:
>> > Would you mind checking that the attached patch fixes the problem?
>>
>> Yes, it now also compiles with GCC 4.4. Thanks for the fix!
>>
>> Tobias
>>
>> >         * dtrace-probe.c (dtrace_process_dof_probe): Initialize expr to NULL.
>
> Excellent, thanks for reporting the problem and checking the fix
> for me. Patch is now in.

FWIW, there are other similar places in binutils-gdb tree:

https://sourceware.org/ml/binutils/2015-03/msg00368.html

I suggested a macro, like

#define SILENCE_UNIITITALIZED_WARNING(var) ....

and do

struct bfd_link_hash_entry SILENCE_UNIITITALIZED_WARNING (ehdr_start_save);
  

Patch

From 9b1d494cfb04c4d05252af84545f060bd67bcb87 Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Fri, 27 Mar 2015 06:37:34 -0700
Subject: [PATCH] Initialize EXPR in dtrace-probe::dtrace_process_dof_probe
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

GCC 4.4.7 generates the following warning:

 | cc1: warnings being treated as errors
 | dtrace-probe.c: In function ‘dtrace_process_dof_probe’:
 | dtrace-probe.c:416: error: ‘expr’ may be used uninitialized in this function
 | make[2]: *** [dtrace-probe.o] Error 1

Later versions (GCC 5) do a better job and don't generate the warning,
but it does not hurt to pre-initialize "expr" to NULL.

gdb/ChangeLog:

        * dtrace-probe.c (dtrace_process_dof_probe): Initialize expr to NULL.
---
 gdb/dtrace-probe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
index ff7ce7d..3f2548d 100644
--- a/gdb/dtrace-probe.c
+++ b/gdb/dtrace-probe.c
@@ -413,7 +413,7 @@  dtrace_process_dof_probe (struct objfile *objfile,
       for (j = 0; j < ret->probe_argc; j++)
 	{
 	  struct dtrace_probe_arg arg;
-	  struct expression *expr;
+	  struct expression *expr = NULL;
 
 	  /* Set arg.expr to ensure all fields in expr are initialized and
 	     the compiler will not warn when arg is used.  */
-- 
1.9.1