[PATCH] D32907: [ELF] - Fix warnings when LLD compiled using gcc 7.1.0

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 10 05:56:44 PDT 2017


grimar added a comment.

My investigation about this came to next results. 
__cplusplus  for GCC 7.1.0 looks defined to 201402L by default:

umb at umb-virtual-machine:~/LLVM/build_gdbindex$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --disable-multilib
Thread model: posix
**gcc version 7.1.0 (GCC) **
umb at umb-virtual-machine:~/LLVM/build_gdbindex$ g++ -dM -E -x c++ /dev/null | grep cplus
#define __cplusplus **201402L**
umb at umb-virtual-machine:~/LLVM/build_gdbindex$ g++ -std=c++14 -dM -E -x c++ /dev/null | grep cplus
#define __cplusplus **201402L**
umb at umb-virtual-machine:~/LLVM/build_gdbindex$ g++ -std=c++17 -dM -E -x c++ /dev/null | grep cplus
#define __cplusplus **201703L**

Code we have in Support\Compiler.h checks that __cplusplus is C++17(>201402L) when checking attribute:

  /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
  #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
  #define LLVM_FALLTHROUGH [[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.
  #define LLVM_FALLTHROUGH
  #elif __has_cpp_attribute(clang::fallthrough)
  #define LLVM_FALLTHROUGH [[clang::fallthrough]]
  #else
  #define LLVM_FALLTHROUGH
  #endif

Initially code above was implemented without C++ standart check in r278868 and updated
to do this check in r278909 because "Clang triggers TONS of warnings about using a C++17 extension".

LLVM_FALLTHROUGH macro so far expands to nothing for me. 
If I use [[fallthrough]] or [[gnu::fallthrough]] directly, this fixes the issue.
FWIW, [[fallthrough]] is supported starting from GCC 7 (https://gcc.gnu.org/projects/cxx-status.html).

For now I think we can add following part of code. I checked that it fixed issue for me:

  ...
  #elif __has_cpp_attribute(gnu::fallthrough)
  #define LLVM_FALLTHROUGH [[gnu::fallthrough]]
  #else
  #define LLVM_FALLTHROUGH
  #endif

I am going to post it on review.


https://reviews.llvm.org/D32907





More information about the llvm-commits mailing list