Build errors while building LLVM or MLIR with Bazel

Hi,
I’m trying to build LLVM with Bazel using “Quick Start” procedure from utils/bazel/README.md. I would like to build it using GCC (used --config=generic_gcc option) with different GCC versions: 6.3.0, 7.4.0, 11.2.0. Depending on GCC version I get different syntax errors:

7.4.0:

In file included from external/llvm-project/libc/src/math/generic/sincosf.cpp:11:0:
external/llvm-project/libc/src/math/generic/sincosf_utils.h:19:32: error: exponent has no digits
static constexpr double PI63 = 0x1.921fb54442d18p-62;
^~~~~~~~~~~~~~~~~~
external/llvm-project/libc/src/math/generic/sincosf_utils.h:21:32: error: exponent has no digits
static constexpr double PIO4 = 0x1.921fb54442d18p-1;
^~~~~~~~~~~~~~~~~~
cc1plus: error: unrecognized command line option ‘-Wno-class-memaccess’ [-Werror]
cc1plus: all warnings being treated as errors

In file included from external/llvm-project/mlir/lib/IR/BuiltinTypes.cpp:10:0:
external/llvm-project/mlir/lib/IR/TypeDetail.h:51:49: error: ‘mlir::detail::IntegerTypeStorage::signedness’ is too small to hold all values of ‘enum mlir::IntegerType::SignednessSemantics’ [-Werror]
IntegerType::SignednessSemantics signedness : 2;
^
cc1plus: error: unrecognized command line option ‘-Wno-class-memaccess’ [-Werror]
cc1plus: all warnings being treated as errors

11.2.0:

external/llvm-project/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp:321:48: error: ‘mlir::spirv::detail::ImageTypeStorage::format’ is too small to hold all values of ‘enum class mlir::spirv::ImageFormat’ [-Werror]
ImageFormat format : getNumBits();
^
cc1plus: error: unrecognized command line option ‘-Wno-class-memaccess’ [-Werror]

In file included from external/llvm-project/mlir/lib/IR/MLIRContext.cpp:14:0:
external/llvm-project/mlir/lib/IR/TypeDetail.h:51:49: error: ‘mlir::detail::IntegerTypeStorage::signedness’ is too small to hold all values of ‘enum mlir::IntegerType::SignednessSemantics’ [-Werror]
IntegerType::SignednessSemantics signedness : 2;
^
cc1plus: error: unrecognized command line option ‘-Wno-class-memaccess’ [-Werror]

I also tried to use clang (9.0.0):

In file included from external/llvm-project/llvm/lib/Support/Watchdog.cpp:13:
In file included from external/llvm-project/llvm/include/llvm/Support/Watchdog.h:16:
external/llvm-project/llvm/include/llvm/Support/Compiler.h:20:10: fatal error: ‘stddef.h’ file not found
#include <stddef.h>
^~~~~~~~~~
1 error generated.

I even tried 54cc7de4bc01e6178213e4487d6ab49b809ba2b0 version (Fix bazel build.) GCC 7.4.0

gcc: error: unrecognized command-line option ‘-mllvm’
gcc: error: unrecognized command-line option ‘-combiner-global-alias-analysis’
gcc: error: unrecognized command-line option ‘-mllvm’
gcc: error: unrecognized command-line option ‘–tail-merge-threshold=0’

Does anybody know what I’m doing wrong?

This flag is supposed to exist in gcc > 8, are you sure you used gcc 11.2.0 here?

That said a default built shouldn’t enable -Werror, this is highly user hostile because not portable, you can patch this ⚙ D123481 Do not build with Werror by default (Bazel build) and retry.

You’re trying to build libc, this project apparently does not have a configuration to build with GCC as these are clang-specific options.

Thanks for the help, @mehdi_amini
I checked gcc version that bazel used and it was 11.2.0. Bazel build finished successfully after I applied your patch and renamed libc/BUILD.bazel