Hi Anna,
thanks for pointing that problem out. Indeed, "-Xlang" must be "-Xclang". I did test the "scan-build --help" functionality and the plugin checkers show up in the list of available checkers as expected.

However, the code in question checks for the checkers which are enabled by default ( in the clang compile). As plugin checkers are not enabled by default, I missed this problem.

To test the correct code, I temporarily added my custom plugin to lib/Driver/Tools.cpp as default and it now shows up as "enabled" as expected. In the course of this investigation, I discovered a possible bug in the scan-build code. Plugins which have a "nested" path ( like security.insecureAPI.getpw, enabled in Tools.cpp:1498 by default) are not correctly detected as enabled. Run "scan-build" and "security.insecureAPI.getpw" shows up, but without the "+" item to mark it is enabled as default.

I fixed both incidents in the patch attached to this mail.

Greetings,
Thomas

On 05/24/12 12:48, Anna Zaks wrote:
Thanks Thomas.

Did you test scan-build help?

+# create a list to load the plugins via the 'Xlang' command line
+# argument
+my @PluginLoadCommandline_xlang;
+foreach my $param ( @PluginsToLoad ) {
+  push ( @PluginLoadCommandline_xlang, "-Xlang" );
+  push ( @PluginLoadCommandline_xlang, $param );
+}

Shouldn't "Xlang" be "Xclang"?

Thanks,
Anna.

On May 24, 2012, at 6:43 AM, Thomas Hauth wrote:

Hello,
following the discussion on the clang list:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-May/021491.html

I prepared a patch to load custom plugins when running scan-build. This is 
useful when additional static analysis Checkers must be provided via clang's 
plugin interface.

Loading additional plugins can now be done via the scan-build call:
scan-build -load-plugin<plugin.so>

Please review the attached patch.

Thanks,
Thomas Hauth
<clang_patch_scan-build_plugins.diff>_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



--

------------------------------------------------------------------------
  Thomas Hauth
  CERN
  Office: 40 3 B20
  Telephone: +41 (0)22 76 71 557
------------------------------------------------------------------------
Index: tools/scan-build/ccc-analyzer
===================================================================
--- tools/scan-build/ccc-analyzer	(revision 157259)
+++ tools/scan-build/ccc-analyzer	(working copy)
@@ -434,6 +434,9 @@
 # Get the analysis options.
 my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'};
 
+# Get the plugins to load.
+my $Plugins = $ENV{'CCC_ANALYZER_PLUGINS'};
+
 # Get the store model.
 my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'};
 
@@ -649,6 +652,10 @@
       push @AnalyzeArgs, split '\s+', $Analyses;
     }
 
+    if (defined $Plugins) {
+      push @AnalyzeArgs, split '\s+', $Plugins;
+    }
+
     if (defined $OutputFormat) {
       push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat;
       if ($OutputFormat =~ /plist/) {
Index: tools/scan-build/scan-build
===================================================================
--- tools/scan-build/scan-build	(revision 157259)
+++ tools/scan-build/scan-build	(working copy)
@@ -36,6 +36,7 @@
 my $CurrentDir = HtmlEscape(getcwd());
 my $CurrentDirSuffix = basename($CurrentDir);
 
+my @PluginsToLoad;
 my $CmdArgs;
 
 my $HtmlTitle;
@@ -1017,9 +1018,23 @@
 
  -enable-checker [checker name]
  -disable-checker [checker name]
+ 
+LOADING CHECKERS:
+
+ Loading external checkers using the clang plugin interface:
+
+ -load-plugin [plugin library]
 ENDTEXT
 
 # Query clang for list of checkers that are enabled.
+
+# create a list to load the plugins via the 'Xclang' command line
+# argument
+my @PluginLoadCommandline_xclang;
+foreach my $param ( @PluginsToLoad ) {
+  push ( @PluginLoadCommandline_xclang, "-Xclang" );
+  push ( @PluginLoadCommandline_xclang, $param );
+}
 my %EnabledCheckers;
 foreach my $lang ("c", "objective-c", "objective-c++", "c++") {
   pipe(FROM_CHILD, TO_PARENT);
@@ -1028,7 +1043,7 @@
     close FROM_CHILD;
     open(STDOUT,">&", \*TO_PARENT);
     open(STDERR,">&", \*TO_PARENT);
-    exec $Clang, ('--analyze', '-x', $lang, '-', '-###');
+    exec $Clang, ( @PluginLoadCommandline_xclang, '--analyze', '-x', $lang, '-', '-###'); 
   }
   close(TO_PARENT);
   while(<FROM_CHILD>) {
@@ -1050,7 +1065,7 @@
   close FROM_CHILD;
   open(STDOUT,">&", \*TO_PARENT);
   open(STDERR,">&", \*TO_PARENT);
-  exec $Clang, ('-cc1', '-analyzer-checker-help');
+  exec $Clang, ('-cc1', @PluginsToLoad , '-analyzer-checker-help');
 }
 close(TO_PARENT);
 my $foundCheckers = 0;
@@ -1086,7 +1101,9 @@
         if ($EnabledCheckers{$aggregate}) {
           $enabled =1;
           last;
-        }        
+        }
+        # append a dot, if an additional domain is added in the next iteration
+        $aggregate .= ".";
       }
       
       if ($enabled) {
@@ -1329,7 +1346,12 @@
     push @AnalysesToRun, "-analyzer-disable-checker", shift @ARGV;
     next;
   }
-
+  if ($arg eq "-load-plugin") {
+    shift @ARGV;
+    push @PluginsToLoad, "-load", shift @ARGV;
+    next;
+  }
+  
   DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/);
   
   last;
@@ -1397,6 +1419,8 @@
 
 $ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun;
 
+$ENV{'CCC_ANALYZER_PLUGINS'} = join ' ',@PluginsToLoad;
+
 if (defined $StoreModel) {
   $ENV{'CCC_ANALYZER_STORE_MODEL'} = $StoreModel;
 }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to