Merge pull request #4829 from martinbudden/bfa_fallthrough

Enabled switch fallthrough checking by compiler
This commit is contained in:
Michael Keller 2017-12-24 09:39:51 +13:00 committed by GitHub
commit d47b076a66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 100 additions and 58 deletions

View File

@ -123,6 +123,8 @@
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f30x_hrtim.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
/** @addtogroup STM32F30x_StdPeriph_Driver
* @{
@ -4104,3 +4106,4 @@ void HRTIM_TIM_ResetConfig(HRTIM_TypeDef * HRTIMx,
#pragma GCC diagnostic pop

View File

@ -40,7 +40,7 @@ DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \
endif
LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -Wimplicit-fallthrough=0
ARCH_FLAGS = -mthumb -mcpu=cortex-m3
ifeq ($(DEVICE_FLAGS),)
DEVICE_FLAGS = -DSTM32F10X_MD

View File

@ -53,7 +53,7 @@ endif
LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k.ld
ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion -Wimplicit-fallthrough=0
ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
DEVICE_FLAGS = -DSTM32F303xC -DSTM32F303
VCP_SRC = \

View File

@ -133,7 +133,7 @@ VPATH := $(VPATH):$(FATFS_DIR)
endif
#Flags
ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion -Wimplicit-fallthrough=0
ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
ifeq ($(TARGET),$(filter $(TARGET),$(F411_TARGETS)))
DEVICE_FLAGS = -DSTM32F411xE

View File

@ -109,7 +109,7 @@ VPATH := $(VPATH):$(FATFS_DIR)
endif
#Flags
ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsingle-precision-constant -Wdouble-promotion -Wimplicit-fallthrough=0
ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsingle-precision-constant -Wdouble-promotion
DEVICE_FLAGS = -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER
ifeq ($(TARGET),$(filter $(TARGET),$(F7X5XG_TARGETS)))

View File

@ -880,12 +880,10 @@ void blackboxFinish(void)
case BLACKBOX_STATE_SHUTTING_DOWN:
// We're already stopped/shutting down
break;
case BLACKBOX_STATE_RUNNING:
case BLACKBOX_STATE_PAUSED:
blackboxLogEvent(FLIGHT_LOG_EVENT_LOG_END, NULL);
// Fall through
FALLTHROUGH;
default:
blackboxSetState(BLACKBOX_STATE_SHUTTING_DOWN);
}

View File

@ -107,3 +107,9 @@ void * memcpy_fn ( void * destination, const void * source, size_t num ) asm("me
#endif
#if __GNUC__ > 6
#define FALLTHROUGH __attribute__ ((fallthrough))
#else
#define FALLTHROUGH do {} while(0)
#endif

View File

@ -912,6 +912,7 @@ bool sdcard_poll(void)
break; // Timeout not reached yet so keep waiting
}
// Timeout has expired, so fall through to convert to a fatal error
FALLTHROUGH;
case SDCARD_RECEIVE_ERROR:
sdcard_deselect();

View File

@ -279,7 +279,8 @@ static int applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t a
if (adjustmentFunction == ADJUSTMENT_PITCH_RATE) {
break;
}
// follow though for combined ADJUSTMENT_PITCH_ROLL_RATE
// fall through for combined ADJUSTMENT_PITCH_ROLL_RATE
FALLTHROUGH;
case ADJUSTMENT_ROLL_RATE:
newValue = constrain((int)controlRateConfig->rates[FD_ROLL] + delta, 0, CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX);
controlRateConfig->rates[FD_ROLL] = newValue;
@ -299,7 +300,8 @@ static int applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t a
if (adjustmentFunction == ADJUSTMENT_PITCH_P) {
break;
}
// follow though for combined ADJUSTMENT_PITCH_ROLL_P
// fall through for combined ADJUSTMENT_PITCH_ROLL_P
FALLTHROUGH;
case ADJUSTMENT_ROLL_P:
newValue = constrain((int)pidProfile->pid[PID_ROLL].P + delta, 0, 200); // FIXME magic numbers repeated in cli.c
pidProfile->pid[PID_ROLL].P = newValue;
@ -313,7 +315,8 @@ static int applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t a
if (adjustmentFunction == ADJUSTMENT_PITCH_I) {
break;
}
// fall though for combined ADJUSTMENT_PITCH_ROLL_I
// fall through for combined ADJUSTMENT_PITCH_ROLL_I
FALLTHROUGH;
case ADJUSTMENT_ROLL_I:
newValue = constrain((int)pidProfile->pid[PID_ROLL].I + delta, 0, 200); // FIXME magic numbers repeated in cli.c
pidProfile->pid[PID_ROLL].I = newValue;
@ -327,7 +330,8 @@ static int applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t a
if (adjustmentFunction == ADJUSTMENT_PITCH_D) {
break;
}
// fall though for combined ADJUSTMENT_PITCH_ROLL_D
// fall through for combined ADJUSTMENT_PITCH_ROLL_D
FALLTHROUGH;
case ADJUSTMENT_ROLL_D:
newValue = constrain((int)pidProfile->pid[PID_ROLL].D + delta, 0, 200); // FIXME magic numbers repeated in cli.c
pidProfile->pid[PID_ROLL].D = newValue;

View File

@ -204,6 +204,7 @@ static void mspFc4waySerialCommand(sbuf_t *dst, sbuf_t *src, mspPostProcessFnPtr
break;
}
FALLTHROUGH;
#endif
default:
sbufWriteU8(dst, 0);

View File

@ -30,6 +30,7 @@
#include "drivers/sdcard.h"
#include "common/maths.h"
#include "common/time.h"
#include "common/utils.h"
#ifdef AFATFS_DEBUG
#define ONLY_EXPOSE_FOR_TESTING
@ -935,14 +936,14 @@ static afatfsOperationStatus_e afatfs_cacheSector(uint32_t physicalSectorIndex,
afatfs.cacheDescriptor[cacheSectorIndex].consecutiveEraseBlockCount = eraseCount;
#endif
// Fall through
FALLTHROUGH;
case AFATFS_CACHE_STATE_WRITING:
case AFATFS_CACHE_STATE_IN_SYNC:
if ((sectorFlags & AFATFS_CACHE_WRITE) != 0) {
afatfs_cacheSectorMarkDirty(&afatfs.cacheDescriptor[cacheSectorIndex]);
}
// Fall through
FALLTHROUGH;
case AFATFS_CACHE_STATE_DIRTY:
if ((sectorFlags & AFATFS_CACHE_LOCK) != 0) {
@ -1456,7 +1457,7 @@ static afatfsOperationStatus_e afatfs_saveDirectoryEntry(afatfsFilePtr_t file, a
break;
case AFATFS_SAVE_DIRECTORY_DELETED:
entry->filename[0] = FAT_DELETED_FILE_MARKER;
//Fall through
FALLTHROUGH;
case AFATFS_SAVE_DIRECTORY_FOR_CLOSE:
// We write the true length of the file on close.
@ -2098,8 +2099,7 @@ afatfsOperationStatus_e afatfs_fseek(afatfsFilePtr_t file, int32_t offset, afatf
break;
case AFATFS_SEEK_SET:
;
// Fall through
FALLTHROUGH;
}
// Now we have a SEEK_SET with a positive offset. Begin by seeking to the start of the file

View File

@ -222,6 +222,7 @@ rx_spi_received_e frSkyDDataReceived(uint8_t *packet)
break;
}
FALLTHROUGH; //!!TODO -check this fall through is correct
// here FS code could be
case STATE_DATA:
if (IORead(gdoPin)) {

View File

@ -365,6 +365,7 @@ rx_spi_received_e frSkyXDataReceived(uint8_t *packet)
protocolState = STATE_INIT;
break;
}
FALLTHROUGH; //!!TODO -check this fall through is correct
// here FS code could be
case STATE_DATA:
if ((IORead(gdoPin)) &&(frame_received==false)){

View File

@ -299,6 +299,7 @@ bool spektrumInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig
case SERIALRX_SRXL:
#ifdef USE_TELEMETRY
srxlEnabled = (feature(FEATURE_TELEMETRY) && !portShared);
FALLTHROUGH;
#endif
case SERIALRX_SPEKTRUM2048:
// 11 bit frames

View File

@ -220,6 +220,7 @@ static void xBusDataReceive(uint16_t c, void *data)
switch (xBusProvider) {
case SERIALRX_XBUS_MODE_B:
xBusUnpackModeBFrame(0);
FALLTHROUGH; //!!TODO - check this fall through is correct
case SERIALRX_XBUS_MODE_B_RJ01:
xBusUnpackRJ01Frame();
}

View File

@ -26,6 +26,7 @@
#include "common/axis.h"
#include "common/filter.h"
#include "common/utils.h"
#include "config/config_reset.h"
#include "config/feature.h"
@ -136,9 +137,10 @@ retry:
switch (accHardwareToUse) {
case ACC_DEFAULT:
; // fallthrough
case ACC_ADXL345: // ADXL345
FALLTHROUGH;
#ifdef USE_ACC_ADXL345
case ACC_ADXL345: // ADXL345
acc_params.useFifo = false;
acc_params.dataRate = 800; // unused currently
if (adxl345Detect(&acc_params, dev)) {
@ -148,10 +150,11 @@ retry:
accHardware = ACC_ADXL345;
break;
}
FALLTHROUGH;
#endif
; // fallthrough
case ACC_LSM303DLHC:
#ifdef USE_ACC_LSM303DLHC
case ACC_LSM303DLHC:
if (lsm303dlhcAccDetect(dev)) {
#ifdef ACC_LSM303DLHC_ALIGN
dev->accAlign = ACC_LSM303DLHC_ALIGN;
@ -159,10 +162,11 @@ retry:
accHardware = ACC_LSM303DLHC;
break;
}
FALLTHROUGH;
#endif
; // fallthrough
case ACC_MPU6050: // MPU6050
#ifdef USE_ACC_MPU6050
case ACC_MPU6050: // MPU6050
if (mpu6050AccDetect(dev)) {
#ifdef ACC_MPU6050_ALIGN
dev->accAlign = ACC_MPU6050_ALIGN;
@ -170,10 +174,11 @@ retry:
accHardware = ACC_MPU6050;
break;
}
FALLTHROUGH;
#endif
; // fallthrough
case ACC_MMA8452: // MMA8452
#ifdef USE_ACC_MMA8452
case ACC_MMA8452: // MMA8452
if (mma8452Detect(dev)) {
#ifdef ACC_MMA8452_ALIGN
dev->accAlign = ACC_MMA8452_ALIGN;
@ -181,10 +186,11 @@ retry:
accHardware = ACC_MMA8452;
break;
}
FALLTHROUGH;
#endif
; // fallthrough
case ACC_BMA280: // BMA280
#ifdef USE_ACC_BMA280
case ACC_BMA280: // BMA280
if (bma280Detect(dev)) {
#ifdef ACC_BMA280_ALIGN
dev->accAlign = ACC_BMA280_ALIGN;
@ -192,10 +198,11 @@ retry:
accHardware = ACC_BMA280;
break;
}
FALLTHROUGH;
#endif
; // fallthrough
case ACC_MPU6000:
#ifdef USE_ACC_SPI_MPU6000
case ACC_MPU6000:
if (mpu6000SpiAccDetect(dev)) {
#ifdef ACC_MPU6000_ALIGN
dev->accAlign = ACC_MPU6000_ALIGN;
@ -203,10 +210,11 @@ retry:
accHardware = ACC_MPU6000;
break;
}
FALLTHROUGH;
#endif
; // fallthrough
case ACC_MPU9250:
#ifdef USE_ACC_SPI_MPU9250
case ACC_MPU9250:
if (mpu9250SpiAccDetect(dev)) {
#ifdef ACC_MPU9250_ALIGN
dev->accAlign = ACC_MPU9250_ALIGN;
@ -214,8 +222,9 @@ retry:
accHardware = ACC_MPU9250;
break;
}
FALLTHROUGH;
#endif
; // fallthrough
case ACC_MPU6500:
case ACC_ICM20601:
case ACC_ICM20602:
@ -249,9 +258,10 @@ retry:
break;
}
#endif
; // fallthrough
case ACC_ICM20649:
FALLTHROUGH;
#ifdef USE_ACC_SPI_ICM20649
case ACC_ICM20649:
if (icm20649SpiAccDetect(dev)) {
accHardware = ACC_ICM20649;
#ifdef ACC_ICM20649_ALIGN
@ -259,10 +269,11 @@ retry:
#endif
break;
}
FALLTHROUGH;
#endif
; // fallthrough
case ACC_ICM20689:
#ifdef USE_ACC_SPI_ICM20689
case ACC_ICM20689:
if (icm20689SpiAccDetect(dev)) {
accHardware = ACC_ICM20689;
#ifdef ACC_ICM20689_ALIGN
@ -270,10 +281,11 @@ retry:
#endif
break;
}
FALLTHROUGH;
#endif
; // fallthrough
case ACC_BMI160:
#ifdef USE_ACCGYRO_BMI160
case ACC_BMI160:
if (bmi160SpiAccDetect(dev)) {
accHardware = ACC_BMI160;
#ifdef ACC_BMI160_ALIGN
@ -281,20 +293,22 @@ retry:
#endif
break;
}
FALLTHROUGH;
#endif
; // fallthrough
case ACC_FAKE:
#ifdef USE_FAKE_ACC
case ACC_FAKE:
if (fakeAccDetect(dev)) {
accHardware = ACC_FAKE;
break;
}
FALLTHROUGH;
#endif
; // fallthrough
default:
case ACC_NONE: // disable ACC
accHardware = ACC_NONE;
break;
}
// Found anything? Check if error or ACC is really missing.
@ -304,7 +318,6 @@ retry:
goto retry;
}
if (accHardware == ACC_NONE) {
return false;
}

View File

@ -154,7 +154,7 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
switch (baroHardware) {
case BARO_DEFAULT:
; // fallthough
FALLTHROUGH;
case BARO_BMP085:
#ifdef USE_BARO_BMP085
@ -175,7 +175,7 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
}
}
#endif
; // fallthough
FALLTHROUGH;
case BARO_MS5611:
#if defined(USE_BARO_MS5611) || defined(USE_BARO_SPI_MS5611)
@ -184,7 +184,7 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
break;
}
#endif
; // fallthough
FALLTHROUGH;
case BARO_BMP280:
#if defined(USE_BARO_BMP280) || defined(USE_BARO_SPI_BMP280)
@ -193,7 +193,7 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
break;
}
#endif
; // fallthough
FALLTHROUGH;
case BARO_NONE:
baroHardware = BARO_NONE;

View File

@ -162,7 +162,7 @@ bool compassDetect(magDev_t *dev)
switch (compassConfig()->mag_hardware) {
case MAG_DEFAULT:
; // fallthrough
FALLTHROUGH;
case MAG_HMC5883:
#if defined(USE_MAG_HMC5883) || defined(USE_MAG_SPI_HMC5883)
@ -178,7 +178,7 @@ bool compassDetect(magDev_t *dev)
break;
}
#endif
; // fallthrough
FALLTHROUGH;
case MAG_AK8975:
#ifdef USE_MAG_AK8975
@ -194,7 +194,7 @@ bool compassDetect(magDev_t *dev)
break;
}
#endif
; // fallthrough
FALLTHROUGH;
case MAG_AK8963:
#if defined(USE_MAG_AK8963) || defined(USE_MAG_SPI_AK8963)
@ -215,7 +215,7 @@ bool compassDetect(magDev_t *dev)
break;
}
#endif
; // fallthrough
FALLTHROUGH;
case MAG_NONE:
magHardware = MAG_NONE;

View File

@ -175,6 +175,8 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
switch (gyroHardware) {
case GYRO_DEFAULT:
FALLTHROUGH;
#ifdef USE_GYRO_MPU6050
case GYRO_MPU6050:
if (mpu6050GyroDetect(dev)) {
@ -184,6 +186,7 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
#endif
break;
}
FALLTHROUGH;
#endif
#ifdef USE_GYRO_L3G4200D
@ -195,6 +198,7 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
#endif
break;
}
FALLTHROUGH;
#endif
#ifdef USE_GYRO_MPU3050
@ -206,6 +210,7 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
#endif
break;
}
FALLTHROUGH;
#endif
#ifdef USE_GYRO_L3GD20
@ -217,6 +222,7 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
#endif
break;
}
FALLTHROUGH;
#endif
#ifdef USE_GYRO_SPI_MPU6000
@ -228,6 +234,7 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
#endif
break;
}
FALLTHROUGH;
#endif
#if defined(USE_GYRO_MPU6500) || defined(USE_GYRO_SPI_MPU6500)
@ -261,19 +268,19 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
#endif
break;
}
FALLTHROUGH;
#endif
#ifdef USE_GYRO_SPI_MPU9250
case GYRO_MPU9250:
if (mpu9250SpiGyroDetect(dev))
{
if (mpu9250SpiGyroDetect(dev)) {
gyroHardware = GYRO_MPU9250;
#ifdef GYRO_MPU9250_ALIGN
dev->gyroAlign = GYRO_MPU9250_ALIGN;
#endif
break;
}
break;
}
FALLTHROUGH;
#endif
#ifdef USE_GYRO_SPI_ICM20649
@ -285,6 +292,7 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
#endif
break;
}
FALLTHROUGH;
#endif
#ifdef USE_GYRO_SPI_ICM20689
@ -296,6 +304,7 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
#endif
break;
}
FALLTHROUGH;
#endif
#ifdef USE_ACCGYRO_BMI160
@ -307,6 +316,7 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
#endif
break;
}
FALLTHROUGH;
#endif
#ifdef USE_FAKE_GYRO
@ -315,7 +325,9 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev)
gyroHardware = GYRO_FAKE;
break;
}
FALLTHROUGH;
#endif
default:
gyroHardware = GYRO_NONE;
}

View File

@ -234,7 +234,7 @@ void gyroDataAnalyseUpdate(biquadFilter_t *notchFilterDyn)
arm_bitreversal_32((uint32_t*) fftData, Sint->bitRevLength, Sint->pBitRevTable);
DEBUG_SET(DEBUG_FFT_TIME, 1, micros() - startTime);
step++;
// fall through
FALLTHROUGH;
}
case STEP_STAGE_RFFT_F32:
{
@ -250,7 +250,7 @@ void gyroDataAnalyseUpdate(biquadFilter_t *notchFilterDyn)
arm_cmplx_mag_f32(rfftData, fftData, fftBinCount);
DEBUG_SET(DEBUG_FFT_TIME, 2, micros() - startTime);
step++;
// fall through
FALLTHROUGH;
}
case STEP_CALC_FREQUENCIES:
{
@ -301,7 +301,7 @@ void gyroDataAnalyseUpdate(biquadFilter_t *notchFilterDyn)
axis = (axis + 1) % 3;
step++;
// fall through
FALLTHROUGH;
}
case STEP_HANNING:
{