Description
Due to an unusual attempt on my part to make the same compile_commands.json file work in both macOS and Windows, I added the same set of source files to the JSON file twice, with the paths to the files on my Mac and on my Windows PC. This was allowed when I was using Apple clangd 17.0.0 as my language server, but it crashes in clangd 19.1.4 on Windows and a self-built clangd 21.0.0git on macOS. Obviously it would be preferable to get an error message saying that a Windows path is not allowed on Mac and a Mac path not allowed in Windows, if it's the case that clangd is not supposed to support this sort of cross-platform kludge in compile_commands.json.
The minimal repro case for this issue is to make a compile_commands.json file in your source directory and place a single listing in it for a file, using some arbitrary path starting with "C:/" if on Mac, or starting with "/" if on Windows, and then run clangd on a source file in that directory (e.g. clangd --check=source/main.cpp
). When clangd finds the JSON file it will blow up. Example file for causing the crash on a Mac:
[
{
"directory": "C:/my/path/to/source",
"command": "clang++ -std=c++20 -c -o VSCode/build/main.o ./source/main.cpp",
"file": "main.cpp"
}
]
Error message:
Assertion failed: (llvm::sys::path::is_absolute(Path)), function absoluteParent, file Path.cpp, line 23.
Stack trace:
#0 0x000000010474b938 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x1004f7938)
#1 0x000000010474bf30 PrintStackTraceSignalHandler(void*) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x1004f7f30)
#2 0x0000000104749bb4 llvm::sys::RunSignalHandlers() (/my/path/to/llvm-project/build/Debug/bin/clangd+0x1004f5bb4)
#3 0x000000010474d494 SignalHandler(int, __siginfo*, void*) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x1004f9494)
#4 0x0000000190b68624 (/usr/lib/system/libsystem_platform.dylib+0x1804ac624)
#5 0x0000000190b2e88c (/usr/lib/system/libsystem_pthread.dylib+0x18047288c)
#6 0x0000000190a37c60 (/usr/lib/system/libsystem_c.dylib+0x18037bc60)
#7 0x0000000190a36eec (/usr/lib/system/libsystem_c.dylib+0x18037aeec)
#8 0x00000001075313b0 clang::clangd::absoluteParent(llvm::StringRef) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x1032dd3b0)
#9 0x0000000106fec18c clang::clangd::(anonymous namespace)::actOnAllParentDirectories(llvm::StringRef, llvm::function_ref<bool (llvm::StringRef)>) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x102d9818c)
#10 0x0000000106ff0188 clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::Filter::addParents(llvm::StringRef) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x102d9c188)
#11 0x0000000106fecae8 clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::Filter::filter(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>, std::__1::atomic<bool>&) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x102d98ae8)
#12 0x0000000106fec804 clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::process(clang::clangd::DirectoryBasedGlobalCompilationDatabase::CDBLookupResult const&) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x102d98804)
#13 0x0000000106ffcc70 clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::run() (/my/path/to/llvm-project/build/Debug/bin/clangd+0x102da8c70)
#14 0x0000000106ffcb54 clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::BroadcastThread(clang::clangd::DirectoryBasedGlobalCompilationDatabase&)::'lambda'()::operator()() const (/my/path/to/llvm-project/build/Debug/bin/clangd+0x102da8b54)
#15 0x0000000106ffcb04 decltype(std::declval<clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::BroadcastThread(clang::clangd::DirectoryBasedGlobalCompilationDatabase&)::'lambda'()>()()) std::__1::__invoke[abi:dn190102]<clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::BroadcastThread(clang::clangd::DirectoryBasedGlobalCompilationDatabase&)::'lambda'()>(clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::BroadcastThread(clang::clangd::DirectoryBasedGlobalCompilationDatabase&)::'lambda'()&&) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x102da8b04)
#16 0x0000000106ffcae0 void std::__1::__thread_execute[abi:dn190102]<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::BroadcastThread(clang::clangd::DirectoryBasedGlobalCompilationDatabase&)::'lambda'()>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::BroadcastThread(clang::clangd::DirectoryBasedGlobalCompilationDatabase&)::'lambda'()>&, std::__1::__tuple_indices<>) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x102da8ae0)
#17 0x0000000106ffc81c void* std::__1::__thread_proxy[abi:dn190102]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::BroadcastThread(clang::clangd::DirectoryBasedGlobalCompilationDatabase&)::'lambda'()>>(void*) (/my/path/to/llvm-project/build/Debug/bin/clangd+0x102da881c)
#18 0x0000000190b2ec0c (/usr/lib/system/libsystem_pthread.dylib+0x180472c0c)
#19 0x0000000190b29b80 (/usr/lib/system/libsystem_pthread.dylib+0x18046db80)