Enabling Address sanitizer

I have installed LLVM from source but for some reason when I tried to use address sanitizer clang give me error that file “{mybuyldfolder}/llvm-project/build/lib/clang/18/lib/linux/libclang_rt.asan_static-x86_64.a” is missing.

I used flag using “-DLLVM_ENABLE_PROJECTS=“clang;clang-tools-extra;lld;lldb;polly”” (or “-DLLVM_ENABLE_PROJECTS=all” but it had some compilation error) to build clang but I don’t know which one I should use to get adress sanitizer working. Could you hint me in the right direction?

You need to build the compiler-rt runtime. You should just need to add -DLLVM_ENABLE_RUNTIMES=compiler-rt to your CMake configure command line. I don’t think there’s anything else you need to do, but the documentation here is quite vague and should probably be fixed.

For some reason I got error if I tried to build it again.

CMake Error at cmake/modules/AddLLVM.cmake:1943 (add_dependencies):
The dependency target “clang” of target “check-all” does not exist.
Call Stack (most recent call first):
cmake/modules/AddLLVM.cmake:1983 (add_lit_target)
CMakeLists.txt:1237 (umbrella_lit_testsuite_end)

Cleaning up the prevous build worked.