[analyzer] Loading external plugins with scan-build

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>

A patch by Thomas Hauth.

llvm-svn: 157452
This commit is contained in:
Anna Zaks 2012-05-25 01:13:50 +00:00
parent 8e705852b7
commit 268f154f48
2 changed files with 35 additions and 4 deletions

View File

@ -434,6 +434,9 @@ if ($Status) { exit($Status >> 8); }
# 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 @@ if ($Action eq 'compile' or $Action eq 'link') {
push @AnalyzeArgs, split '\s+', $Analyses;
}
if (defined $Plugins) {
push @AnalyzeArgs, split '\s+', $Plugins;
}
if (defined $OutputFormat) {
push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat;
if ($OutputFormat =~ /plist/) {

View File

@ -36,6 +36,7 @@ my $HostName = HtmlEscape(hostname() || 'unknown');
my $CurrentDir = HtmlEscape(getcwd());
my $CurrentDirSuffix = basename($CurrentDir);
my @PluginsToLoad;
my $CmdArgs;
my $HtmlTitle;
@ -1032,9 +1033,23 @@ CONTROLLING CHECKERS:
-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);
@ -1043,7 +1058,7 @@ foreach my $lang ("c", "objective-c", "objective-c++", "c++") {
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>) {
@ -1065,7 +1080,7 @@ if ($pid == 0) {
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;
@ -1101,7 +1116,9 @@ else {
if ($EnabledCheckers{$aggregate}) {
$enabled =1;
last;
}
}
# append a dot, if an additional domain is added in the next iteration
$aggregate .= ".";
}
if ($enabled) {
@ -1344,7 +1361,12 @@ while (@ARGV) {
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;
@ -1412,6 +1434,8 @@ if ($MaxLoop > 0) {
$ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun;
$ENV{'CCC_ANALYZER_PLUGINS'} = join ' ',@PluginsToLoad;
if (defined $StoreModel) {
$ENV{'CCC_ANALYZER_STORE_MODEL'} = $StoreModel;
}