public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* libctf warnings
@ 2024-04-09  1:59 Alan Modra
  2024-04-09 19:07 ` Nick Alcock
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2024-04-09  1:59 UTC (permalink / raw)
  To: binutils; +Cc: Nick Alcock

Seen with every compiler I have:
home/alan/src/binutils-gdb/libctf/ctf-create.c: In function ‘ctf_add_encoded’:
/home/alan/src/binutils-gdb/libctf/ctf-create.c:555:3: warning: ‘encoding’ may be used uninitialized [-Wmaybe-uninitialized]
  555 |   memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding));

Seen with gcc-4.9 and probably others at lower optimisation levels:
home/alan/src/binutils-gdb/libctf/ctf-serialize.c: In function 'symtypetab_density':
/home/alan/src/binutils-gdb/libctf/ctf-serialize.c:211:18: warning: 'sym' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if (*max < sym->st_symidx)

Seen with gcc-4.5 and probably others at lower optimisation levels:
/home/alan/src/binutils-gdb/libctf/ctf-types.c:1649:21: warning: 'tp' may be used uninitialized in this function
/home/alan/src/binutils-gdb/libctf/ctf-link.c:765:16: warning: 'parent_i' may be used uninitialized in this function

Also with gcc-4.5:
In file included from /home/alan/src/binutils-gdb/libctf/ctf-endian.h:25:0,
                 from /home/alan/src/binutils-gdb/libctf/ctf-archive.c:24:
/home/alan/src/binutils-gdb/libctf/swap.h:70:0: warning: "_Static_assert" redefined
/usr/include/sys/cdefs.h:568:0: note: this is the location of the previous definition

	* swap.h (_Static_assert): Undef before defining.
	* ctf-serialize.c (symtypetab_density): Merge two
	CTF_SYMTYPETAB_FORCE_INDEXED blocks.
	* ctf-create.c (ctf_add_encoded): Avoid "encoding" may be used
	uninitialized warning.
	* ctf-link.c (ctf_link_deduplicating_open_inputs): Avoid
	"parent_i" may be used uninitialized warning.
	* ctf-types.c (ctf_type_rvisit): Avoid "tp" may be used
	uninitialized warning.

I'll apply this in a few days unless Nick objects.

diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index d0255e5ba7f..99ff4882fd9 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -551,6 +551,10 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
     case CTF_K_FLOAT:
       encoding = CTF_FP_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits);
       break;
+    default:
+      /* ctf_assert is opaque to compilers.  This dead code avoids a
+	 warning about "encoding" being used uninitialized.  */
+      return CTF_ERR;
     }
   memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding));
 
diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
index d5433b9d9bd..360bc1a0e63 100644
--- a/libctf/ctf-link.c
+++ b/libctf/ctf-link.c
@@ -762,7 +762,7 @@ ctf_link_deduplicating_open_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
       ctf_link_input_t *one_input;
       ctf_dict_t *one_fp;
       ctf_dict_t *parent_fp = NULL;
-      uint32_t parent_i;
+      uint32_t parent_i = 0;
       ctf_next_t *j = NULL;
 
       /* If we are processing CU names, get the real input.  All the inputs
diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
index 8645f32ab20..11cbe75601e 100644
--- a/libctf/ctf-serialize.c
+++ b/libctf/ctf-serialize.c
@@ -202,17 +202,15 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
 	    }
 
 	  ctf_dynhash_remove (linker_known, name);
-	}
-      *unpadsize += sizeof (uint32_t);
-      (*count)++;
 
-      if (!(flags & CTF_SYMTYPETAB_FORCE_INDEXED))
-	{
 	  if (*max < sym->st_symidx)
 	    *max = sym->st_symidx;
 	}
       else
 	(*max)++;
+
+      *unpadsize += sizeof (uint32_t);
+      (*count)++;
     }
   if (err != ECTF_NEXT_END)
     {
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index 6dc723d61ea..0eaafa13619 100644
--- a/libctf/ctf-types.c
+++ b/libctf/ctf-types.c
@@ -1646,7 +1646,7 @@ ctf_type_rvisit (ctf_dict_t *fp, ctf_id_t type, ctf_visit_f *func,
 {
   ctf_dict_t *ofp = fp;
   ctf_id_t otype = type;
-  const ctf_type_t *tp;
+  const ctf_type_t *tp = NULL;
   const ctf_dtdef_t *dtd;
   unsigned char *vlen;
   ssize_t size, increment, vbytes;
diff --git a/libctf/swap.h b/libctf/swap.h
index d004dc14348..2dd20a27390 100644
--- a/libctf/swap.h
+++ b/libctf/swap.h
@@ -67,6 +67,7 @@ bswap_64 (uint64_t v)
 /* < C11? define away static assertions.  */
 
 #if !defined (__STDC_VERSION__) || __STDC_VERSION__ < 201112L
+#undef _Static_assert
 #define _Static_assert(cond, err)
 #endif
 

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: libctf warnings
  2024-04-09  1:59 libctf warnings Alan Modra
@ 2024-04-09 19:07 ` Nick Alcock
  2024-04-10  4:48   ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Alcock @ 2024-04-09 19:07 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils, Nick Alcock

On 9 Apr 2024, Alan Modra said:

> Seen with every compiler I have:
> home/alan/src/binutils-gdb/libctf/ctf-create.c: In function ‘ctf_add_encoded’:
> /home/alan/src/binutils-gdb/libctf/ctf-create.c:555:3: warning: ‘encoding’ may be used uninitialized [-Wmaybe-uninitialized]
>   555 |   memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding));

Never seen this one. Does it apply to prehistoric compilers only?

> Seen with gcc-4.9 and probably others at lower optimisation levels:
> home/alan/src/binutils-gdb/libctf/ctf-serialize.c: In function 'symtypetab_density':
> /home/alan/src/binutils-gdb/libctf/ctf-serialize.c:211:18: warning: 'sym' may be used uninitialized in this function [-Wmaybe-uninitialized]
>     if (*max < sym->st_symidx)

I'd like to fix this warning, but your fix is broken :( see below.

> Seen with gcc-4.5 and probably others at lower optimisation levels:
> /home/alan/src/binutils-gdb/libctf/ctf-types.c:1649:21: warning: 'tp' may be used uninitialized in this function
> /home/alan/src/binutils-gdb/libctf/ctf-link.c:765:16: warning: 'parent_i' may be used uninitialized in this function

Do we care about compilers that old? I know I never test with them. GCC
4.6 was released *ten years ago*. I'd be inclined to just ignore
all warnings on anything of remotely that vintage.

> Also with gcc-4.5:
> In file included from /home/alan/src/binutils-gdb/libctf/ctf-endian.h:25:0,
>                  from /home/alan/src/binutils-gdb/libctf/ctf-archive.c:24:
> /home/alan/src/binutils-gdb/libctf/swap.h:70:0: warning: "_Static_assert" redefined
> /usr/include/sys/cdefs.h:568:0: note: this is the location of the previous definition
>
> 	* swap.h (_Static_assert): Undef before defining.

Doesn't this break _Static_assert() if the compiler actually provides
it? I'd rather not do that.

> 	* ctf-create.c (ctf_add_encoded): Avoid "encoding" may be used
> 	uninitialized warning.

... hm, the warning is definitely an fp: ack. (Does this only happen
with really old GCCs?)

> 	* ctf-link.c (ctf_link_deduplicating_open_inputs): Avoid
> 	"parent_i" may be used uninitialized warning.
> 	* ctf-types.c (ctf_type_rvisit): Avoid "tp" may be used
> 	uninitialized warning.
>
> I'll apply this in a few days unless Nick objects.

*waves objection flag* though honestly the only bit that's really
objectionable is the bit that's actually broken, below (the rest is just
me wondering why on earth anyone would care about warnings seen only
with decade-old compilers).

> diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
> index d0255e5ba7f..99ff4882fd9 100644
> --- a/libctf/ctf-create.c
> +++ b/libctf/ctf-create.c
> @@ -551,6 +551,10 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
>      case CTF_K_FLOAT:
>        encoding = CTF_FP_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits);
>        break;
> +    default:
> +      /* ctf_assert is opaque to compilers.  This dead code avoids a
> +	 warning about "encoding" being used uninitialized.  */

Hmm. Do you know of any way to make it *less* opaque? :/

> diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
> index d5433b9d9bd..360bc1a0e63 100644
> --- a/libctf/ctf-link.c
> +++ b/libctf/ctf-link.c
> @@ -762,7 +762,7 @@ ctf_link_deduplicating_open_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
>        ctf_link_input_t *one_input;
>        ctf_dict_t *one_fp;
>        ctf_dict_t *parent_fp = NULL;
> -      uint32_t parent_i;
> +      uint32_t parent_i = 0;
>        ctf_next_t *j = NULL;
>        /* If we are processing CU names, get the real input.  All the inputs

Again, if this is only seen with GCC 4.5, I'm tempted to just ignore
warnings from a compiler this prehistoric.

> diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
> index 8645f32ab20..11cbe75601e 100644
> --- a/libctf/ctf-serialize.c
> +++ b/libctf/ctf-serialize.c
> @@ -202,17 +202,15 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
>  	    }
>  
>  	  ctf_dynhash_remove (linker_known, name);
> -	}
> -      *unpadsize += sizeof (uint32_t);
> -      (*count)++;
>  
> -      if (!(flags & CTF_SYMTYPETAB_FORCE_INDEXED))
> -	{
>  	  if (*max < sym->st_symidx)
>  	    *max = sym->st_symidx;
>  	}
>        else
>  	(*max)++;
> +
> +      *unpadsize += sizeof (uint32_t);
> +      (*count)++;

I think this is a change in semantics. (That (*max++) branch is no
longer executed when sym->st_type != STT_FUNC, whether or not (flags &
CTF_SYMTYPETAB_EMIT_FUNCTION) is turned on.

I think just initializing sym to NULL to quiet the warning would be
safer.

> diff --git a/libctf/swap.h b/libctf/swap.h
> index d004dc14348..2dd20a27390 100644
> --- a/libctf/swap.h
> +++ b/libctf/swap.h
> @@ -67,6 +67,7 @@ bswap_64 (uint64_t v)
>  /* < C11? define away static assertions.  */
>  
>  #if !defined (__STDC_VERSION__) || __STDC_VERSION__ < 201112L
> +#undef _Static_assert
>  #define _Static_assert(cond, err)
>  #endif

I do wish there was some way to say 'use the compiler's _Static_assert'
if available', but there's no requirement it's a macro...

