Commit 19db887a6c57ad42b17b24256a5b2cf9125e898b
authorThomas Martens <thomas@defaultschuldiger.de>
Mon, 14 Aug 2017 20:52:21 +0000 (22:52 +0200)
committerMichel Pollet <github.com@pollet.net>
Tue, 15 Aug 2017 11:12:14 +0000 (12:12 +0100)
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.

4 files changed:
examples/board_timer_64led/timer_64led.c
simavr/sim/avr_adc.c
simavr/sim/sim_avr.h
simavr/sim/sim_core.c

index 5e6fe3f5a0f4a531f45e9a77e7ac98501915488e..c5f4e26edd2e9e53826b07f23c78fa228e2da07d 100644 (file)
@@ -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);
index 4565b890db08f57de1fe4d4e9a4b1c591090b19d..b563cba76f53aa1bf339a358bb8befc1ba7acfec 100644 (file)
@@ -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);
        }
index 035e41eeee0ac864cd115dd2a62a9ae16dae473c..aedffb2190a7a8bb8179af9a2d79e5323506c0c1 100644 (file)
 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"
index 8650c85b8e43ffeed25cdc150766dd4751ff2c15..f3b163dce560213d3e0b30e87f5c911f62739c77 100644 (file)
@@ -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;