Skip to content

Clang Language Server Crash When Using Greater Than C++17 and Experimental Compile Options #118191

Open
@ZtRXR

Description

@ZtRXR

Title: Clang Language Server Crash When Using Greater Than C++17 and Experimental Compile Options

Description:

I encountered a crash with the Clang Language Server while trying to compile a simple C++ project using C++26 and an experimental compile option. Below are the details of my project and the error output that occurred.

Environment:

  • OS: Windows
  • Clangd version: 19.1.4
  • CMake version: 3.10
  • Visual Studio 2022

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

project(hello_world)

set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(-fexperimental-new-constant-interpreter)

add_executable(hello_world main.cpp)

main.cpp:

#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;

using ll = int64_t;
vector<pair<ll,ll>> v[ll(1e5+5)];

int main(){
    cout<<"hello world\n";
}

Error Log:
During compilation, the Clang Language Server crashed multiple times, outputting the following error:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\ppltasks.h:676:124: current parser token ')'
1.	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\ppltasks.h:95:1: parsing namespace 'Concurrency'
... [more stack frames]
[Error - 11:13:32] The Clang Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

Steps to Reproduce:

  1. Create a directory and add the above CMakeLists.txt and main.cpp.
  2. Build the project using CMake and initiate the Clang Language Server.
  3. Observe the crash and error logs.

Expected Behavior:
The Clang Language Server should not crash, and the project should compile successfully.

Additional Notes:

  • The crash seems related to parsing issues in the ppltasks.h header file.
  • The issue persists despite using a stable version of Clangd and CMake.

Please let me know if you need further information to investigate this issue. Thank you!

logs

[Info  - 11:13:29] Connection to server got closed. Server will restart.
I[11:13:30.032] clangd version 19.1.4
I[11:13:30.032] Features: windows
I[11:13:30.032] PID: 4316
I[11:13:30.033] Working directory: c:\dev\cpp\helloworld
I[11:13:30.033] argv[0]: C:\dev\cpp\clang\bin\clangd.exe
I[11:13:30.041] Starting LSP over stdin/stdout
I[11:13:30.041] <-- initialize(0)
I[11:13:30.042] --> reply:initialize(0) 1 ms
I[11:13:30.044] <-- initialized
I[11:13:30.046] <-- textDocument/didOpen
I[11:13:30.047] Loaded compilation database from c:\dev\cpp\helloworld\build/compile_commands.json
I[11:13:30.047] ASTWorker building file c:\dev\cpp\helloworld\main.cpp version 101 with command 
[C:/dev/cpp/helloworld/build]
"C:\\dev\\cpp\\clang\\bin\\clang++.exe" --driver-mode=g++ -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -std=gnu++26 -fexperimental-new-constant-interpreter -o CMakeFiles/hello_world.dir/main.cpp.obj -c "-resource-dir=C:\\dev\\cpp\\clang\\lib\\clang\\19" -- "c:\\dev\\cpp\\helloworld\\main.cpp"
I[11:13:30.048] --> window/workDoneProgress/create(0)
I[11:13:30.048] Enqueueing 1 commands for indexing
I[11:13:30.049] <-- reply(0)
I[11:13:30.049] --> $/progress
I[11:13:30.049] --> $/progress
I[11:13:30.056] <-- textDocument/documentSymbol(1)
I[11:13:30.057] <-- textDocument/codeAction(2)
I[11:13:30.061] --> textDocument/clangd.fileStatus
I[11:13:30.068] <-- textDocument/documentLink(3)
I[11:13:30.068] <-- textDocument/inlayHint(4)
I[11:13:30.161] --> $/progress
I[11:13:30.161] --> $/progress
I[11:13:30.269] <-- textDocument/foldingRange(5)
I[11:13:30.270] --> reply:textDocument/foldingRange(5) 0 ms
I[11:13:30.356] <-- textDocument/documentSymbol(6)
I[11:13:30.361] <-- textDocument/semanticTokens/full(7)
I[11:13:30.685] Built preamble of size 11708152 for file c:\dev\cpp\helloworld\main.cpp version 101 in 0.62 seconds
I[11:13:30.685] --> workspace/semanticTokens/refresh(1)
I[11:13:30.685] --> textDocument/clangd.fileStatus
I[11:13:30.686] Indexing c++23 standard library in the context of c:\dev\cpp\helloworld\main.cpp
I[11:13:30.687] <-- reply(1)
I[11:13:30.819] --> textDocument/publishDiagnostics
I[11:13:30.819] --> textDocument/inactiveRegions
I[11:13:30.819] --> reply:textDocument/documentSymbol(1) 763 ms
I[11:13:30.819] --> reply:textDocument/codeAction(2) 762 ms
I[11:13:30.819] --> reply:textDocument/documentLink(3) 751 ms
I[11:13:30.819] --> reply:textDocument/inlayHint(4) 751 ms
I[11:13:30.820] --> reply:textDocument/documentSymbol(6) 463 ms
I[11:13:30.820] --> reply:textDocument/semanticTokens/full(7) 458 ms
I[11:13:30.820] --> textDocument/clangd.fileStatus
I[11:13:31.296] <-- textDocument/semanticTokens/full/delta(8)
I[11:13:31.296] --> reply:textDocument/semanticTokens/full/delta(8) 0 ms
I[11:13:31.296] --> textDocument/clangd.fileStatus
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\ppltasks.h:676:124: current parser token ')'
1.	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\ppltasks.h:95:1: parsing namespace 'Concurrency'
2.	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\ppltasks.h:156:1: parsing namespace 'Concurrency::details'
3.	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\ppltasks.h:671:5: parsing struct/union/class body 'Concurrency::details::_ResultHolder<std::vector<bool>>'
4.	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\ppltasks.h:674:9: parsing function body 'Concurrency::details::_ResultHolder<std::vector<bool>>::Set'
5.	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\ppltasks.h:674:9: in compound statement ('{}')
6.	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\algorithm:3734:21: instantiating function definition 'std::transform<std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<unsigned int>>>, std::_Vector_iterator<std::_Vector_val<std::_Simple_types<char>>>, (lambda at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\ppltasks.h:676:75)>'
[Error - 11:13:32] The Clang Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clangdcrashPrefer [crash-on-valid] or [crash-on-invalid]

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions