clangd: openmp pragmas break clangd behavior (e.g. go-to-def, rename) on symbols inside parallel loop
When using OpenMP #pragma
s, clangd’s jump to definition, rename, doesn’t work for variables or functions.
I found this error while using clangd as a C++ LSP in neovim editor.
Here’s a proof of concept C++ code showing the error …
int j = 88, k = 99;
#pragma omp parallel for
for(int i = 0; i < 10; i++)
{
printf("%d\n", k); // ERROR: Does not jump to k or rename symbol k
}
printf("%d\n", j); // CORRECT: Does jump to j and rename symbol j
Clangd breaks down inside the for loop. I can’t jump to k
, or rename it. I can’t also jump to the definition of function printf
inside the loop.
But outside the loop, I can jump to definition of j
and also rename it. Also, I can jump to definition of function printf
.
The error is clearly due to the pragma, as if I comment the pragma line out, then everything works correctly again for both k
, j
, and printf
.
Logs
I don’t know how to get the clangd logs in neovim right now.
System information
I installed clangd in neovim using Mason, and the clangd version is: 15.0.6
Editor/LSP plugin: Neovim v0.9.0-dev
NVIM v0.9.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wno-unused-result -Wimplicit-fallthrough -Wvla -fno-common -fdiagnostics-color=auto -fstack-protector-strong -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DMIN_LOG_LEVEL=3 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -DNVIM_UNIBI_HAS_VAR_FROM -I/usr/include/luajit-2.1 -I/usr/include -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/.deps/usr/include -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/build/src/nvim/auto -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/build/include -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/build/cmake.config -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/src -I/usr/include -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/.deps/usr/include -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/.deps/usr/include -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/.deps/usr/include -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/.deps/usr/include -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/.deps/usr/include -I/build/neovim-kqgxhc/neovim-0.9.0~ubuntu1+git202303031604-6d4f48182-333b5866f/.deps/usr/include
Operating system: Linux. Ubuntu 20.04.1
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 15 (2 by maintainers)
That’s exactly what my suggestion of adding the following to the clangd config file accomplishes:
The only remaining question is whether perhaps clangd should do this automatically. I don’t have a strong opinion on that.