Greg’s Online CS 193P Resources

May 10, 2009

Getting Clang to work – Hopefully

Filed under: cs 193p — gregorykaiser @ 11:23 pm
Tags:

Lecture #11 had a short section (look about 5:00 in) on using Clang to do static analysis of your projects to look for memory issues. It looked pretty easy so I downloaded Clang thinking I’d learn something about memory management by running it on some of my completed projects.

Edit : Make sure and use Clang version checker-0.199 or above if you see an #error “SSE instruction set not enabled” when you run Clang.

Note from Clang Website: Look at all of Clang’s suggestions but before you make them be sure you understand them as there are false positives.

To run Clang you:
1. Download, Unzip and Move the resulting directory to where you want it installed (I used /Developer/Application/checker) I renamed the checker directory to remove the version number).
2. Open a terminal window and create a “.bash_profile” in your home directory (“cd ~” to get there and for instance “pico .bash_profile” to edit the file) with the line

export PATH=$PATH:/Developer/Applications/checker

then stop the terminal and restart it to pick up the new PATH.

3. Open a project in Xcode. Follow the instructions on this site (look for the “iPhone Usage” section) to verify that you will build for a Simulator project with no Code Signing. Then Build>Clean your project. You must repeat this “Clean”each time before you run Clang

4. In a Terminal “cd” into your project directory then run Clang with the line below. You do not seem to need the simulator parameter the class video uses.

scan-build -k -V xcodebuild -configuration Debug

5. With any luck Clang will scroll a lot of text and then pop up Safari with its results. If only a few lines appear in your terminal you probably forgot to “Clean” your project before running Clang. If you have no error try adding this code inside -viewDidRun

BOOL maybe;
if (maybe) {
}
else {
}

6. If everything works you will see a message like “ANALYZE: /Users/…/TryClang2/Classes/TryClang2ViewController.m dealloc” appear and then at the end

** BUILD SUCCEEDED **
scan-build: 2 bugs found.
scan-build: Run ‘scan-view /var/folders/Ck/Cklnad2tHayb4iUB6fuC0U+++TQ/-Tmp-/scan-build-2009-05-10-8’ to examine bug reports.
scan-build: Analysis run complete.
scan-build: Viewing analysis results in ‘/var/folders/Ck/Cklnad2tHayb4iUB6fuC0U+++TQ/-Tmp-/scan-build-2009-05-10-8’ using scan-view.
Starting scan-view at: http://127.0.0.1:8181
Use Ctrl-C to exit.
^C

7. I always get an message at the end of the Clang window showing there are no results. Something in my system is causing C compile errors in the SDK (#error “SSE instruction set not enabled”) which prevents the Clang analysis from running. If anyone else has this problem or figures it out please tell me!

** BUILD SUCCEEDED **
scan-build: Removing directory ‘/var/folders/2A/2Afvq+53GuGI5j19hXiDck+++TI/-Tmp-/scan-build-2009-05-10-1’ because it contains no reports.

Note: If you output the Clang command to a text file and then look at it you will see Clang Does 1 “Processing …” , then it “CompileXIB …” your .xib files, and finally it “CompileC ..” each of your project’s source files. After each Compile… it will “ANALYZE” the file.

Advertisements

6 Comments »

  1. The “SSE instruction set not enabled” error should now be fixed in checker-0.199 and higher.

    Comment by Ted Kremenek — May 11, 2009 @ 2:36 am | Reply

    • I just downloaded Check-0.199 and Clang now works on my machine! Thanks so much Ted

      Comment by gregorykaiser — May 11, 2009 @ 3:02 am | Reply

  2. So I’m getting these errors you mentioned in section 7:

    7. I always get an message at the end of the Clang window showing there are no results. Something in my system is causing C compile errors in the SDK (#error “SSE instruction set not enabled”) which prevents the Clang analysis from running. If anyone else has this problem or figures it out please tell me!

    ** BUILD SUCCEEDED **
    scan-build: Removing directory ‘/var/folders/2A/2Afvq+53GuGI5j19hXiDck+++TI/-Tmp-/scan-build-2009-05-10-1′ because it contains no reports.

    How did yo fix these?

    Comment by AM — May 11, 2009 @ 4:46 pm | Reply

    • No you’re right. checker-0.200 available here http://checker.minormatter.com/checker-0.200.tar.bz2 fixed it.

      Comment by AM — May 11, 2009 @ 4:50 pm | Reply

    • I got the empty results error for three reasons

      1. The Clang version was broken. Solution: Make sure and download 0.199 or greater (for me 0.196 was broken and 0.199 worked).
      2. You have to build for simulator, Debug, no code signing. Look at the blog entry pointed to in step 3. Make sure you have edited the Project settings and verify they really took effect.
      3. You have no errors in your code for Clang to find. Make sure and include something for Clang to find while you are getting things working (try the code in step #5).

      The SSE error stuff seems to come from a broken Clang version. Make sure you are really running a good version. It does not print a version in the output so make sure you have the correct version downloaded and that your PATH points to it.

      What version are you running?

      Greg

      Comment by gregorykaiser — May 11, 2009 @ 5:02 pm | Reply

  3. Running 0.211 and I am getting the “scan-build: Removing directory … because it contains no reports.” error.

    It also complains about this:

    2009-07-01 10:34:05.838 xcodebuild[57087:613] warning: compiler ‘com.apple.compilers.llvm.clang.1_0.analyzer’ is based on missing compiler ‘com.apple.compilers.llvm.clang.1_0.analyzer’

    … which seems suspicious.

    Running on simulator, debug, no code signing.

    Any ideas?

    Thanos

    Comment by Thanos — July 1, 2009 @ 5:35 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.