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
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 'Xlang' command line
+# argument
+my @PluginLoadCommandline_xlang;
+foreach my $param ( @PluginsToLoad ) {
+  push ( @PluginLoadCommandline_xlang, "-Xlang" );
+  push ( @PluginLoadCommandline_xlang, $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_xlang, '--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;
@@ -1329,7 +1344,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 +1417,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