[cfe-dev] unclear about how to correctly run scan-build through make

Dmitri Gribenko gribozavr at gmail.com
Wed Dec 12 10:48:09 PST 2012


On Wed, Dec 12, 2012 at 8:17 PM, Peeter Joot <peeter.joot at gmail.com> wrote:
> If I run scan-build on one file manually I get a report directory created as
> expected:
>
> # cat t.C
> int * foo(){ int x ; return &x ;}
>
> # scan-build -o $HOME/scan-build --use-analyzer=`which clang` clang++ t.C -c
> scan-build: Using '/home/peeterj/clang/optimized/bin/clang' for static
> analysis
> t.C:1:30: warning: address of stack memory associated with local variable
> 'x' returned [-Wreturn-stack-address]
> int * foo(){ int x ; return &x ;}
>                              ^
> 1 warning generated.
> t.C:1:22: warning: Address of stack memory associated with local variable
> 'x' returned to caller
> int * foo(){ int x ; return &x ;}
>              ~~~~~   ^      ~~
> 1 warning generated.
> scan-build: 1 bugs found.
> scan-build: Run 'scan-view /home/peeterj/scan-build/2012-12-12-3' to examine
> bug reports.
>
> However, if I run this using a make rule, I see scan-build invoke make, but
> get the "contains no reports" message:
>
> # rm *.o
> # cat makefile
> t.o : t.C
>         clang++ t.C -c
> # scan-build -o $HOME/scan-build --use-analyzer=`which clang` make
> scan-build: Using '/home/peeterj/clang/optimized/bin/clang' for static
> analysis
> clang++ t.C -c
> t.C:1:30: warning: address of stack memory associated with local variable
> 'x' returned [-Wreturn-stack-address]
> int * foo(){ int x ; return &x ;}
>                              ^
> 1 warning generated.
> scan-build: Removing directory '/home/peeterj/scan-build/2012-12-12-4'
> because it contains no reports.
>
> From the scan-build man page, it appears that this is how to use this
> utility, but doing so just results in make being called as is.  In what way
> is the makefile for the project supposed to be modified to use scan-build?

IIRC, scan-build works by setting CC, CXX etc. environment variables.
Since your Makefile does not use these, static analyzer is not being
run.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/



More information about the cfe-dev mailing list