facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.9k stars 2.01k forks source link

in-tree vs. out-out-of tree builds #1309

Open 251 opened 4 years ago

251 commented 4 years ago

[Infer v0.17.0 in Docker based on Ubuntu Bionic]

Hi,

when I use Infer on several C utilities (coreutils, diffutils, grep, make...) I've noticed that it makes a difference if I use an in-tree build:

project> ./configure
project> infer run -- make

or an out-of-tree build:

project/builddir> ../configure
project/builddir> infer run -- make

The in-tree build typically finds more issues (e.g. coreutils: 14 null dereferences in-tree but only 5 out-of-tree) but sometimes it is the other way around (e.g. make: 14/12 memory leaks but 4/6 null dereferences). Is this a known issue and what is the recommended usage? The results in each case are deterministic.

jvillard commented 3 years ago

I wonder if this has to do with the path of the files where infer finds issues. Infer will not report issues that are outside the "project root", which by default is the current directory. So, if a file is located at "project/a/b/file.c" and you run from project/buildir/, infer won't report there. Perhaps when running out-of-tree you need to pass --project-root .. to infer:

project/builddir> infer run --project-root .. -- make

That doesn't fully explain the results you are seeing but maybe could explain the biggest discrepancies.

251 commented 3 years ago

Thanks, this definitely helped - for diffutils and grep I get the same results as with the in-tree build now. Others are closer to the in-tree build but still show differences, e.g. (in-tree/out-of-tree/out-of-tree-root; omitted reports are identical):

bc

dead store: 5/4/4 memory leak: 11/10/10

coreutils

memory leak: 19/13/14 null dereference: 14/5/9

findutils

dead store: 15/14/14

make

memory leak: 14/12/15 null dereference: 4/6/5