Bug 127637 - Add FALLTHROUGH and -Wimplicit-fallthrough to warn about unannotated implicit fallthroughs in switches
Summary: Add FALLTHROUGH and -Wimplicit-fallthrough to warn about unannotated implicit...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-25 17:23 PST by Joseph Pecoraro
Modified: 2014-01-25 19:50 PST (History)
7 users (show)

See Also:


Attachments
[PATCH] Proposed Fix - FALLTHROUGH (8.03 KB, patch)
2014-01-25 17:24 PST, Joseph Pecoraro
no flags Details | Formatted Diff | Diff
[PATCH] Proposed Fix (9.07 KB, patch)
2014-01-25 17:29 PST, Joseph Pecoraro
darin: review+
Details | Formatted Diff | Diff
[PATCH] For Landing (9.72 KB, patch)
2014-01-25 19:16 PST, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2014-01-25 17:23:21 PST
clang has -Wimplicit-fallthrough and [[clang::fallthrough]]. Lets use them!
<http://clang.llvm.org/docs/LanguageExtensions.html#the-clang-fallthrough-attribute>

The clang::fallthrough attribute is used along with the -Wimplicit-fallthrough argument to annotate intentional fall-through between switch labels. It can only be applied to a null statement placed at a point of execution between any statement and the next switch label. It is common to mark these places with a specific comment, but this attribute is meant to replace comments with a more strict annotation, which can be checked by the compiler. This attribute doesn’t change semantics of the code and can be used wherever an intended fall-through occurs. It is designed to mimic control-flow statements like break;, so it can be placed in most places where break; can, but only if there are no statements on the execution path between it and the next switch label.
Comment 1 Joseph Pecoraro 2014-01-25 17:24:10 PST
Created attachment 222242 [details]
[PATCH] Proposed Fix - FALLTHROUGH

Any reason not to add this? This adds it to WTF and enables for WTF. I haven't looked at other projects yet (JSC, WebCore, ...)
Comment 2 WebKit Commit Bot 2014-01-25 17:25:08 PST
Attachment 222242 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/Compiler.h:160:  Extra space before [  [whitespace/braces] [5]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:235:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:236:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256:  More than one command on the same line in if  [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257:  More than one command on the same line in if  [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:289:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:290:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:291:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:292:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 15 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Joseph Pecoraro 2014-01-25 17:29:04 PST
Created attachment 222243 [details]
[PATCH] Proposed Fix

Now with a ChangeLog.
Comment 4 WebKit Commit Bot 2014-01-25 17:29:51 PST
Attachment 222243 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/Compiler.h:160:  Extra space before [  [whitespace/braces] [5]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:235:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:236:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256:  More than one command on the same line in if  [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257:  More than one command on the same line in if  [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:289:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:290:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:291:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:292:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 15 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Darin Adler 2014-01-25 18:30:13 PST
Comment on attachment 222243 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=222243&action=review

> Source/WTF/wtf/Compiler.h:159
> +#if !defined(FALLTHROUGH) && COMPILER_SUPPORTS(FALLTHROUGH_WARNINGS)
> +#if COMPILER(CLANG)

Should just be a single #if with another && in it.

> Source/WTF/wtf/Compiler.h:165
> +#define FALLTHROUGH do { } while (false)

Can this just be defined to nothing? I wouldn’t think it needs to be a statement (see my comments below about semicolons).

> Source/WTF/wtf/dtoa/fast-dtoa.cc:257
> +                FALLTHROUGH;

Does this really require a semicolon after it? That doesn’t seem quite right to me, but maybe that’s how the clang feature works?

I don’t think we should keep the "// else fallthrough" comments since we are adding the FALLTHROUGH macros, which say the same thing.
Comment 6 Joseph Pecoraro 2014-01-25 19:12:54 PST
There is an advantage to defining the macro without a semicolon. Clang detects if is a macro with the exact text of the fall through extension. So when it emits a warning it suggests using the macro in the build warning:

With: #define FALLTHROUGH [[clang::fallthrough]]

    CompileC wtf/dtoa/fast-dtoa.cc
    /Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
                case 29:
                ^
    /Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: note: insert 'FALLTHROUGH;' to silence this warning
                case 29:
                ^
>                FALLTHROUGH; 
    /Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: note: insert 'break;' to avoid fall-through
                case 29:
                ^
                break; 
    1 error generated.


However, if the macro is not an exact match, e.g. includes a semicolon, the warning doesn't mention the macro at all:

#define FALLTHROUGH [[clang::fallthrough]];

    CompileC wtf/dtoa/fast-dtoa.cc
    /Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
                case 29:
                ^
    /Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: note: insert '[[clang::fallthrough]];' to silence this warning
                case 29:
                ^
>                [[clang::fallthrough]]; 
    /Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: note: insert 'break;' to avoid fall-through
                case 29:
                ^
                break; 
    1 error generated.
Comment 7 Joseph Pecoraro 2014-01-25 19:16:34 PST
Created attachment 222245 [details]
[PATCH] For Landing
Comment 8 WebKit Commit Bot 2014-01-25 19:18:15 PST
Attachment 222245 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/Compiler.h:159:  Extra space before [  [whitespace/braces] [5]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:235:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:236:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256:  More than one command on the same line in if  [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257:  More than one command on the same line in if  [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:289:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:290:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:291:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:292:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 15 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 WebKit Commit Bot 2014-01-25 19:50:25 PST
Comment on attachment 222245 [details]
[PATCH] For Landing

Clearing flags on attachment: 222245

Committed r162793: <http://trac.webkit.org/changeset/162793>
Comment 10 WebKit Commit Bot 2014-01-25 19:50:28 PST
All reviewed patches have been landed.  Closing bug.