<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/146798>146798</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clangd] Crashing when running on Mac and Windows paths are found in compile_commands.json, and vice versa
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Iritscen
      </td>
    </tr>
</table>

<pre>
    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)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWU1v4zgS_TXKhYhBUbYlHXJwnM7uLHa3G5PGztEokSWbE4rUklTc_vcLkv5QHGcQoN2zQGOCHGipWPXq1StSEsE5udaId9nsPps93MDgN8be_WKldxz1TWPE7u5hQOINAU0GPbgBFAHvses9MZp0O9KD9cGgg2ckfoPEQYeEm66XClfcdB1o4Sa_O6NJKxWSrbHPRGrSGL8hHfDPTwS0IL9JLczWZWxJfiEgBIqTN4eemJY4M1iO0YsLIcP9fzx9_nfy67eSY5i-lX4T7_XgN0fDNCth_hfwGDP92kcmX5YTQr5upCNbcASUMlsUZLtBTX6JlwYn9Zos-l4h4Qr0WpC8nNAJJeCCo3BpgHXAa1_QBizN4In0hFtwG3Qh7cPEepJPpgHBIXwABMSham-bQSp_sGR5CLGWifDA14SQz82LNINTu-B9awYlSIOkt9iihUbFkq3Rh7KhtcaSDp2L0GAXkvAb8ASOsQNTRDqijT8mbvSRJ4ijaDS2kHpcNdkS6TNWukg3B4cpyj6NvXc39L1xobgmjYN6AucujExLuDXO3fYKfGtsR57VINYYibskqUlGFxldfN0g6aSWHShisbcmxW-NTc6lcwMGCAehwh8pVGqyM4M96E1Ii9wbu4tc9Ap4mB-0oJAo6XwgVOpQiRAQopPASNKLMx0SsI30Fuwuseg82DgtajVjbJkVi4w9ZowFHhP1wYWxb21f2Y0KEND5oFY7HGVmdIB66puAM1bllFTGKpysJySb0_2k21u-Qf6cFQ9pZsYeO5B6wvs-m9OM1RNCfguB9vat1MKddWOQpVSKNMpsydBPCPn0DbrQOfF2IIpDIijKJTRIQhsyLxapriFc-qeLsEjRBSEkK_eDMGbsmEmgpliM2Ox2GXsMfGfs0ZuMPR7SYRlbBhcZY_vyn-bGnDJ2n7F7cuu8yIoHnn4ySm45uTXkP09LIwIroU_FgR1DJqMQJ8aO0Q6AkzwO8cZ2-_QeYrYP5_nTxadxK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