llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.47k stars 11.77k forks source link

Clang analyzer incorrectly detects input file type #54916

Open ISSOtm opened 2 years ago

ISSOtm commented 2 years ago
scan-build: The analyzer encountered problems on some source files.
scan-build: Preprocessed versions of these sources were deposited in '/tmp/scan-build-2022-04-14-202208-1299136-1/failures'.
scan-build: Please consider submitting a bug report using these files:
scan-build:   http://clang-analyzer.llvm.org/filing_bugs.html

Here is the aforementioned failures directory, plus the object file that was treated for some reason as a C++ input file.

Here is the invocation that caused the errors:

scan-build: Using '/usr/bin/clang-13' for static analysis
/usr/bin/../lib/clang/c++-analyzer  -Wall -pedantic -DBUILD_VERSION_STRING=\"`git describe --tags --dirty --always 2>/dev/null`\" `pkg-config --libs-only-L libpng` -o rgbgfx src/gfx/main.o src/gfx/pal_packing.o src/gfx/pal_sorting.o src/gfx/pal_spec.o src/gfx/process.o src/gfx/proto_palette.o src/gfx/reverse.o src/gfx/rgba.o src/extern/getopt.o src/error.o -O3 -flto -DNDEBUG -Wall -pedantic -std=c++17 -I include -D_POSIX_C_SOURCE=200809L -fno-exceptions -fno-rtti -x c++ src/version.c `pkg-config --libs-only-l libpng`

I can also provide more files as well as sources if desired.

issotm@sheik-kitty ~% pacman -Qo scan-build
/usr/bin/scan-build is owned by clang 13.0.1-2

(Arch Linux x86_64)

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-static-analyzer

steakhal commented 2 years ago

By looking at the message:

src/gfx/pal_packing.o:1:1: error: expected unqualified-id
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000>[...]

I think clang tried to interpret the object file as a source text. Note the ELF file magic at the very beginning. However, I'm not experienced with scan-build. It's probably misinterpreting the command line in some way and that's the reason you get this. You could experiment with different flags to narrow down the problem space.

ISSOtm commented 2 years ago

Yeah, that's also the conclusion I've arrived to, but running the command manually yields the same result. Note that this only happens for object files generated from C++ sources, oddly enough.