[PATCH] D55665: Output to SARIF from scan-build

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 13 12:21:26 PST 2018


aaron.ballman created this revision.
aaron.ballman added reviewers: NoQ, george.karpenkov.

This updates the scan-build perl script to allow outputting to sarif in a more natural fashion by specifying `-sarif` as a command line argument, similar to how `-plist` is already supported.

There appear to be no tests for scan-build, which is why you only see implementation files here. I tested locally by running test/Analysis/diagnostics/sarif-diagnostics-taint-test.c through scan-build and ensuring the results are expected for the generated temp directory.


https://reviews.llvm.org/D55665

Files:
  tools/scan-build/bin/scan-build
  tools/scan-build/libexec/ccc-analyzer


Index: tools/scan-build/libexec/ccc-analyzer
===================================================================
--- tools/scan-build/libexec/ccc-analyzer
+++ tools/scan-build/libexec/ccc-analyzer
@@ -746,9 +746,10 @@
 
     if (defined $OutputFormat) {
       push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat;
-      if ($OutputFormat =~ /plist/) {
+      if ($OutputFormat =~ /plist/ || $OutputFormat =~ /sarif/) {
         # Change "Output" to be a file.
-        my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist",
+        my $Suffix = $OutputFormat =~ /plist/ ? ".plist" : ".sarif";
+        my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => $Suffix,
                                DIR => $HtmlDir);
         $ResultFile = $f;
         # If the HtmlDir is not set, we should clean up the plist files.
Index: tools/scan-build/bin/scan-build
===================================================================
--- tools/scan-build/bin/scan-build
+++ tools/scan-build/bin/scan-build
@@ -1193,6 +1193,11 @@
 
    Display the description of defects in the list
 
+ -sarif
+
+  By default the output of scan-build is a set of HTML files. This option
+  outputs the results in SARIF format.
+ 
  -plist
 
    By default the output of scan-build is a set of HTML files. This option
@@ -1665,6 +1670,12 @@
       next;
     }
 
+    if ($arg eq "-sarif") {
+      shift @$Args;
+      $Options{OutputFormat} = "sarif";
+      next;
+    }
+
     if ($arg eq "-plist") {
       shift @$Args;
       $Options{OutputFormat} = "plist";
@@ -1888,9 +1899,12 @@
 	                        $Cmd, $CmdCXX, \%EnvVars);
 
 if (defined $Options{OutputFormat}) {
-  if ($Options{OutputFormat} =~ /plist/) {
+  if ($Options{OutputFormat} =~ /plist/ ||
+      $Options{OutputFormat} =~ /sarif/) {
     Diag "Analysis run complete.\n";
-    Diag "Analysis results (plist files) deposited in '$Options{OutputDir}'\n";
+    Diag "Analysis results (" .
+      ($Options{OutputFormat} =~ /plist/ ? "plist" : "sarif") .
+      " files) deposited in '$Options{OutputDir}'\n";
   }
   if ($Options{OutputFormat} =~ /html/) {
     # Postprocess the HTML directory.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55665.178115.patch
Type: text/x-patch
Size: 2152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181213/acaefd56/attachment-0001.bin>


More information about the cfe-commits mailing list