odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.13k stars 551 forks source link

Odin does not work with an LLVM build with assertions enabled #3854

Open laytan opened 5 days ago

laytan commented 5 days ago

Building LLVM in a mode that has assertions enabled makes any compilation done with it fail assertions. This is incredibly annoying when trying to use a debug version of LLVM in order to step into what LLVM is executing with a debugger.

Additionally this probably means we aren't doing things 100% correctly here.

The assertions seem to be related to the type info generation that is done, specifically after that was refactored a few months ago. And another case in the way custom metadata is done which was added with fixing #packed struct loads recently.

The first one I hit is the following, but there are more that need to be fixed following it.

lb_get_metadata_custom_u64(lbModule, LLVMOpaqueValue, String) llvm_backend_utility.cpp:69 Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h, line 578.

laytan commented 5 days ago

This might be obvious and unrelated but here's how I build LLVM:

git clone https://github.com/llvm/llvm-project.git --branch=release/18.x
cmake -Wno-dev -G "Ninja" -B build -S llvm -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;WebAssembly;X86" -DLLVM_INCLUDE_TOOLS=ON -DCOMPILER_RT_INCLUDE_TESTS=OFF -DLLVM_BUILD_BENCHMARKS=OFF -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_BUILD_UTILS=OFF -DLLVM_ENABLE_BACKTRACES=ON -DLLVM_ENABLE_BINDINGS=OFF -DLLVM_ENABLE_CRASH_OVERRIDES=OFF -DLLVM_ENABLE_LIBEDIT=OFF -DLLVM_ENABLE_LIBFPM=OFF -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_DOCS=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_UTILS=OFF -DLLVM_TOOL_LLVM_C_TEST_BUILD=OFF -DLLVM_BUILD_LLVM_C_DYLIB=ON -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=OFF
cmake --build build
laytan commented 5 days ago

3855 fixes two assertion failures (including the one in the description above).

A simple program now compiles without failures (just an empty project with an empty main proc).

Now, when I use any of the reflection/type info, LLVM prints this and segfaults:

While deleting: { i64, i64, i32, i32, i64, <{ %runtime.Type_Info_Pointer, [112 x i8], i64 }> } %
Use still stuck around after Def is destroyed:@"__$ti-76" = private unnamed_addr constant { i64, i64, i32, i32, i64, <{ %runtime.Type_Info_Pointer, [112 x i8], i64 }> } {