MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.73k stars 254 forks source link

Diagnostics for wrong file are shown #886

Open Cnly opened 2 years ago

Cnly commented 2 years ago

Observed behavior

I was using ccls on the linux kernel. On some files it seems to show the diagnostics for another file instead. For example in this screenshot, it's saying a bunch of comments are using an undeclared identifier:

CleanShot 2022-05-21 at 01 12 48@2x

It seems these diagnostics are from other files.

Minimal compile_commands.json:

[{
    "command": "clang-13 -Wp,-MMD,kernel/bpf/.core.o.d -nostdinc -I/root/linux/arch/x86/include -I./arch/x86/include/generated -I/root/linux/include -I./include -I/root/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/root/linux/include/uapi -I./include/generated/uapi -include /root/linux/include/linux/compiler-version.h -include /root/linux/include/linux/kconfig.h -include /root/linux/include/linux/compiler_types.h -D__KERNEL__ -Qunused-arguments -fmacro-prefix-map=/root/linux/= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu11 --target=x86_64-linux-gnu -fintegrated-as -Werror=unknown-warning-option -Werror=ignored-optimization-argument -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -mno-80387 -mstack-alignment=8 -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mretpoline-external-thunk -fno-delete-null-pointer-checks -Wno-frame-address -Wno-address-of-packed-member -O2 -Wframe-larger-than=2048 -fstack-protector-strong -Werror -Wno-gnu -Wno-unused-but-set-variable -Wno-unused-const-variable -fomit-frame-pointer -ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang -fno-stack-clash-protection -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wcast-function-type -fno-strict-overflow -fno-stack-check -Werror=date-time -Werror=incompatible-pointer-types -Wno-initializer-overrides -Wno-format -Wno-sign-compare -Wno-format-zero-length -Wno-pointer-to-enum-cast -Wno-tautological-constant-out-of-range-compare -Wno-override-init -I /root/linux/kernel/bpf -I ./kernel/bpf    -DKBUILD_MODFILE='\"kernel/bpf/core\"' -DKBUILD_BASENAME='\"core\"' -DKBUILD_MODNAME='\"core\"' -D__KBUILD_MODNAME=kmod_core -c -o kernel/bpf/core.o /root/linux/kernel/bpf/core.c",
    "directory": "/tmp/out/x86_64",
    "file": "/root/linux/kernel/bpf/core.c"
  }
]

I also tried strace -s999 -e read,write -fp $(pgrep -fn ccls) to get the actual output from ccls, and I saw among others

`{\"uri\":\"file:///root/linux/kernel/bpf/verifier.c\",\"diagnostics\":[{\"range\":{\"start\":{\"line\":4,\"character\":0},\"end\":{\"line\":4,\"character\":13}},\"severity\":1,\"code\":2,\"source\":\"ccls\",\"message\":\"use of undeclared identifier 'sk_filter_verifier_ops'; did you mean 'bpf_verifier_ops'?\"`

so I think it's not that the language client is showing it wrong.

Expected behavior

Diagnostics for the correct file should be shown.

Steps to reproduce

For reproducibility I'm doing this in a docker image I built, which is based on a recent debian-unstable base image:

docker run -it --rm cnly/dotfiles-full:latest-20220509-c3a091c

The following steps are run inside the container:

git clone --depth 1 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
apt install -y libelf-dev bison bc flex libncursesw5-dev lld-13
ccls --version
clang-13 --version

# Following the steps in wiki here, but compiling with gcc gives the same problems
cd linux
make O=/tmp/out/x86_64 ARCH=x86_64 LLVM=1 LLVM_SUFFIX=-13 defconfig
make O=/tmp/out/x86_64 ARCH=x86_64 LLVM=1 LLVM_SUFFIX=-13 -k -j $(nproc) bzImage modules
scripts/clang-tools/gen_compile_commands.py -d /tmp/out/x86_64

nvim kernel/bpf/verifier.c  # One of the problematic files

System information

These are obtained from the docker container above.