facebook / infer

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

[pulse] Handling Third-Party Library Calls when Analysing Projects #1814

Closed Robsterbobster closed 7 months ago

Robsterbobster commented 7 months ago

Hello, I am using Pulse to analyse a C project that assumes some third-party libraries are installed before compilation. In that C project, there are some calls to third-party library functions. If I analyse this project, these calls can be treated as unknown and thus give inaccurate results. I have the third-libraries source codes and I can run pulse on them, is there any features in Pulse or things I can do to address this problem?

jvillard commented 7 months ago

Hi @Robsterbobster, if you have a way to expose the code of library functions to infer then you should be able to have infer take them into account. One way to do this is to capture libraries and then the project in the same infer-out/ with --continue. Something like this:

# first library
$ cd ~/code/lib1
$ infer capture -o /tmp/infer-out -- make -j 8
# second library
$ cd ~/code/lib2
$ infer capture --continue -o /tmp/infer-out -- make -j 8
# main project
$ cd ~/code/project
$ infer capture --continue -o /tmp/infer-out -- make -j 8
$ infer analyze -o /tmp/infer-out

If you also want infer to report on library code then all of these should share a common project root (here that would be --project-root ~/code).

Alternatively, you can also look into the various --pulse-model-* options to specify what some of these functions do in basic terms if it turns out that a few library functions are causing most of the precision loss.

Robsterbobster commented 7 months ago

Hi @jvillard, that works! Thank you very much for your help!