From 3912a8db685f5e19a883d02d66900cdf10a200f0 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 18 Apr 2021 21:01:00 -0400 Subject: [PATCH] sim: cr16: fix build warnings The printf fix is obvious enough, but the hash one is a real bug: cr16/interp.c: In function 'sim_open': cr16/interp.c:560:17: error: 'h' may be used uninitialized in this function [-Werror=maybe-uninitialized] 560 | h = h->next; | ~~^~~~~~~~~ It happens to not cause a problem currently because the first entry in the generated table that this loop operates matches a codepath where h is initialized. Then when later entries don't match, the previous value is pointing at the end of a valid hash table already, and the rest of the code does nothing. With this tidied up, we can delete the SIM_AC_OPTION_WARNINGS(no) call to get the default common behavior where -Werror is enabled. --- sim/cr16/ChangeLog | 7 +++++++ sim/cr16/configure | 5 ++++- sim/cr16/configure.ac | 1 - sim/cr16/interp.c | 5 +++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sim/cr16/ChangeLog b/sim/cr16/ChangeLog index 274d89fdb7d..38cfe221169 100644 --- a/sim/cr16/ChangeLog +++ b/sim/cr16/ChangeLog @@ -1,3 +1,10 @@ +2021-04-18 Mike Frysinger + + * interp.c (sim_open): Use PRIx64 to match mcode type. Skip the + current simop when it doesn't match a known hash table. + * configure.ac (SIM_AC_OPTION_WARNINGS): Delete call. + * configure: Regenerate. + 2021-04-12 Mike Frysinger * interp.c (sim_open): Delete 3rd arg to sim_cpu_alloc_all. diff --git a/sim/cr16/configure b/sim/cr16/configure index 16b0d7237a8..99e21fc4b51 100755 --- a/sim/cr16/configure +++ b/sim/cr16/configure @@ -11978,6 +11978,7 @@ fi fi + # Check whether --enable-werror was given. if test "${enable_werror+set}" = set; then : enableval=$enable_werror; case "${enableval}" in @@ -11994,6 +11995,9 @@ if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then fi WERROR_CFLAGS="" + if test "${ERROR_ON_WARNING}" = yes ; then + WERROR_CFLAGS="-Werror" + fi build_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith \ -Wpointer-sign \ @@ -12075,7 +12079,6 @@ $as_echo "${WARN_CFLAGS} ${WERROR_CFLAGS}" >&6; } fi - cgen_breaks="" if grep CGEN_MAINT $srcdir/Makefile.in >/dev/null; then cgen_breaks="break cgen_rtx_error"; diff --git a/sim/cr16/configure.ac b/sim/cr16/configure.ac index 582779750d8..f4dc9c1314d 100644 --- a/sim/cr16/configure.ac +++ b/sim/cr16/configure.ac @@ -6,6 +6,5 @@ SIM_AC_COMMON SIM_AC_OPTION_ENDIAN(LITTLE) SIM_AC_OPTION_ALIGNMENT(NONSTRICT_ALIGNMENT) -SIM_AC_OPTION_WARNINGS(no) SIM_AC_OUTPUT diff --git a/sim/cr16/interp.c b/sim/cr16/interp.c index f0e0f76224a..46150069a38 100644 --- a/sim/cr16/interp.c +++ b/sim/cr16/interp.c @@ -330,7 +330,7 @@ do_run (SIM_DESC sd, SIM_CPU *cpu, uint64 mcode) #ifdef DEBUG if ((cr16_debug & DEBUG_INSTRUCTION) != 0) - sim_io_printf (sd, "do_long 0x%x\n", mcode); + sim_io_printf (sd, "do_long 0x%" PRIx64 "\n", mcode); #endif h = lookup_hash (sd, cpu, mcode, 1); @@ -543,8 +543,9 @@ sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *cb, else h = &hash_table[hash(s->opcode, 0)]; break; + default: - break; + continue; } /* go to the last entry in the chain. */ -- 2.30.2