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

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 23:53:48 PDT 2017


Author: grimar
Date: Fri May 12 01:53:48 2017
New Revision: 302878

URL: http://llvm.org/viewvc/llvm-project?rev=302878&view=rev
Log:
[Support/Compiler.h] - Use gnu::fallthrough for LLVM_FALLTHROUGH when available.

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]].

Patch uses gnu::fallthrough when it is available and fixes warning I am observing.

Initial idea of way to fix belongs to Davide Italiano.

Differential revision: https://reviews.llvm.org/D33036

Modified:
    llvm/trunk/include/llvm/Support/Compiler.h

Modified: llvm/trunk/include/llvm/Support/Compiler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=302878&r1=302877&r2=302878&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Compiler.h (original)
+++ llvm/trunk/include/llvm/Support/Compiler.h Fri May 12 01:53:48 2017
@@ -227,6 +227,8 @@
 /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
 #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
 #define LLVM_FALLTHROUGH [[fallthrough]]
+#elif __has_cpp_attribute(gnu::fallthrough)
+#define LLVM_FALLTHROUGH [[gnu::fallthrough]]
 #elif !__cplusplus
 // 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.




More information about the llvm-commits mailing list