This is an archive of the discontinued LLVM Phabricator instance.

[Support/Compiler.h] - Use gnu::fallthrough for LLVM_FALLTHROUGH when available.
ClosedPublic

Authored by grimar on May 10 2017, 6:15 AM.

Details

Summary

I tried to compile LLD using GCC 7.1.0 and got warnings like
"warning: this statement may fall through [-Wimplicit-fallthrough=]"
(some more details are here: D32907)

GCC's __cplusplus value is 201402L by default, so macro expands to nothing,
though GCC 7 has support for [[fallthrough]].

I suggest to use gnu::fallthrough when it is available. That fixes issue I am observing.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.May 10 2017, 6:15 AM
aaron.ballman accepted this revision.May 10 2017, 6:19 AM
aaron.ballman added a subscriber: aaron.ballman.

This looks reasonable to me.

This revision is now accepted and ready to land.May 10 2017, 6:19 AM
davide accepted this revision.May 10 2017, 7:46 AM

Sure, but this is what I suggested in the first place, so I'll let other sign-off.

Sure, but this is what I suggested in the first place, so I'll let other sign-off.

Yeah, thanks for pointing on gnu::fallthrough !

ruiu added inline comments.May 10 2017, 11:51 AM
Compiler.h
236–237 ↗(On Diff #98435)

I think you want to move this before !cplusplus to define LLVM_FALLTHROUGH even !cplusplus.

grimar updated this revision to Diff 98600.May 11 2017, 2:28 AM
  • Addressed review comments.
grimar added inline comments.May 11 2017, 2:30 AM
Compiler.h
236–237 ↗(On Diff #98435)

Looks reasonable, thanks.

Code probably could be something like next for clarity about workaround:

#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
#define LLVM_FALLTHROUGH [[fallthrough]]
#elif __has_cpp_attribute(gnu::fallthrough)
#define LLVM_FALLTHROUGH [[gnu::fallthrough]]
#elif __cplusplus && __has_cpp_attribute(clang::fallthrough)
// Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
// error when __has_cpp_attribute is given a scoped attribute in C mode.
#define LLVM_FALLTHROUGH [[clang::fallthrough]]
#else
#define LLVM_FALLTHROUGH
#endif
ruiu accepted this revision.May 11 2017, 11:37 AM

LGTM

This revision was automatically updated to reflect the committed changes.