-- 
NULL && (void)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: libctf warnings
  2024-04-09 19:07 ` Nick Alcock
@ 2024-04-10  4:48   ` Alan Modra
  2024-04-10 14:23     ` Nick Alcock
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2024-04-10  4:48 UTC (permalink / raw)
  To: Nick Alcock; +Cc: binutils

On Tue, Apr 09, 2024 at 08:07:57PM +0100, Nick Alcock wrote:
> On 9 Apr 2024, Alan Modra said:
> 
> > Seen with every compiler I have:
> > home/alan/src/binutils-gdb/libctf/ctf-create.c: In function ‘ctf_add_encoded’:
> > /home/alan/src/binutils-gdb/libctf/ctf-create.c:555:3: warning: ‘encoding’ may be used uninitialized [-Wmaybe-uninitialized]
> >   555 |   memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding));
> 
> Never seen this one. Does it apply to prehistoric compilers only?

No, but I neglected to mention this was bulding with -O1 -fno-inlines.
To be honest, I'd forgotten that was the way I was building..
(-O1 -fno-inlines can help quite a bit when debugging.)

> *waves objection flag* though honestly the only bit that's really

Heh.

> objectionable is the bit that's actually broken, below (the rest is just
> me wondering why on earth anyone would care about warnings seen only
> with decade-old compilers).

Because people build binutils on older systems with decades-old
compilers.

> 
> > diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
> > index d0255e5ba7f..99ff4882fd9 100644
> > --- a/libctf/ctf-create.c
> > +++ b/libctf/ctf-create.c
> > @@ -551,6 +551,10 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
> >      case CTF_K_FLOAT:
> >        encoding = CTF_FP_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits);
> >        break;
> > +    default:
> > +      /* ctf_assert is opaque to compilers.  This dead code avoids a
> > +	 warning about "encoding" being used uninitialized.  */
> 
> Hmm. Do you know of any way to make it *less* opaque? :/

Um, my comment is wrong.  ctf_assert is only opague with -fno-inlines.
I'd forgotten I was using that option.  Sorry.

> > diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
> > index d5433b9d9bd..360bc1a0e63 100644
> > --- a/libctf/ctf-link.c
> > +++ b/libctf/ctf-link.c
> > @@ -762,7 +762,7 @@ ctf_link_deduplicating_open_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
> >        ctf_link_input_t *one_input;
> >        ctf_dict_t *one_fp;
> >        ctf_dict_t *parent_fp = NULL;
> > -      uint32_t parent_i;
> > +      uint32_t parent_i = 0;
> >        ctf_next_t *j = NULL;
> >        /* If we are processing CU names, get the real input.  All the inputs
> 
> Again, if this is only seen with GCC 4.5, I'm tempted to just ignore
> warnings from a compiler this prehistoric.

It also might be seen with newer compilers and some optimisation
options other than plain -O2.

> > diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
> > index 8645f32ab20..11cbe75601e 100644
> > --- a/libctf/ctf-serialize.c
> > +++ b/libctf/ctf-serialize.c
> > @@ -202,17 +202,15 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
> >  	    }
> >  
> >  	  ctf_dynhash_remove (linker_known, name);
> > -	}
> > -      *unpadsize += sizeof (uint32_t);
> > -      (*count)++;
> >  
> > -      if (!(flags & CTF_SYMTYPETAB_FORCE_INDEXED))
> > -	{
> >  	  if (*max < sym->st_symidx)
> >  	    *max = sym->st_symidx;
> >  	}
> >        else
> >  	(*max)++;
> > +
> > +      *unpadsize += sizeof (uint32_t);
> > +      (*count)++;
> 
> I think this is a change in semantics. (That (*max++) branch is no
> longer executed when sym->st_type != STT_FUNC, whether or not (flags &
> CTF_SYMTYPETAB_EMIT_FUNCTION) is turned on.

I think you may be reading the patch wrong.  The "else" now belongs to
the earlier "if (!(flags & CTF_SYMTYPETAB_FORCE_INDEXED))".  The only
semantic change is that *max now changes before *unpadsize and *count.

> 
> I think just initializing sym to NULL to quiet the warning would be
> safer.
> 
> > diff --git a/libctf/swap.h b/libctf/swap.h
> > index d004dc14348..2dd20a27390 100644
> > --- a/libctf/swap.h
> > +++ b/libctf/swap.h
> > @@ -67,6 +67,7 @@ bswap_64 (uint64_t v)
> >  /* < C11? define away static assertions.  */
> >  
> >  #if !defined (__STDC_VERSION__) || __STDC_VERSION__ < 201112L
> > +#undef _Static_assert
> >  #define _Static_assert(cond, err)
> >  #endif
> 
> I do wish there was some way to say 'use the compiler's _Static_assert'
> if available', but there's no requirement it's a macro...

Right, but in the case I hit, it *is* a macro.  Would you prefer
#ifndef instead?

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: libctf warnings
  2024-04-10  4:48   ` Alan Modra
