[cfe-dev] Learning how to use and deploy 'scan-build'

Martin J. O'Riordan via cfe-dev cfe-dev at lists.llvm.org
Sat Nov 12 12:36:17 PST 2016


Thanks Anna,

 

Actually there was a typo in my message and I actually had the identifier ‘zero’ not the constant ‘0’:

int main () {

  int zero = 0;

  return 5 / zero;

}

but I have changed this to just contain:

int foo () {

  int x = 0;

  return 5/x;

}

 

Compiling this as:

clang++ --analyze testScanBuild.cpp

does report the warning, and creates the file ‘testScanBuild.plist’ which on inspection appears to contain the expected diagnostic information, and compiling it as:

clang++ -c testScanBuild.cpp

does not produce a warning  (no ‘-Wall’ option).

 

I just changed my Makefile to simply:

build:  testScanBuild.o

 

%o.%cpp:

    $(CXX) -c $<

and:

scan-build --use-cc clang --use-cxx clang++ -v -v -v -o check --keep-empty make build

 

I had not realised that the analyzers would not produce a report if the compiler already warned.

 

Thanks again,

 

            MartinO

 

From: ganna at apple.com [mailto:ganna at apple.com] 
Sent: 12 November 2016 19:54
To: Martin.ORiordan at Movidius.com
Cc: Aleksei Sidorin <a.sidorin at samsung.com>; cfe-dev <cfe-dev at lists.llvm.org>
Subject: Re: [cfe-dev] Learning how to use and deploy 'scan-build'

 

Please, use the examples I provided in the previous email. The analyzer tries to avoid reporting the issues that can be found by the compiler.

 

Annas-MBP-3:compiler-rt anna$ clang --analyze ~/tmp/ex.c

/Users/anna/tmp/ex.c:6:11: warning: Division by zero

  return 5/x + 5/0;

         ~^~

1 warning generated.

Annas-MBP-3:compiler-rt anna$ clang -fsyntax-only ~/tmp/ex.c

/Users/anna/tmp/ex.c:6:17: warning: division by zero is undefined [-Wdivision-by-zero]

  return 5/x + 5/0;

                ^~

1 warning generated.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161112/4024fcd3/attachment.html>


More information about the cfe-dev mailing list