libctf warnings

Seen with every compiler I have if using -fno-inline:
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): 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.
This commit is contained in:
Alan Modra
2024-04-09 08:53:35 +09:30
parent 20bf7711bc
commit 59497587af
5 changed files with 11 additions and 7 deletions

View File

@@ -551,6 +551,10 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
case CTF_K_FLOAT: case CTF_K_FLOAT:
encoding = CTF_FP_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits); encoding = CTF_FP_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits);
break; 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)); memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding));

View File

@@ -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_link_input_t *one_input;
ctf_dict_t *one_fp; ctf_dict_t *one_fp;
ctf_dict_t *parent_fp = NULL; ctf_dict_t *parent_fp = NULL;
uint32_t parent_i; uint32_t parent_i = 0;
ctf_next_t *j = NULL; ctf_next_t *j = NULL;
/* If we are processing CU names, get the real input. All the inputs /* If we are processing CU names, get the real input. All the inputs

View File

@@ -202,17 +202,15 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
} }
ctf_dynhash_remove (linker_known, name); ctf_dynhash_remove (linker_known, name);
}
*unpadsize += sizeof (uint32_t);
(*count)++;
if (!(flags & CTF_SYMTYPETAB_FORCE_INDEXED))
{
if (*max < sym->st_symidx) if (*max < sym->st_symidx)
*max = sym->st_symidx; *max = sym->st_symidx;
} }
else else
(*max)++; (*max)++;
*unpadsize += sizeof (uint32_t);
(*count)++;
} }
if (err != ECTF_NEXT_END) if (err != ECTF_NEXT_END)
{ {

View File

@@ -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_dict_t *ofp = fp;
ctf_id_t otype = type; ctf_id_t otype = type;
const ctf_type_t *tp; const ctf_type_t *tp = NULL;
const ctf_dtdef_t *dtd; const ctf_dtdef_t *dtd;
unsigned char *vlen; unsigned char *vlen;
ssize_t size, increment, vbytes; ssize_t size, increment, vbytes;

View File

@@ -67,8 +67,10 @@ bswap_64 (uint64_t v)
/* < C11? define away static assertions. */ /* < C11? define away static assertions. */
#if !defined (__STDC_VERSION__) || __STDC_VERSION__ < 201112L #if !defined (__STDC_VERSION__) || __STDC_VERSION__ < 201112L
#ifndef _Static_assert
#define _Static_assert(cond, err) #define _Static_assert(cond, err)
#endif #endif
#endif
/* Swap the endianness of something. */ /* Swap the endianness of something. */