mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-27 03:51:15 +08:00
59497587af
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.
95 lines
2.5 KiB
C
95 lines
2.5 KiB
C
/* Interface to byteswapping functions.
|
|
Copyright (C) 2006-2024 Free Software Foundation, Inc.
|
|
|
|
This file is part of libctf.
|
|
|
|
libctf is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
version.
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; see the file COPYING. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef _CTF_SWAP_H
|
|
#define _CTF_SWAP_H
|
|
|
|
#include "config.h"
|
|
#include <stdint.h>
|
|
#include <assert.h>
|
|
|
|
#ifdef HAVE_BYTESWAP_H
|
|
#include <byteswap.h>
|
|
#endif /* defined(HAVE_BYTESWAP_H) */
|
|
|
|
/* Provide our own versions of the byteswap functions. */
|
|
|
|
#if !HAVE_DECL_BSWAP_16
|
|
static inline uint16_t
|
|
bswap_16 (uint16_t v)
|
|
{
|
|
return ((v >> 8) & 0xff) | ((v & 0xff) << 8);
|
|
}
|
|
#endif /* !HAVE_DECL_BSWAP16 */
|
|
|
|
#if !HAVE_DECL_BSWAP_32
|
|
static inline uint32_t
|
|
bswap_32 (uint32_t v)
|
|
{
|
|
return ( ((v & 0xff000000) >> 24)
|
|
| ((v & 0x00ff0000) >> 8)
|
|
| ((v & 0x0000ff00) << 8)
|
|
| ((v & 0x000000ff) << 24));
|
|
}
|
|
#endif /* !HAVE_DECL_BSWAP32 */
|
|
|
|
#if !HAVE_DECL_BSWAP_64
|
|
static inline uint64_t
|
|
bswap_64 (uint64_t v)
|
|
{
|
|
return ( ((v & 0xff00000000000000ULL) >> 56)
|
|
| ((v & 0x00ff000000000000ULL) >> 40)
|
|
| ((v & 0x0000ff0000000000ULL) >> 24)
|
|
| ((v & 0x000000ff00000000ULL) >> 8)
|
|
| ((v & 0x00000000ff000000ULL) << 8)
|
|
| ((v & 0x0000000000ff0000ULL) << 24)
|
|
| ((v & 0x000000000000ff00ULL) << 40)
|
|
| ((v & 0x00000000000000ffULL) << 56));
|
|
}
|
|
#endif /* !HAVE_DECL_BSWAP64 */
|
|
|
|
/* < 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. */
|
|
|
|
#define swap_thing(x) \
|
|
do \
|
|
{ \
|
|
_Static_assert (sizeof (x) == 1 || (sizeof (x) % 2 == 0 \
|
|
&& sizeof (x) <= 8), \
|
|
"Invalid size, update endianness code"); \
|
|
switch (sizeof (x)) { \
|
|
case 2: x = bswap_16 (x); break; \
|
|
case 4: x = bswap_32 (x); break; \
|
|
case 8: x = bswap_64 (x); break; \
|
|
case 1: /* Nothing needs doing */ \
|
|
break; \
|
|
} \
|
|
} \
|
|
while (0);
|
|
|
|
|
|
#endif /* !defined(_CTF_SWAP_H) */
|