llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.52k forks source link

Unable to compile LLVM libc due to warnings treated as errors #101006

Open shreepo opened 1 month ago

shreepo commented 1 month ago

I'm trying to compile the LLVM libc project on Ubuntu, but I keep running into an issue where warnings are being treated as errors, specifically related to type conversion. Here is the relevant error message:

In file included from /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/CPP/stringstream.h:16,
                 from /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/StringUtil/error_to_string.cpp:14:
/home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/integer_to_string.h:160:58: error: conversion from ‘long unsigned int’ to ‘unsigned char’ may change value [-Werror=conversion]
  160 | template <size_t radix> using Custom = details::Fmt<radix>;
      |                                                          ^
...
cc1plus: all warnings being treated as errors

I have already tried setting the following CMake flags:

cmake -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="libc" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wno-error" -DCMAKE_C_FLAGS="-Wno-error" -DCMAKE_INSTALL_PREFIX=$HOME/local/llvm/libc ../llvm-project-18.1.8.src/llvm

And I also tried:

make CFLAGS="-Wno-error=format-truncation"

And I also tried:

env CXXFLAGS="-Wno-ignored-qualifiers -Wno-stringop-truncation -Wno-cast-function-type" make

And I also add set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) at top of the llvm-project-18.1.8.src/libc/CMakeLists.txt

But the problem persists. How can I compile the project successfully without treating these warnings as errors? Thanks in advance for any help!

lntue commented 1 month ago

Instead of -DCMAKE_C_FLAGS="-Wno-error", you can add -DLIBC_WNO_ERROR=ON to your cmake command.

shreepo commented 1 month ago

Instead of -DCMAKE_C_FLAGS="-Wno-error", you can add -DLIBC_WNO_ERROR=ON to your cmake command.

Thank you, it worked, but another issue came up. When I configure cmake with the command: cmake -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="libc" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wno-error -std=c++20" -DCMAKE_C_FLAGS="-std=c++20 -Wno-error" -DLIBC_WNO_ERROR=ON -DCMAKE_INSTALL_PREFIX=$HOME/local/llvm/libc -DLLVM_ENABLE_WERROR=OFF ../llvm-project-18.1.8.src/llvm (Add -std=c++20 flag), it gives an error: CMake Error at /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake:72 (message): Unsupported CPU features: Call Stack (most recent call first): /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/CMakeLists.txt:300 (include) I checked with lscpu and found that my computer does not support AVX512.it does not seem to avoid using this feature based on my CPU. Is it necessary to support AVX512?

lntue commented 1 month ago

is it ok for you to use ninja build instead? I don't think we have any CI bot to maintain builds with make.

If that's ok, then the simplest cmake command can be used to configure LLVM libc is:

$ cmake -GNinja -DLLVM_ENABLE_PROJECTS=libc -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=<clang/gcc> -DCMAKE_CXX_COMPILER=<clang++/g++> -DCMAKE_INSTALL_PREFIX=<...>
$ ninja libc
$ ninja install-libc
shreepo commented 1 month ago

is it ok for you to use ninja build instead? I don't think we have any CI bot to maintain builds with make.

If that's ok, then the simplest cmake command can be used to configure LLVM libc is:

$ cmake -GNinja -DLLVM_ENABLE_PROJECTS=libc -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=<clang/gcc> -DCMAKE_CXX_COMPILER=<clang++/g++> -DCMAKE_INSTALL_PREFIX=<...>
$ ninja libc
$ ninja install-libc