@ 2024-04-10 14:23     ` Nick Alcock
  2024-04-16 23:56       ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Alcock @ 2024-04-10 14:23 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On 10 Apr 2024, Alan Modra spake thusly:

> On Tue, Apr 09, 2024 at 08:07:57PM +0100, Nick Alcock wrote:
>> On 9 Apr 2024, Alan Modra said:
>> 
>> > Seen with every compiler I have:
>> > home/alan/src/binutils-gdb/libctf/ctf-create.c: In function ‘ctf_add_encoded’:
>> > /home/alan/src/binutils-gdb/libctf/ctf-create.c:555:3: warning: ‘encoding’ may be used uninitialized [-Wmaybe-uninitialized]
>> >   555 |   memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding));
>> 
>> Never seen this one. Does it apply to prehistoric compilers only?
>
> No, but I neglected to mention this was bulding with -O1 -fno-inlines.
> To be honest, I'd forgotten that was the way I was building..
> (-O1 -fno-inlines can help quite a bit when debugging.)

Oh, maybe I should add that to my test vector :) if this happens on
non-prehistoric compilers, by all means fix it!

>> objectionable is the bit that's actually broken, below (the rest is just
>> me wondering why on earth anyone would care about warnings seen only
>> with decade-old compilers).
>
> Because people build binutils on older systems with decades-old
> compilers.

Yes, but do we care about *warnings* there, particularly when they're
fps, as opposed to actual problems? As I see it the purpose of a warning
is to highlight real problems: if the warning is false, and only happens
on ancient compilers, then quiescing it is only worthwhile if it doesn't
increase the risk of missing real problems in future. (But if it happens
on newer compilers too, that's different.)

>> > diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
>> > index d0255e5ba7f..99ff4882fd9 100644
>> > --- a/libctf/ctf-create.c
>> > +++ b/libctf/ctf-create.c
>> > @@ -551,6 +551,10 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
>> >      case CTF_K_FLOAT:
>> >        encoding = CTF_FP_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits);
>> >        break;
>> > +    default:
>> > +      /* ctf_assert is opaque to compilers.  This dead code avoids a
>> > +	 warning about "encoding" being used uninitialized.  */
>> 
>> Hmm. Do you know of any way to make it *less* opaque? :/
>
> Um, my comment is wrong.  ctf_assert is only opague with -fno-inlines.
> I'd forgotten I was using that option.  Sorry.

Hm. Is there some way to *detect* -fno-inlines? Because I'm quite happy
to define away ctf_assert() to nothing when that flag is in use, if that
would help. (Alas, I can't immediately see a useful predefined
preprocessor flag.)

>> > diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
>> > index d5433b9d9bd..360bc1a0e63 100644
>> > --- a/libctf/ctf-link.c
>> > +++ b/libctf/ctf-link.c
>> > @@ -762,7 +762,7 @@ ctf_link_deduplicating_open_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
>> >        ctf_link_input_t *one_input;
>> >        ctf_dict_t *one_fp;
>> >        ctf_dict_t *parent_fp = NULL;
>> > -      uint32_t parent_i;
>> > +      uint32_t parent_i = 0;
>> >        ctf_next_t *j = NULL;
>> >        /* If we are processing CU names, get the real input.  All the inputs
>> 
>> Again, if this is only seen with GCC 4.5, I'm tempted to just ignore
>> warnings from a compiler this prehistoric.
>
> It also might be seen with newer compilers and some optimisation
> options other than plain -O2.

That's OK then, initialize away.

>> > diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
>> > index 8645f32ab20..11cbe75601e 100644
>> > --- a/libctf/ctf-serialize.c
>> > +++ b/libctf/ctf-serialize.c
>> > @@ -202,17 +202,15 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
>> >  	    }
>> >  
>> >  	  ctf_dynhash_remove (linker_known, name);
>> > -	}
>> > -      *unpadsize += sizeof (uint32_t);
>> > -      (*count)++;
>> >  
>> > -      if (!(flags & CTF_SYMTYPETAB_FORCE_INDEXED))
>> > -	{
>> >  	  if (*max < sym->st_symidx)
>> >  	    *max = sym->st_symidx;
>> >  	}
>> >        else
>> >  	(*max)++;
>> > +
>> > +      *unpadsize += sizeof (uint32_t);
>> > +      (*count)++;
>> 
>> I think this is a change in semantics. (That (*max++) branch is no
>> longer executed when sym->st_type != STT_FUNC, whether or not (flags &
>> CTF_SYMTYPETAB_EMIT_FUNCTION) is turned on.
>
> I think you may be reading the patch wrong.  The "else" now belongs to
> the earlier "if (!(flags & CTF_SYMTYPETAB_FORCE_INDEXED))".  The only
> semantic change is that *max now changes before *unpadsize and *count.

If the only difference is ordering, go for it (on re-examination it
looks like you're right). Tab-based indentation makes this very hard to
read :(

>> >  /* < C11? define away static assertions.  */
>> >  
>> >  #if !defined (__STDC_VERSION__) || __STDC_VERSION__ < 201112L
>> > +#undef _Static_assert
>> >  #define _Static_assert(cond, err)
>> >  #endif
>> 
>> I do wish there was some way to say 'use the compiler's _Static_assert'
>> if available', but there's no requirement it's a macro...
>
> Right, but in the case I hit, it *is* a macro.  Would you prefer
> #ifndef instead?

That sounds like a good idea.

-- 
NULL && (void)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: libctf warnings
  2024-04-10 14:23     ` Nick Alcock
