Menu

#906 gcc7 implicit-fallthrough

17.6.4
closed
None
RT
Low
16.1.9
True
2018-04-05
2017-11-23
No

hi team,

gcc7 warns about switch/case that may fallthrough (no break at the end of case). this can be easily fixed by a comment / fallthrough / or // fallthrough or attribute ((fallthrough)) at the position in which you'd place the break; otherwise.

i see warnings (maybe bugs!?) in
./os/hal/ports/STM32/LLD/TIMv1/hal_pwm_lld.c
and
./os/rt/src/chschd.c
in chschd.c there are comments already, but not exactly as above.

Discussion

  • Giovanni Di Sirio

    • assigned_to: Giovanni Di Sirio
    • Component: Other --> RT
    • Affected Version: 17.6.3 --> 16.1.9
    • Fixed in Repository: False --> True
     
  • Giovanni Di Sirio

    Thanks, fixed in all versions in repository.

     
  • Niki W. Waibel

    Niki W. Waibel - 2017-11-23

    hmm,

    Compiling chschd.c
    ../chibios-svn/os/rt/src/chschd.c: In function 'wakeup':
    ../chibios-svn/os/rt/src/chschd.c:334:5: warning: this statement may fall through [-Wimplicit-fallthrough=]
         chSemFastSignalI(tp->u.wtsemp);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../chibios-svn/os/rt/src/chschd.c:338:3: note: here
       case CH_STATE_WTCOND:
       ^~~~
    

    still falls through with warning. it seems you have to put the comment right before the following case statement (even if there are some #if #else #endif)

    $ svn diff ../chibios-svn/os/rt/src/chschd.c
    Index: ../chibios-svn/os/rt/src/chschd.c
    ===================================================================
    --- ../chibios-svn/os/rt/src/chschd.c   (revision 11070)
    +++ ../chibios-svn/os/rt/src/chschd.c   (working copy)
    @@ -332,9 +332,9 @@
     #if CH_CFG_USE_SEMAPHORES == TRUE
       case CH_STATE_WTSEM:
         chSemFastSignalI(tp->u.wtsemp);
    -    /* Falls through.*/
     #endif
     #if (CH_CFG_USE_CONDVARS == TRUE) && (CH_CFG_USE_CONDVARS_TIMEOUT == TRUE)
    +    /* Falls through.*/
       case CH_STATE_WTCOND:
         /* Falls through.*/
     #endif
    

    then the warning is gone.

     

    Last edit: Niki W. Waibel 2017-11-23
  • Giovanni Di Sirio

    • status: open --> closed
     
  • Niki W. Waibel

    Niki W. Waibel - 2018-04-05

    it seems,

    $ arm-none-eabi-gcc --version
    arm-none-eabi-gcc (Fedora 7.1.0-5.fc27) 7.1.0
    Copyright (C) 2017 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    has removed the feature to get rid of the warning by using a comment.

    i use __attribute__ ((fallthrough)); for now.

     

    Last edit: Niki W. Waibel 2018-04-05
  • Niki W. Waibel

    Niki W. Waibel - 2018-04-05

    ups, i have to correct myself! i was playing with gcc -save-temps :-o (which might have removed the comments in some way, the attributes not).
    --> the comments /* falls through */ or similar are NOT ignored. sorry for false report.

     

    Last edit: Niki W. Waibel 2018-04-05

Log in to post a comment.