Thank you for your response. I used Ninja and configured with the following CMake command: cmake -GNinja -DLLVM_ENABLE_PROJECTS=libc -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=~/local/gcc-14.1.0/bin/gcc -DCMAKE_CXX_COMPILER=~/local/gcc-14.1.0/bin/g++ -DCMAKE_INSTALL_PREFIX=$HOME/local/llvm/libc ../llvm-project-18.1.8.src/llvm However, I still encounter errors during compilation when executing ninja libc. Could the issue be related to MPFR? My MPFR library is installed in a user-specific directory. Here is the error: [152/336] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.log1pf.dir/log1pf.cpp.o FAILED: projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.log1pf.dir/log1pf.cpp.o /home/chongchuanlong/local/gcc-14.1.0/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_18_1_8_ -I/home/chongchuanlong/src/LLVM/llvm-project-18.1.8.build/projects/libc/src/math/generic -I/home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/math/generic -I/home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc -isystem /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.build/projects/libc/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fpie -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -mavx2 -mfma -O3 -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.log1pf.dir/log1pf.cpp.o -MF projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.log1pf.dir/log1pf.cpp.o.d -o projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.log1pf.dir/log1pf.cpp.o -c /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/math/generic/log1pf.cpp In file included from /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/integer_utils.h:15, from /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/UInt.h:17, from /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/UInt128.h:12, from /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/FPUtil/FPBits.h:14, from /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/math/generic/log1pf.cpp:13: /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/math_extras.h: In function ‘__llvm_libc_18_1_8_::cpp::enable_if_t<((bool)(is_integral_v<T> && is_unsigned_v<T>)), __llvm_libc_18_1_8_::SumCarry<T> > __llvm_libc_18_1_8_::add_with_carry(T, T, T) [with T = unsigned char; cpp::enable_if_t<((bool)(is_integral_v<T> && is_unsigned_v<T>)), SumCarry<T> > = SumCarry<unsigned char>]’: /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/math_extras.h:77:16: error: ‘__builtin_addcb’ was not declared in this scope; did you mean ‘__builtin_addcl’? 77 | result.sum = __builtin_addcb(a, b, carry_in, &result.carry); | ^~~~~~~~~~~~~~~ | __builtin_addcl /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/math_extras.h: In function ‘__llvm_libc_18_1_8_::cpp::enable_if_t<((bool)(is_integral_v<T> && is_unsigned_v<T>)), __llvm_libc_18_1_8_::SumCarry<T> > __llvm_libc_18_1_8_::add_with_carry(T, T, T) [with T = short unsigned int; cpp::enable_if_t<((bool)(is_integral_v<T> && is_unsigned_v<T>)), SumCarry<T> > = SumCarry<short unsigned int>]’: /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/math_extras.h:86:16: error: ‘__builtin_addcs’ was not declared in this scope; did you mean ‘__builtin_addcl’? 86 | result.sum = __builtin_addcs(a, b, carry_in, &result.carry); | ^~~~~~~~~~~~~~~ | __builtin_addcl /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/math_extras.h: In function ‘__llvm_libc_18_1_8_::cpp::enable_if_t<((bool)(is_integral_v<T> && is_unsigned_v<T>)), __llvm_libc_18_1_8_::DiffBorrow<T> > __llvm_libc_18_1_8_::sub_with_borrow(T, T, T) [with T = unsigned char; cpp::enable_if_t<((bool)(is_integral_v<T> && is_unsigned_v<T>)), DiffBorrow<T> > = DiffBorrow<unsigned char>]’: /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/math_extras.h:153:17: error: ‘__builtin_subcb’ was not declared in this scope; did you mean ‘__builtin_subcl’? 153 | result.diff = __builtin_subcb(a, b, borrow_in, &result.borrow); | ^~~~~~~~~~~~~~~ | __builtin_subcl /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/math_extras.h: In function ‘__llvm_libc_18_1_8_::cpp::enable_if_t<((bool)(is_integral_v<T> && is_unsigned_v<T>)), __llvm_libc_18_1_8_::DiffBorrow<T> > __llvm_libc_18_1_8_::sub_with_borrow(T, T, T) [with T = short unsigned int; cpp::enable_if_t<((bool)(is_integral_v<T> && is_unsigned_v<T>)), DiffBorrow<T> > = DiffBorrow<short unsigned int>]’: /home/chongchuanlong/src/LLVM/llvm-project-18.1.8.src/libc/src/__support/math_extras.h:162:17: error: ‘__builtin_subcs’ was not declared in this scope; did you mean ‘__builtin_subcl’? 162 | result.diff = __builtin_subcs(a, b, borrow_in, &result.borrow); | ^~~~~~~~~~~~~~~ | __builtin_subcl ninja: build stopped: subcommand failed.

lntue commented 1 month ago

Apparently we still have some issues with building libc using gcc/g++. Is it ok for you to use clang/clang++ instead?

Otherwise, you might need to use runtime build instead, which, under the hood, build clang and use the newly built clang to build libc, with a single cmake / ninja invocation.