]> granicus.if.org Git - clang/commitdiff
[analyzer] SARIF: Add EOF newline; replace diff_sarif
authorHubert Tong <hubert.reinterpretcast@gmail.com>
Wed, 19 Jun 2019 15:27:35 +0000 (15:27 +0000)
committerHubert Tong <hubert.reinterpretcast@gmail.com>
Wed, 19 Jun 2019 15:27:35 +0000 (15:27 +0000)
Summary:
This patch applies a change similar to rC363069, but for SARIF files.

The `%diff_sarif` lit substitution invokes `diff` with a non-portable
`-I` option. The intended effect can be achieved by normalizing the
inputs to `diff` beforehand. Such normalization can be done with
`grep -Ev`, which is also used by other tests.

Additionally, this patch updates the SARIF output to have a newline at
the end of the file. This makes it so that the SARIF file qualifies as a
POSIX text file, which increases the consumability of the generated file
in relation to various tools.

Reviewers: NoQ, sfertile, xingxue, jasonliu, daltenty, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, Charusso, jsji, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62952

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363822 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
test/Analysis/diagnostics/sarif-diagnostics-taint-test.c
test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
test/Analysis/lit.local.cfg

index 4233f25edb349a898500bd35b3ffb9c328fdd5ac..d1faf3f4dea9d8091b70acfea6efdf660bd7111b 100644 (file)
@@ -345,5 +345,5 @@ void SarifDiagnostics::FlushDiagnosticsImpl(
        "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2018-11-28"},
       {"version", "2.0.0-csd.2.beta.2018-11-28"},
       {"runs", json::Array{createRun(Diags)}}};
-  OS << llvm::formatv("{0:2}", json::Value(std::move(Sarif)));
+  OS << llvm::formatv("{0:2}\n", json::Value(std::move(Sarif)));
 }
index af482a40c97a59593fca7751013d4bc793e7ca64..cebc817dec63fecd86993bfc73a5d13bbb5b46a8 100644 (file)
@@ -6,7 +6,7 @@
         {
           "fileLocation": {
           },
-          "length": 415,
+          "length": 434,
           "mimeType": "text/plain",
           "roles": [
             "resultFile"
index 4ce20e084349e624cd76f25384bd02dbc4e05230..f1527d4105d5799bcf250f3bca91ce60b4929f31 100644 (file)
@@ -6,7 +6,7 @@
         {
           "fileLocation": {
           },
-          "length": 667,
+          "length": 686,
           "mimeType": "text/plain",
           "roles": [
             "resultFile"
index 37ddc9df6a24493df3cedf6e4cfc72546c51d74e..b1042f9034d7d70edad0dc411db5d27e9d3fac68 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %diff_sarif %S/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif -
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif -
 #include "../Inputs/system-header-simulator.h"
 
 int atoi(const char *nptr);
index 459128a05fa0b974a32857a9e92da4c935ede88d..3402714a30ae736193d760c4550795273efc8ba2 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %diff_sarif %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
 #include "../Inputs/system-header-simulator.h"
 
 int atoi(const char *nptr);
index bfe4589438c2bf7bcf27d15cbabbce54c8e91c26..d6c0a370c7452f4cb3eefdf8f9ef64f755663f36 100644 (file)
@@ -17,9 +17,12 @@ config.substitutions.append(('%normalize_plist',
          '^[[:space:]]*<string>/.*</string>[[:space:]]*$',
          '^[[:space:]]*<string>.:.*</string>[[:space:]]*$')))
 
-# Diff command for testing SARIF output to reference output.
-config.substitutions.append(('%diff_sarif',
-    '''diff -U1 -w -I ".*file:.*%basename_t" -I '"version":' -I "2\.0\.0\-csd\.[0-9]*\.beta\."'''))
+# Filtering command for testing SARIF output against reference output.
+config.substitutions.append(('%normalize_sarif',
+    "grep -Ev '^[[:space:]]*(%s|%s|%s)[[:space:]]*$'" %
+        ('"uri": "file:.*%basename_t"',
+         '"version": ".* version .*"',
+         '"version": "2\.0\.0-csd\.[0-9]*\.beta\.[0-9-]{10}"')))
 
 if not config.root.clang_staticanalyzer:
     config.unsupported = True