@ 2024-04-16 23:56       ` Alan Modra
  2024-04-17 20:19         ` Nick Alcock
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2024-04-16 23:56 UTC (permalink / raw)
  To: Nick Alcock; +Cc: binutils

Applied.

	* swap.h (_Static_assert): Don't define if already defined.
	* ctf-serialize.c (symtypetab_density): Merge two
	CTF_SYMTYPETAB_FORCE_INDEXED blocks.
	* ctf-create.c (ctf_add_encoded): Avoid "encoding" may be used
	uninitialized warning.
	* ctf-link.c (ctf_link_deduplicating_open_inputs): Avoid
	"parent_i" may be used uninitialized warning.
	* ctf-types.c (ctf_type_rvisit): Avoid "tp" may be used
	uninitialized warning.

diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index d0255e5ba7f..21fbad714a9 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -551,6 +551,10 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
     case CTF_K_FLOAT:
       encoding = CTF_FP_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits);
       break;
+    default:
+      /* ctf_assert is opaque with -fno-inline.  This dead code avoids
+	 a warning about "encoding" being used uninitialized.  */
+      return CTF_ERR;
     }
   memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding));
 
diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
index d5433b9d9bd..360bc1a0e63 100644
--- a/libctf/ctf-link.c
+++ b/libctf/ctf-link.c
@@ -762,7 +762,7 @@ ctf_link_deduplicating_open_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
       ctf_link_input_t *one_input;
       ctf_dict_t *one_fp;
       ctf_dict_t *parent_fp = NULL;
-      uint32_t parent_i;
+      uint32_t parent_i = 0;
       ctf_next_t *j = NULL;
 
       /* If we are processing CU names, get the real input.  All the inputs
diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
index 8645f32ab20..11cbe75601e 100644
--- a/libctf/ctf-serialize.c
+++ b/libctf/ctf-serialize.c
@@ -202,17 +202,15 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
 	    }
 
 	  ctf_dynhash_remove (linker_known, name);
-	}
-      *unpadsize += sizeof (uint32_t);
-      (*count)++;
 
-      if (!(flags & CTF_SYMTYPETAB_FORCE_INDEXED))
-	{
 	  if (*max < sym->st_symidx)
 	    *max = sym->st_symidx;
 	}
       else
 	(*max)++;
+
+      *unpadsize += sizeof (uint32_t);
+      (*count)++;
     }
   if (err != ECTF_NEXT_END)
     {
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index 6dc723d61ea..0eaafa13619 100644
--- a/libctf/ctf-types.c
+++ b/libctf/ctf-types.c
@@ -1646,7 +1646,7 @@ ctf_type_rvisit (ctf_dict_t *fp, ctf_id_t type, ctf_visit_f *func,
 {
   ctf_dict_t *ofp = fp;
   ctf_id_t otype = type;
-  const ctf_type_t *tp;
+  const ctf_type_t *tp = NULL;
   const ctf_dtdef_t *dtd;
   unsigned char *vlen;
   ssize_t size, increment, vbytes;
diff --git a/libctf/swap.h b/libctf/swap.h
index d004dc14348..2e2b6973531 100644
--- a/libctf/swap.h
+++ b/libctf/swap.h
@@ -67,8 +67,10 @@ bswap_64 (uint64_t v)
 /* < C11? define away static assertions.  */
 
 #if !defined (__STDC_VERSION__) || __STDC_VERSION__ < 201112L
+#ifndef _Static_assert
 #define _Static_assert(cond, err)
 #endif
+#endif
 
 /* Swap the endianness of something.  */
 

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: libctf warnings
  2024-04-16 23:56       ` Alan Modra
@ 2024-04-17 20:19         ` Nick Alcock
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Alcock @ 2024-04-17 20:19 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On 17 Apr 2024, Alan Modra told this:

> Applied.

Thank you! I just threw it past all my routine tests as part of the
testing of the series I'm about to post: all passed happily.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-17 20:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09  1:59 libctf warnings Alan Modra
2024-04-09 19:07 ` Nick Alcock
2024-04-10  4:48   ` Alan Modra
2024-04-10 14:23     ` Nick Alcock
2024-04-16 23:56       ` Alan Modra
2024-04-17 20:19         ` Nick Alcock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).