r363822 - [analyzer] SARIF: Add EOF newline; replace diff_sarif
Hubert Tong via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 19 08:27:35 PDT 2019
Author: hubert.reinterpretcast
Date: Wed Jun 19 08:27:35 2019
New Revision: 363822
URL: http://llvm.org/viewvc/llvm-project?rev=363822&view=rev
Log:
[analyzer] SARIF: Add EOF newline; replace diff_sarif
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
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
cfe/trunk/test/Analysis/diagnostics/sarif-diagnostics-taint-test.c
cfe/trunk/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
cfe/trunk/test/Analysis/lit.local.cfg
Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp?rev=363822&r1=363821&r2=363822&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp Wed Jun 19 08:27:35 2019
@@ -345,5 +345,5 @@ void SarifDiagnostics::FlushDiagnosticsI
"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)));
}
Modified: cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif?rev=363822&r1=363821&r2=363822&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif (original)
+++ cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif Wed Jun 19 08:27:35 2019
@@ -6,7 +6,7 @@
{
"fileLocation": {
},
- "length": 415,
+ "length": 434,
"mimeType": "text/plain",
"roles": [
"resultFile"
Modified: cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif?rev=363822&r1=363821&r2=363822&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif (original)
+++ cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif Wed Jun 19 08:27:35 2019
@@ -6,7 +6,7 @@
{
"fileLocation": {
},
- "length": 667,
+ "length": 686,
"mimeType": "text/plain",
"roles": [
"resultFile"
Modified: cfe/trunk/test/Analysis/diagnostics/sarif-diagnostics-taint-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/sarif-diagnostics-taint-test.c?rev=363822&r1=363821&r2=363822&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/sarif-diagnostics-taint-test.c (original)
+++ cfe/trunk/test/Analysis/diagnostics/sarif-diagnostics-taint-test.c Wed Jun 19 08:27:35 2019
@@ -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);
Modified: cfe/trunk/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c?rev=363822&r1=363821&r2=363822&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c (original)
+++ cfe/trunk/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c Wed Jun 19 08:27:35 2019
@@ -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);
Modified: cfe/trunk/test/Analysis/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/lit.local.cfg?rev=363822&r1=363821&r2=363822&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/lit.local.cfg (original)
+++ cfe/trunk/test/Analysis/lit.local.cfg Wed Jun 19 08:27:35 2019
@@ -17,9 +17,12 @@ config.substitutions.append(('%normalize
'^[[: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
More information about the cfe-commits
mailing list