AliveToolkit / alive2

Automatic verification of LLVM optimizations
MIT License
721 stars 93 forks source link

Is a specific version of llvm needed to build alive2? #973

Closed jeremy-rifkin closed 7 months ago

jeremy-rifkin commented 7 months ago

Hello, I'm trying to build alive2 but I'm running into the following errors. Locally I built llvm 17.0.5.

FAILED: CMakeFiles/llvm_util.dir/llvm_util/llvm2alive.cpp.o 
/usr/bin/c++ -DNO_REDIS_SUPPORT -I/home/rifkin/thirdparty/alive2 -I/home/rifkin/thirdparty/alive2/build -I/home/rifkin/thirdparty/alive-deps/include -Wall -Werror -fPIC -fstrict-enums  -O3 -O3    -D_GNU_SOURCE -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_HARDENED_MODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -std=c++20 -MD -MT CMakeFiles/llvm_util.dir/llvm_util/llvm2alive.cpp.o -MF CMakeFiles/llvm_util.dir/llvm_util/llvm2alive.cpp.o.d -o CMakeFiles/llvm_util.dir/llvm_util/llvm2alive.cpp.o -c /home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp
/home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp: In member function ‘{anonymous}::llvm2alive_::RetTy {anonymous}::llvm2alive_::visitCastInst(llvm::CastInst&)’:
/home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp:279:46: error: ‘PossiblyNonNegInst’ is not a member of ‘llvm’
  279 |         if (const auto *NNI = dyn_cast<llvm::PossiblyNonNegInst>(&i)) {
      |                                              ^~~~~~~~~~~~~~~~~~
/home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp:279:65: error: no matching function for call to ‘dyn_cast<<expression error> >(llvm::CastInst*)’
  279 |         if (const auto *NNI = dyn_cast<llvm::PossiblyNonNegInst>(&i)) {
      |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
In file included from /home/rifkin/thirdparty/alive-deps/include/llvm/Support/CBindingWrapping.h:17,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Use.h:28,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/User.h:23,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Constant.h:16,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Constants.h:28,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/Analysis/TargetFolder.h:23,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/Analysis/MemoryBuiltins.h:20,
                 from /home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp:9:
/home/rifkin/thirdparty/alive-deps/include/llvm/Support/Casting.h:667:37: note: candidate: ‘template<class To, class From> decltype(auto) llvm::dyn_cast(std::unique_ptr<From>&&)’
  667 | [[nodiscard]] inline decltype(auto) dyn_cast(std::unique_ptr<From> &&Val) {
      |                                     ^~~~~~~~
/home/rifkin/thirdparty/alive-deps/include/llvm/Support/Casting.h:667:37: note:   template argument deduction/substitution failed:
/home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp:279:65: error: template argument 1 is invalid
  279 |         if (const auto *NNI = dyn_cast<llvm::PossiblyNonNegInst>(&i)) {
      |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
In file included from /home/rifkin/thirdparty/alive-deps/include/llvm/Support/CBindingWrapping.h:17,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Use.h:28,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/User.h:23,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Constant.h:16,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Constants.h:28,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/Analysis/TargetFolder.h:23,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/Analysis/MemoryBuiltins.h:20,
                 from /home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp:9:
/home/rifkin/thirdparty/alive-deps/include/llvm/Support/Casting.h:661:37: note: candidate: ‘template<class To, class From> decltype(auto) llvm::dyn_cast(From*)’
  661 | [[nodiscard]] inline decltype(auto) dyn_cast(From *Val) {
      |                                     ^~~~~~~~
/home/rifkin/thirdparty/alive-deps/include/llvm/Support/Casting.h:661:37: note:   template argument deduction/substitution failed:
/home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp:279:65: error: template argument 1 is invalid
  279 |         if (const auto *NNI = dyn_cast<llvm::PossiblyNonNegInst>(&i)) {
      |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
In file included from /home/rifkin/thirdparty/alive-deps/include/llvm/Support/CBindingWrapping.h:17,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Use.h:28,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/User.h:23,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Constant.h:16,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Constants.h:28,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/Analysis/TargetFolder.h:23,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/Analysis/MemoryBuiltins.h:20,
                 from /home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp:9:
/home/rifkin/thirdparty/alive-deps/include/llvm/Support/Casting.h:655:37: note: candidate: ‘template<class To, class From> decltype(auto) llvm::dyn_cast(From&)’
  655 | [[nodiscard]] inline decltype(auto) dyn_cast(From &Val) {
      |                                     ^~~~~~~~
/home/rifkin/thirdparty/alive-deps/include/llvm/Support/Casting.h:655:37: note:   template argument deduction/substitution failed:
/home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp:279:65: error: template argument 1 is invalid
  279 |         if (const auto *NNI = dyn_cast<llvm::PossiblyNonNegInst>(&i)) {
      |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
In file included from /home/rifkin/thirdparty/alive-deps/include/llvm/Support/CBindingWrapping.h:17,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Use.h:28,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/User.h:23,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Constant.h:16,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/IR/Constants.h:28,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/Analysis/TargetFolder.h:23,
                 from /home/rifkin/thirdparty/alive-deps/include/llvm/Analysis/MemoryBuiltins.h:20,
                 from /home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp:9:
/home/rifkin/thirdparty/alive-deps/include/llvm/Support/Casting.h:649:37: note: candidate: ‘template<class To, class From> decltype(auto) llvm::dyn_cast(const From&)’
  649 | [[nodiscard]] inline decltype(auto) dyn_cast(const From &Val) {
      |                                     ^~~~~~~~
/home/rifkin/thirdparty/alive-deps/include/llvm/Support/Casting.h:649:37: note:   template argument deduction/substitution failed:
/home/rifkin/thirdparty/alive2/llvm_util/llvm2alive.cpp:279:65: error: template argument 1 is invalid
  279 |         if (const auto *NNI = dyn_cast<llvm::PossiblyNonNegInst>(&i)) {
      |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
regehr commented 7 months ago

hi Jeremy, please always build Alive against LLVM's top of tree. every now and then that won't work, after something changes on the LLVM side, but our goal is to keep Alive's main branch buildable against LLVM's main.

as a compiler for Alive, most recent versions of g++ and clang++ should work.

regehr commented 7 months ago

(I just refreshed my LLVM and successfully built Alive against it)

jeremy-rifkin commented 7 months ago

Awesome, I just successfully built it as well. Thank you so much for the clarification!

FlashSheridan commented 7 months ago

(I just refreshed my LLVM and successfully built Alive against it)

Was this for Mac or Linux, and with which Alive and LLVM commits?
    (Our fork is still on LLVM 15, for which building with Apple clang-1400.0.29.202 has usually worked, but my occasional attempts on Mac to build Alive ToT, with either Apple Clang or LLVM ToT, generally fail (sometimes reminiscent of https://github.com/AliveToolkit/alive2/issues/903#issuecomment-1532020202), and I haven’t detected the pattern. Linux generally works.)     I’d suggest regularly posting the last known good combination of Alive commit, platform, and compiler vendor/version.

regehr commented 7 months ago

I'll just add that these are my notes for building Alive2 and I have not seen a build fail for some time on either OSX or Linux

make an LLVM:

cmake -GNinja -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_EH=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS="llvm;clang" -DLLVM_ENABLE_RUNTIMES="libcxxabi;libcxx" ../llvm -DBUILTINS_CMAKE_ARGS=-DCOMPILER_RT_ENABLE_IOS=OFF

make sure up-to-date LLVM is in the PATH

cmake .. -G Ninja -DBUILD_TV=1 -DBUILD_LLVM_UTILS=1 -DCMAKE_BUILD_TYPE=Release -DLLVM_DIR=$HOME/llvm-project/for-alive/lib/cmake/llvm
FlashSheridan commented 7 months ago

I'll just add that these are my notes for building Alive2 and I have not seen a build fail for some time on either OSX or Linux…

Hmm, I’ve been laboring (A) to stick to the ReadMe instructions, and (B) to keep my work machine suitable for work, so some experimentation will be needed, which I’ll try to make time for next week.

FlashSheridan commented 6 months ago

My build breakage (“no member named 'isneq' in namespace 'std'”) was a problem in Alive2’s check in spaceship.h (PR https://github.com/AliveToolkit/alive2/pull/905) for reimplementing some C++20 definitions in \<compare>. It’s checking \_clangmajor__ and \_clangpatchlevel_\, which are the compiler version, rather than the SDK version. I tried, per your suggestion, my own build of Clang 18 ToT (18.0.0 8f6f5ec77), but the sysroot on my Mac (in the latest Xcode compatible with its then-current MacOS, 12.7.2 — which our product currently supports) was MacOSX13.1.sdk, and that SDK needed those definitions. When I simply commented out the version check at spaceship.h line 10, the file compiled with Clang 18.     I didn’t see a simple way to fix this, as I couldn’t find a compile-time variable for the SDK version. (Presumably enough fiddling with CMake could supply one.) It didn’t seem worth the effort, since I got another compilation error for “<=>” at spaceship.h:62 even after my crude workaround.     After upgrading to MacOSX14.2.sdk (which required updating to MacOS 13.6.3 22G436 and Xcode 15.1 15C65), I was able to build Alive2 ToT (1352eaa0) for Translation Validation with the same Clang 18, using the command in the ReadMe, plus specifying the path to Clang/++. (I didn’t need to put it in my PATH, which I don’t recommend for normal use.)     I’ve added “and SDK” to the “experimentation with Clang versions” sentence in the ReadMe in my next PR (https://github.com/AliveToolkit/alive2/pull/985).