Since clang does not support comment style fallthrough annotations
these should be switched.
Compiler.h must be modified to allow c code to include it and allow LLVM_FALLTHROUGH to expand to attribute((fallthrough))
Differential D66487
Fix -Wimplicit-fallthrough warnings in regcomp.c Nathan-Huckleberry on Aug 20 2019, 11:18 AM. Authored by
Details Since clang does not support comment style fallthrough annotations Compiler.h must be modified to allow c code to include it and allow LLVM_FALLTHROUGH to expand to attribute((fallthrough))
Diff Detail
Event Timeline
Comment Actions I think this patch is causing BB errors: FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/regcomp.c.o /usr/bin/cc -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support -I/b/sanitizer-x86_64-linux-bootstrap/build/llvm/lib/Support -I/usr/include/libxml2 -Iinclude -I/b/sanitizer-x86_64-linux-bootstrap/build/llvm/include -fPIC -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -UNDEBUG -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/regcomp.c.o -MF lib/Support/CMakeFiles/LLVMSupport.dir/regcomp.c.o.d -o lib/Support/CMakeFiles/LLVMSupport.dir/regcomp.c.o -c /b/sanitizer-x86_64-linux-bootstrap/build/llvm/lib/Support/regcomp.c In file included from /b/sanitizer-x86_64-linux-bootstrap/build/llvm/lib/Support/regcomp.c:51:0: /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/Support/Compiler.h:152:30: error: missing ')' after "__has_attribute" #if __has_cpp_attribute(clang::reinitializes) ^ /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/Support/Compiler.h:152:31: error: ':' without preceding '?' #if __has_cpp_attribute(clang::reinitializes) ^ /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/Support/Compiler.h:255:30: error: missing ')' after "__has_attribute" #elif __has_cpp_attribute(gnu::fallthrough) ^ /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/Support/Compiler.h:255:31: error: ':' without preceding '?' #elif __has_cpp_attribute(gnu::fallthrough) ^ /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/Support/Compiler.h:259:32: error: missing ')' after "__has_attribute" #elif __has_cpp_attribute(clang::fallthrough) ^ /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/Support/Compiler.h:259:33: error: ':' without preceding '?' #elif __has_cpp_attribute(clang::fallthrough) ^ /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/Support/Compiler.h:267:30: error: missing ')' after "__has_attribute" #if __has_cpp_attribute(clang::require_constant_initialization) ^ /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/Support/Compiler.h:267:31: error: ':' without preceding '?' #if __has_cpp_attribute(clang::require_constant_initialization)
Comment Actions While we discuss the fix, I went ahead and reverted in r369569 to get the bots back to green. This comment was removed by ormris. Comment Actions Maybe replace __has_cpp_attribute with something like this? #ifndef has_cpp_attribute #ifdef __cplusplus # define has_cpp_attribute(x) __has_cpp_attribute(x) #else # define has_cpp_attribute(x) 0 #endif #endif Comment Actions We have other C files that may wish to use attributes, so I don't see that as a long-term solution. That will run into the same issue -- you'll use has_cpp_attribute(clang::something) and in non-C++ mode, the :: will cause an error. You need to hide the :: behind the __cplusplus check. Comment Actions
Shouldn't the preprocessor take care of that? has_cpp_attribute(clang::something) just gets replaced by 0? I tested locally and it appears to work. Comment Actions I think I missed the lack of double underscores there -- I was worried about the Clang 3.6 behavior commented elsewhere in the file, but that won't happen here. You're right, this code should work. I would name it LLVM_HAS_BRACKET_ATTRIBUTE though to avoid confusion like what I ran into. Something like: #ifndef LLVM_HAS_BRACKET_ATTRIBUTE #if defined(__cplusplus) && defined(__has_cpp_attribute) #define LLVM_HAS_BRACKET_ATTRIBUTE(x) __has_cpp_attribute(x) #else #define LLVM_HAS_BRACKET_ATTRIBUTE(x) 0 #endif #endif (I don't think we should name it LLVM_HAS_ATTRIBUTE because we also have __has_attribute checks for GNU-style attributes.) |
#if defined(__cplusplus) please