New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 39382 - Enable -Wimplicit-fallthrough for C
Summary: Enable -Wimplicit-fallthrough for C
Status: RESOLVED DUPLICATE of bug 37135
Alias: None
Product: clang
Classification: Unclassified
Component: Frontend (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: David Bolvansky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-22 10:14 PDT by Nick Desaulniers
Modified: 2019-08-15 11:10 PDT (History)
7 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Desaulniers 2018-10-22 10:14:20 PDT
For some reason, -Wimplicit-fallthrough doesn't do anything for C code.  It doesn't produce a warning for being an unrecognized flag, it just doesn't print any Diags.

Would be nice to have with:
https://bugs.llvm.org/show_bug.cgi?id=37135

https://godbolt.org/z/gV_c9_
Comment 1 Nick Desaulniers 2018-10-22 10:17:36 PDT
https://godbolt.org/z/9Xxg9k (C++ example)
Comment 2 Miguel Ojeda 2018-10-22 13:35:50 PDT
Note that the warning works when using -fdouble-square-bracket-attributes.

What is missing is simply enabling the GNU attribute syntax for this one.
Comment 3 Chih-Hung Hsieh 2018-10-22 13:46:54 PDT
Could this check not depending on -fdouble-square-bracket-attributes in C mode?
C/C++ code can be changed to avoid such warning without using any new feature.
Comment 4 Miguel Ojeda 2018-10-22 13:53:12 PDT
This is the message I was planning to send here, but Nick went ahead :-)

clang supports in C mode the [[fallthrough]] attribute using -fdouble-square-bracket-attributes. However, it does not support the GNU attribute, i.e. __fallthrough__.

Since it supports both in C++ mode, could we enable it in C mode? It would increase compatibility with gcc >= 7.1 (e.g. no need to use a different definition for a __fallthrough macro between gcc and clang) and make the warning useful without the need to set -fdouble-square-bracket-attributes.

This came up in the LKML while we were discussing whether to continue using gcc's "comment parsing" vs. switching already to the attribute approach.

  https://lore.kernel.org/lkml/20181021171414.22674-1-miguel.ojeda.sandonis@gmail.com/
Comment 5 Nick Desaulniers 2019-06-19 18:36:57 PDT
https://reviews.llvm.org/D63260
Comment 6 Nick Desaulniers 2019-06-19 18:38:38 PDT
Maybe a duplicate of https://bugs.llvm.org/show_bug.cgi?id=37135?
Comment 7 Kees Cook 2019-08-15 11:10:20 PDT

*** This bug has been marked as a duplicate of bug 37135 ***