1

We are using a PVS Studio (free variant for opensource projects) in conjunction with travis-ci and it for some reason spawns errors for files located in /usr/local/clang-3.5.0/lib/clang/3.5.0/include:

/usr/local/clang-3.5.0/lib/clang/3.5.0/include/stddef.h:58:1: warning: V677 Custom declaration of a standard 'size_t' type. The declaration from system header files should be used instead.
/usr/local/clang-3.5.0/lib/clang/3.5.0/include/stddef.h:86:1: warning: V677 Custom declaration of a standard 'wchar_t' type. The declaration from system header files should be used instead.
/usr/local/clang-3.5.0/lib/clang/3.5.0/include/stdarg.h:30:1: warning: V677 Custom declaration of a standard 'va_list' type. The declaration from system header files should be used instead.
/usr/local/clang-3.5.0/lib/clang/3.5.0/include/stddef.h:47:1: warning: V677 Custom declaration of a standard 'ptrdiff_t' type. The declaration from system header files should be used instead.

This location looks like an example of “system” headers for non-standard compiler and is far away from the project root (which AFAIR is somewhere in /home: standard travis location). Script run uses latest version from https://www.viva64.com/en/pvs-studio-download-linux/, latest run at “Mon Jul 3 20:13:42 UTC 2017” (unfortunately, used version is not saved).

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
ZyX
  • 52,536
  • 7
  • 114
  • 135
  • Apparently those types are declared twice and the compiler only thinks one of those locations is the actual library. Some sort of library conflict between that custom lib and the clang std lib, probably. – Lundin Jul 04 '17 at 13:12
  • Do you compile your project with `/usr/local/clang-3.5.0/bin/clang` or with some other compiler? If you are not using this non system `clang` I'd suspect some sort of `CFLAGS` pollution. Does `env` command for user performing the build contain `CFLAGS`? – tgregory Jul 04 '17 at 14:35
  • "How to get rid …" - use the standard headers, resp. use them as expected. – too honest for this site Jul 04 '17 at 14:40
  • @tgregory From what I see CC is just clang (which CMake then expands to /usr/local/clang-3.5.0/bin/clang) and CFLAGS is just `-O0`. – ZyX Jul 04 '17 at 15:01
  • Looks like according to [FAQ](https://clang.llvm.org/docs/FAQ.html#i-get-errors-about-some-headers-being-missing-stddef-h-stdarg-h) this is a normal clang behaviour. Try passing `-nobuiltininc` compile flag. – tgregory Jul 04 '17 at 15:19
  • @tgregory I do not understand the connection, FAQ is about missing headers and error is there definitely because of some found header. I though had an idea what may have screwed things up (I actually used clang with `compiler: gcc-5`), but fixing the problem in https://github.com/neovim/bot-ci/pull/112 did not make warnings go away. – ZyX Jul 04 '17 at 15:43
  • 2
    PVS is unhappy about Clang using it's builtin headers (which are mentioned in FAQ). So adding `-nobuiltininc` to `CFLAGS` should make `Clang` use system headers and ignore the builtin ones. You may try adding `-v` to `CFLAGS` to check where does it look for headers. – tgregory Jul 04 '17 at 15:51
  • @tgregory When building with clang locally PVS does not show the error and I did not supply `-nobuiltininc`. I am currently investigating whether I may have problem go away by using different clang version (mine is 3.9.1, travis uses 3.5.0 by default). `-nobuiltininc` may also be an option, but unfortunately it is harder to test due to some hardcodings. – ZyX Jul 04 '17 at 16:02

2 Answers2

3

If the compiler is located in some unusual place, it is recommended to add a new path to the analyzer exceptions, so that you can see in the report only the warnings for the code of your own projects.

pvs-studio-analyzer analyze ... -e /path/to/exclude-path ...

or

pvs-studio ... --exclude-path /path/to/exclude-path ...

1

It appears that PVS does not detect the error if clang is updated to clang-4.0.

ZyX
  • 52,536
  • 7
  • 114
  • 135