C: Using the 'Clang Static Analyzer' with Eclipse
Thursday, 02 June 2011 21:51

Below are notes describing how to use the 'clang static analyzer' with Eclipse & CDT.

  • Start eclipse and create, or open, a C project.
  • Select, and right click, on your C Project in the 'Project Explorer'.
  • From the popup menu select 'Properties'.
  • In the 'Properties' dialog select 'C/C++ Build.
    • Un-select 'use default build command'.
    • Change the 'build command' from 'make' to 'scan-build make'.

  • In the 'Properties' dialog select 'C/C++ Build -> Settings.
    • Change the compiler from 'gcc' to '$(CC)'.

  • Rebuild your project.
    • Clang will report problems during the build as warnings. For example:
      "../main.c"
      ANALYZE: ../main.c foo
      ../main.c:11:2: warning: Undefined or garbage value returned to caller
              return retval;
              ^
      
    • Clang will also provide an html report for any problems found. The report is easily found from the last few lines of the build output:
      scan-build: 1 bugs found.
      scan-build: Run 'scan-view /tmp/scan-build-2011-06-02-10' to examine bug reports