New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does infer support Makefile generated by CMake? #25

Closed
yagamy4680 opened this Issue Jun 12, 2015 · 5 comments

Comments

Projects
None yet
5 participants
@yagamy4680

Hi,

I try to apply infer on the Makefile generated by CMake: infer -- make, but it seems infer cannot do any static analysis on any C source code in the workspace. Shall I give more arguments to infer to process the Makefile generated by CMake?

# cmake ../apps/test01/
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /vagrant/logs/ironman/work
06:42:31 root@yasai /vagrant/logs/ironman/work [0]
# ls -al
total 36
drwxr-xr-x 1 vagrant vagrant   204 Jun 12 06:42 .
drwxr-xr-x 1 vagrant vagrant   578 Jun 12 06:37 ..
-rw-r--r-- 1 vagrant vagrant 12278 Jun 12 06:42 CMakeCache.txt
drwxr-xr-x 1 vagrant vagrant   442 Jun 12 06:42 CMakeFiles
-rw-r--r-- 1 vagrant vagrant  1595 Jun 12 06:42 cmake_install.cmake
-rw-r--r-- 1 vagrant vagrant 16643 Jun 12 06:42 Makefile
06:42:34 root@yasai /vagrant/logs/ironman/work [0]
# infer -- make
Scanning dependencies of target test01
[ 10%] Building C object CMakeFiles/test01.dir/control.c.o
[ 20%] Building C object CMakeFiles/test01.dir/thread01.c.o
[ 30%] Building C object CMakeFiles/test01.dir/thread02.c.o
[ 40%] Building C object CMakeFiles/test01.dir/vagrant/logs/ironman/framework/native/src/httpie.c.o
[ 50%] Building C object CMakeFiles/test01.dir/vagrant/logs/ironman/framework/native/src/j_thread.c.o
[ 60%] Building C object CMakeFiles/test01.dir/vagrant/logs/ironman/framework/native/src/logger.c.o
[ 70%] Building C object CMakeFiles/test01.dir/vagrant/logs/ironman/framework/native/src/main.c.o
[ 80%] Building C object CMakeFiles/test01.dir/vagrant/logs/ironman/framework/native/src/reader.c.o
[ 90%] Building C object CMakeFiles/test01.dir/vagrant/logs/ironman/framework/native/src/sensorweb.c.o
[100%] Building C object CMakeFiles/test01.dir/vagrant/logs/ironman/framework/native/src/service.c.o
Linking C executable test01
[100%] Built target test01
Starting analysis (Infer version v0.1.0)
Analysis done

0 file analyzed


No issues found
@yagamy4680

This comment has been minimized.

Show comment
Hide comment
@yagamy4680

yagamy4680 Jun 12, 2015

Here is a simpler way to reproduce this issue:

main.c

#include <stdio.h>

int main()
{
    int *s = NULL;
    *s = 42;
    printf("hello world. \n");
}

CMakeLists.txt

cmake_minimum_required (VERSION 2.6)

project(ex1)
add_executable(ex1 main.c)

Using makefile generated by CMake:

# cmake .
# make clean
# infer -- make

Scanning dependencies of target ex1
[100%] Building C object CMakeFiles/ex1.dir/main.c.o
Linking C executable ex1
[100%] Built target ex1
Starting analysis (Infer version v0.1.0)
Analysis done

0 file analyzed

Compile main.c with gcc and infer:

# infer -- gcc ./main.c
Starting analysis (Infer version v0.1.0)
Analysis done

1 file analyzed


main.c:6: error: NULL_DEREFERENCE
   pointer s last assigned on line 5 could be null and is dereferenced at line 6, column 5

Here is a simpler way to reproduce this issue:

main.c

#include <stdio.h>

int main()
{
    int *s = NULL;
    *s = 42;
    printf("hello world. \n");
}

CMakeLists.txt

cmake_minimum_required (VERSION 2.6)

project(ex1)
add_executable(ex1 main.c)

Using makefile generated by CMake:

# cmake .
# make clean
# infer -- make

Scanning dependencies of target ex1
[100%] Building C object CMakeFiles/ex1.dir/main.c.o
Linking C executable ex1
[100%] Built target ex1
Starting analysis (Infer version v0.1.0)
Analysis done

0 file analyzed

Compile main.c with gcc and infer:

# infer -- gcc ./main.c
Starting analysis (Infer version v0.1.0)
Analysis done

1 file analyzed


main.c:6: error: NULL_DEREFERENCE
   pointer s last assigned on line 5 could be null and is dereferenced at line 6, column 5
@oschwand

This comment has been minimized.

Show comment
Hide comment
@oschwand

oschwand Jun 12, 2015

The problem is that cmake generates a Makefile which runs directly /usr/bin/cc, so infer cannot replace it by its own wrapper (since it relies on ugly $PATH tricks).

It works if you explicitly change the CC variable in order to use the infer wrapper:

CC=/path/to/infer/infer/lib/capture/clang cmake .
infer -- make

Be careful that CC can be set only one time, so you will need to clean all the cmake cache files or to use a fresh out-of-sources build directory.

The problem is that cmake generates a Makefile which runs directly /usr/bin/cc, so infer cannot replace it by its own wrapper (since it relies on ugly $PATH tricks).

It works if you explicitly change the CC variable in order to use the infer wrapper:

CC=/path/to/infer/infer/lib/capture/clang cmake .
infer -- make

Be careful that CC can be set only one time, so you will need to clean all the cmake cache files or to use a fresh out-of-sources build directory.

@yagamy4680

This comment has been minimized.

Show comment
Hide comment
@yagamy4680

yagamy4680 Jun 12, 2015

Thanks, it works.

Thanks, it works.

ghost pushed a commit that referenced this issue Mar 29, 2016

add cmake to the list of make-like tools
Summary:public
Simplifies the way to configure cmake to run infer's fake compiler commands.
Instead of `CC=/path/to/infer/infer/lib/capture/clang cmake .`, which is what
is advised on #25 and is now outdated because the paths to infer's clang has
changed since, simply run `infer -- cmake .`. The only caveat is that infer
tries to analyze the end result, and prints "No issues found". This could be
fixed later.

Reviewed By: jeremydubreil

Differential Revision: D3093162

fb-gh-sync-id: 99df50a
fbshipit-source-id: 99df50a
@mcandre

This comment has been minimized.

Show comment
Hide comment
@mcandre

mcandre Apr 3, 2016

infer 0.8.0 from Homebrew doesn't appear to have a path like .../lib/capture/clang. Is there a similar command for running infer 0.8.0 against cmake-generated Makefiles?

mcandre commented Apr 3, 2016

infer 0.8.0 from Homebrew doesn't appear to have a path like .../lib/capture/clang. Is there a similar command for running infer 0.8.0 against cmake-generated Makefiles?

@jvillard

This comment has been minimized.

Show comment
Hide comment
@jvillard

jvillard Apr 4, 2016

Contributor

The new way is easier: just run infer -- cmake ....

I forgot to comment again on this issue when I pushed 9f10b09 😶

Contributor

jvillard commented Apr 4, 2016

The new way is easier: just run infer -- cmake ....

I forgot to comment again on this issue when I pushed 9f10b09 😶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment