DISQUS

Basil Shkara: Using the LLVM/Clang Static Analyzer for iPhone apps

  • MontagFTB · 10 months ago
    I get the following output:

    ** BUILD SUCCEEDED **
    scan-build: Removing directory '/var/folders/aG/aGcWcE9zH+KjyJhECHmwhE+++TI/-Tmp-//scan-build-2009-02-23-1' because it contains no reports.

    Any thoughts how to get it to produce more than nothing?
  • Basil Shkara · 10 months ago
    That message indicates that the static analyzer could not detect any problems with your code. Perhaps try introducing a bug in your application. E.g. `NSNumber *number = [[NSNumber alloc] initWithInt:0];` and don't `release` it. That should introduce 2 bugs: a dead initialization, and a memory leak.
  • anonymous · 9 months ago
    very helpful
  • millenomi · 8 months ago
    Or use scan-build -k xcodebuild -configuration Debug -sdk iphonesimulator2.2 rather than changing the project :)
  • Basil Shkara · 8 months ago
    Ahh cool. Good tip :)
  • Benoit Cerrina · 8 months ago
    unfortunately when I run this on my project I receive no report and the last line is
    scan-build: Removing directory '/var/folders/x2/x2PXNw6pE7O8Zr7cBMzy1U+++TI/-Tmp-/scan-build-2009-04-10-1' because it contains no reports.
    can someone give me an example of the type of errors clang finds? I am really surprised that it didn't find any in my project but I'd like to try to add explicitly errors to verify that it works
  • Basil Shkara · 8 months ago
    Is scan-build in your path? I've had problems in the past when running it by specifying relative paths.

    Otherwise, you can try introducing a bug into your application.

    E.g. `NSNumber *number = [[NSNumber alloc] initWithInt:0];` and don't `release` it. That should introduce 2 bugs: a dead initialization, and a memory leak.
  • benoitcerrina · 8 months ago
    Yes it is in my build path.
    Moreover I did add some errors (in particular the exact one you suggested) and it didn't change the result. Nothing is reported and the directory is removed.

    I also have to say that on toy projects it work it is just in my real project where it doesn't
  • benoitcerrina · 8 months ago
    Do you know if clang works on objectiveC++
    Most of my source files are .mm that may be the problem?
  • benoitcerrina · 8 months ago
    Yes I think that is my problem clang is not analyzing those files.
    This is a pain as I am using some C++ mixed with objective C
  • calbot · 5 months ago
    I had the same problem I added the extra parameters after xcodebuild:
    scan-build -k -V xcodebuild -configuration Debug -sdk iphonesimulator2.1

    Found this here:http://forums.macrumors.com/showthread.php?t=737768
  • Lance Weber · 7 months ago
    Just what I needed, thanks!
  • Albert Jordan · 7 months ago
    Thanks a lot for this posting. It helped a lot getting clang to work.
  • jota · 6 months ago
    Also check on your Project info > Configurations tab (at the very bottom) that you are set to Debug in the "Command-line builds use:" option

    Nice article
  • banoidas · 5 months ago
    it s showing same : Code Signing Identity 'iPhone Developer' does not match any code-signing certificate in your keychain. Once added to the keychain, touch a file or clean the project to continue. i did same as u explained above.please help me to test
  • Rolf · 4 months ago
    i have installed the checker.. folder in my project - but scan-build does not start in the terminal ? Why
  • cmate · 4 months ago
    Is clang working for anyone else when analyzing a project that contains a 3.0 library such as MessageUI?

    I keep getting an error "MessageUI/MessageUI.h: No such file or directory".

    It builds fine if I just do an 'xcodebuild' or build within xcode.

    I have tried setting the basesdk for all to 2.2, and I have tried :

    scan-build -k -V xcodebuild -configuration Debug -sdk iphonesimulator2.2

    scan-build -k -V xcodebuild -configuration Debug -sdk iphonesimulator2.1

    scan-build -k -V xcodebuild -configuration Debug

    scan-build -k -V xcodebuild

    Doing some searches it seems like it may have to do witht the fact that this is a 3.0 library ?
  • cmate · 4 months ago
    I just found my own answer:

    THIS WORKED:

    scan-build -k -V xcodebuild -configuration Debug -sdk iphonesimulator3.0
  • Michael Adams · 1 month ago
    Hi,
    I had same problem, i.e. got error like:

    scan-build: Removing directory '/var/folders/x2/x2PXNw6pE7O8Zr7cBMzy1U+++TI/-Tmp-/scan-build-2009-04-10-1' because it contains no reports.

    After investigating it, in my case, this was happening because of either one of two reasons:

    Reason 1 - I had a compilation error in my code. When I fixed the compilation error then it worked.

    Reason 2 - The scan-build analysed my code and I had no actual errors.

    So in my case, while my code compiled and while I had memory leaks in my code, the analyser worked and I got the web page pop up with the results. Otherwise I got something like the error listed above in the terminal window.
  • nonoDream · 1 month ago
    scan-build -k -V xcodebuild
    -bash: scan-build: command not found