From: Thomas Martens Date: Mon, 14 Aug 2017 20:52:21 +0000 (+0200) Subject: Added a define "FALLTHROUGH" to suppress 'this statement may fallthrough' messages X-Git-Tag: v1.6~25 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=19db887a6c57ad42b17b24256a5b2cf9125e898b;p=sx%2Fsimavr.git Added a define "FALLTHROUGH" to suppress 'this statement may fallthrough' messages Since avr-gcc version 7 the flag -Wimplicit-fallthrough is set, so that a missing "break;" inside a switch-case statement will throw an error in the compiling process. The missing breaks are replaced by the FALLTHROUGH define and no errors occours. FALLTHROUGH is simply an "__attribute__((fallthrough));" - if it is supported by the compiler. --- diff --git a/examples/board_timer_64led/timer_64led.c b/examples/board_timer_64led/timer_64led.c index 5e6fe3f..c5f4e26 100644 --- a/examples/board_timer_64led/timer_64led.c +++ b/examples/board_timer_64led/timer_64led.c @@ -104,8 +104,10 @@ void displayCB(void) /* function called whenever redisplay needed */ switch (i) { case 3: dy += 3.0f * pixsize; + FALLTHROUGH case 6: dy += 3.0f * pixsize; + FALLTHROUGH case 0: dx += 1.0f * pixsize; glVertex2f(dx + size, dy + size); glVertex2f(dx, dy + size); glVertex2f(dx, dy); glVertex2f(dx + size, dy); diff --git a/simavr/sim/avr_adc.c b/simavr/sim/avr_adc.c index 4565b89..b563cba 100644 --- a/simavr/sim/avr_adc.c +++ b/simavr/sim/avr_adc.c @@ -140,8 +140,10 @@ avr_adc_read_h( switch (p->read_status) { case 0: avr_adc_read_l(avr, p->r_adcl, param); + FALLTHROUGH case 1: p->read_status = 2; + FALLTHROUGH default: return avr_core_watch_read(avr, addr); } diff --git a/simavr/sim/sim_avr.h b/simavr/sim/sim_avr.h index 035e41e..aedffb2 100644 --- a/simavr/sim/sim_avr.h +++ b/simavr/sim/sim_avr.h @@ -26,6 +26,16 @@ extern "C" { #endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif + +#if __has_attribute(fallthrough) + #define FALLTHROUGH __attribute__((fallthrough)); +#else + #define FALLTHROUGH +#endif + #include "sim_irq.h" #include "sim_interrupts.h" #include "sim_cmds.h" diff --git a/simavr/sim/sim_core.c b/simavr/sim/sim_core.c index 8650c85..f3b163d 100644 --- a/simavr/sim/sim_core.c +++ b/simavr/sim/sim_core.c @@ -976,6 +976,7 @@ run_one_again: case 0x9518: // RETI -- Return from Interrupt -- 1001 0101 0001 1000 avr_sreg_set(avr, S_I, 1); avr_interrupt_reti(avr); + FALLTHROUGH case 0x9508: { // RET -- Return -- 1001 0101 0000 1000 new_pc = _avr_pop_addr(avr); cycle += 1 + avr->address_size;