Closed Bug 1355692 Opened 7 years ago Closed 7 years ago

Add MOZ_FALLTHROUGH macro definition for gcc 7 to suppress -Wimplicit-fallthrough warnings

Categories

(Core :: MFBT, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla57
Tracking Status
firefox57 --- fixed

People

(Reporter: cpeterson, Assigned: Cykesiopka)

References

Details

Attachments

(2 files)

gcc 7 added support for clang's -Wimplicit-fallthrough warning:

https://gcc.gnu.org/gcc-7/changes.html

Bug 1215411 defined the MOZ_FALLTHROUGH annotation macro as `[[clang::fallthrough]]` for clang. We should add a gcc-compatible definition like `[[gnu::fallthrough]]` for gcc >= 7.
Assignee: nobody → cykesiopka.bmo
Status: NEW → ASSIGNED
Comment on attachment 8887036 [details]
Bug 1355692 - Add MOZ_FALLTHROUGH macro definition for gcc 7 to suppress -Wimplicit-fallthrough warnings.

(MozReview and/or Bugzilla ran into some DB issue and created two review requests somehow.)
Attachment #8887036 - Attachment is obsolete: true
Attachment #8887036 - Flags: review?(mh+mozilla)
Comment on attachment 8887036 [details]
Bug 1355692 - Add MOZ_FALLTHROUGH macro definition for gcc 7 to suppress -Wimplicit-fallthrough warnings.

https://reviewboard.mozilla.org/r/157776/#review163238

::: mfbt/Attributes.h:363
(Diff revision 1)
>   *     MOZ_FALLTHROUGH_ASSERT("Unexpected foo value?!");
>   *   case 5:
>   *     return 5;
>   * }
>   */
>  #if defined(__clang__) && __cplusplus >= 201103L

while here, would you mind changing that to use __has_cpp_attribute(clang:fallthrough)?

::: mfbt/Attributes.h:373
(Diff revision 1)
> +#elif defined(__GNUC__) && __GNUC__ >= 7 && __cplusplus > 201402L
> +   /* GCC 7 and above in C++17 mode support standard fallthrough
> +    * annotations. */
> +#  define MOZ_FALLTHROUGH [[fallthrough]]

Let's leave this out for the moment. Eventually, we'll justs be able to add it under #if __cplusplus > 2017something (and that would go first)
Attachment #8887037 - Flags: review?(mh+mozilla)
Comment on attachment 8887036 [details]
Bug 1355692 - Add MOZ_FALLTHROUGH macro definition for gcc 7 to suppress -Wimplicit-fallthrough warnings.

https://reviewboard.mozilla.org/r/157776/#review163238

> while here, would you mind changing that to use __has_cpp_attribute(clang:fallthrough)?

That would indeed be nicer, but it looks like the GCC we use in CI doesn't support `__has_cpp_attribute` and therefore barfs once it sees the macro in the same line as the `#if defined(__clang__)` check.

We'd have to choose from:
 1. Move the `__has_cpp_attribute` check inside the `#if defined(__clang__)` body and duplicate a bit of logic.
 2. Define `__has_cpp_attribute` as 0 if it's not already defined.
 3. Keep using the existing check.

Thoughts?
2 sounds reasonable.
Comment on attachment 8887036 [details]
Bug 1355692 - Add MOZ_FALLTHROUGH macro definition for gcc 7 to suppress -Wimplicit-fallthrough warnings.

https://reviewboard.mozilla.org/r/157776/#review165376

::: mfbt/Attributes.h:365
(Diff revision 2)
> + * The __has_cpp_attribute macro is not directly usable because:
> + *   1. When this header is included as part of a C file, Clang does not define
> + *      the macro. Also, GCC will treat passing a scoped attribute to the macro
> + *      as a syntax error.
> + *   2. We still support versions of GCC where the macro isn't supported. If
> + *      use of the macro isn't wrapped by a compiler check, GCC will consider
> + *      the use of the macro a syntax error.

it sounds like:
#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif

would work just as much, and would be simpler.

And then you don't even need to check __clang__ and __GNUC__.
Attachment #8887036 - Flags: review?(mh+mozilla)
Comment on attachment 8887036 [details]
Bug 1355692 - Add MOZ_FALLTHROUGH macro definition for gcc 7 to suppress -Wimplicit-fallthrough warnings.

https://reviewboard.mozilla.org/r/157776/#review169476
Attachment #8887036 - Flags: review?(mh+mozilla) → review+
Thanks for the review.

https://treeherder.mozilla.org/#/jobs?repo=try&revision=857a72eef992a76ad004cffbf2f21cf240ccb74f
(Only red is from Buildbot builds, which AIUI can be ignored.)
Keywords: checkin-needed
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/3403a367f1a7
Add MOZ_FALLTHROUGH macro definition for gcc 7 to suppress -Wimplicit-fallthrough warnings. r=glandium
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/3403a367f1a7
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: