+++ /dev/null
-//===- CrossTUAnalysisHelper.h - Abstraction layer for CTU ------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
-#define LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
-
-#include "llvm/ADT/Optional.h"
-#include "clang/Basic/SourceManager.h"
-
-namespace clang {
-
-class ASTUnit;
-
-/// This class is an abstract interface acting as a bridge between
-/// an analysis that requires lookups across translation units (a user
-/// of that interface) and the facility that implements such lookups
-/// (an implementation of that interface). This is useful to break direct
-/// link-time dependencies between the (possibly shared) libraries in which
-/// the user and the implementation live.
-class CrossTUAnalysisHelper {
-public:
- /// Determine the original source location in the original TU for an
- /// imported source location.
- /// \p ToLoc Source location in the imported-to AST.
- /// \return Source location in the imported-from AST and the corresponding
- /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit
- /// object that is returned here).
- /// If any error happens (ToLoc is a non-imported source location) empty is
- /// returned.
- virtual llvm::Optional<std::pair<SourceLocation /*FromLoc*/, Preprocessor *>>
- getImportedFromSourceLocationWithPreprocessor(SourceLocation ToLoc) const = 0;
-
- virtual ~CrossTUAnalysisHelper() {}
-};
-} // namespace clang
-
-#endif // LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
+++ /dev/null
-//===-- PathDiagnosticConsumers.def - Visualizing warnings ------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the set of path diagnostic consumers - objects that
-// implement different representations of static analysis results.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef ANALYSIS_DIAGNOSTICS
-#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)
-#endif
-
-ANALYSIS_DIAGNOSTICS(HTML, "html", "Output analysis results using HTML",
- createHTMLDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(
- HTML_SINGLE_FILE, "html-single-file",
- "Output analysis results using HTML (not allowing for multi-file bugs)",
- createHTMLSingleFileDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(PLIST, "plist", "Output analysis results using Plists",
- createPlistDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(
- PLIST_MULTI_FILE, "plist-multi-file",
- "Output analysis results using Plists (allowing for multi-file bugs)",
- createPlistMultiFileDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(PLIST_HTML, "plist-html",
- "Output analysis results using HTML wrapped with Plists",
- createPlistHTMLDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(SARIF, "sarif", "Output analysis results in a SARIF file",
- createSarifDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(TEXT, "text", "Text output of analysis results to stderr",
- createTextPathDiagnosticConsumer)
-
-ANALYSIS_DIAGNOSTICS(TEXT_MINIMAL, "text-minimal",
- "Emits minimal diagnostics to stderr, stating only the "
- "warning message and the associated notes. Usually "
- "used in addition to other analysis types",
- createTextMinimalPathDiagnosticConsumer)
-
-#undef ANALYSIS_DIAGNOSTICS
#ifndef LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
#define LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
-#include "clang/Analysis/CrossTUAnalysisHelper.h"
#include "clang/AST/ASTImporterSharedState.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMap.h"
/// the locations of the AST files for each definition.
///
/// Note that this class also implements caching.
-class CrossTranslationUnitContext : public CrossTUAnalysisHelper {
+class CrossTranslationUnitContext {
public:
CrossTranslationUnitContext(CompilerInstance &CI);
- ~CrossTranslationUnitContext() override;
+ ~CrossTranslationUnitContext();
/// This function loads a function or variable definition from an
/// external AST file and merges it into the original AST.
/// imported source location.
/// \p ToLoc Source location in the imported-to AST.
/// \return Source location in the imported-from AST and the corresponding
- /// ASTUnit object (the AST was loaded from a file using an internal ASTUni
+ /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit
/// object that is returned here).
/// If any error happens (ToLoc is a non-imported source location) empty is
/// returned.
llvm::Optional<std::pair<SourceLocation /*FromLoc*/, ASTUnit *>>
- getImportedFromSourceLocation(SourceLocation ToLoc) const;
-
- /// Determine the original source location in the original TU for an
- /// imported source location.
- /// \p ToLoc Source location in the imported-to AST.
- /// \return Source location in the imported-from AST and the Preprocessor
- /// corresponding to the AST unit that originally contained the imported-from
- /// source location.
- /// If any error happens (ToLoc is a non-imported source location) empty is
- /// returned.
- llvm::Optional<std::pair<SourceLocation /*FromLoc*/, Preprocessor *>>
- getImportedFromSourceLocationWithPreprocessor(
- SourceLocation ToLoc) const override;
+ getImportedFromSourceLocation(const clang::SourceLocation &ToLoc) const;
private:
using ImportedFileIDMap =
ANALYSIS_CONSTRAINTS(Z3Constraints, "z3", "Use Z3 contraint solver",
CreateZ3ConstraintManager)
+#ifndef ANALYSIS_DIAGNOSTICS
+#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)
+#endif
+
+ANALYSIS_DIAGNOSTICS(HTML, "html", "Output analysis results using HTML",
+ createHTMLDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(
+ HTML_SINGLE_FILE, "html-single-file",
+ "Output analysis results using HTML (not allowing for multi-file bugs)",
+ createHTMLSingleFileDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(PLIST, "plist", "Output analysis results using Plists",
+ createPlistDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(
+ PLIST_MULTI_FILE, "plist-multi-file",
+ "Output analysis results using Plists (allowing for multi-file bugs)",
+ createPlistMultiFileDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(PLIST_HTML, "plist-html",
+ "Output analysis results using HTML wrapped with Plists",
+ createPlistHTMLDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(SARIF, "sarif", "Output analysis results in a SARIF file",
+ createSarifDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(TEXT, "text", "Text output of analysis results to stderr",
+ createTextPathDiagnosticConsumer)
+
+ANALYSIS_DIAGNOSTICS(TEXT_MINIMAL, "text-minimal",
+ "Emits minimal diagnostics to stderr, stating only the "
+ "warning message and the associated notes. Usually "
+ "used in addition to other analysis types",
+ createTextMinimalPathDiagnosticConsumer)
+
#ifndef ANALYSIS_PURGE
#define ANALYSIS_PURGE(NAME, CMDFLAG, DESC)
#endif
#undef ANALYSIS_STORE
#undef ANALYSIS_CONSTRAINTS
+#undef ANALYSIS_DIAGNOSTICS
#undef ANALYSIS_PURGE
#undef ANALYSIS_INLINING_MODE
#undef ANALYSIS_IPA
/// analysis results.
enum AnalysisDiagClients {
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) PD_##NAME,
-#include "clang/Analysis/PathDiagnosticConsumers.def"
+#include "clang/StaticAnalyzer/Core/Analyses.def"
PD_NONE,
NUM_ANALYSIS_DIAG_CLIENTS
};
#include <string>
#include <vector>
-#include "clang/Analysis/PathDiagnostic.h"
-
namespace clang {
class AnalyzerOptions;
class Preprocessor;
-class CrossTUAnalysisHelper;
+namespace cross_tu {
+class CrossTranslationUnitContext;
+}
namespace ento {
class PathDiagnosticConsumer;
-typedef std::vector<PathDiagnosticConsumer *> PathDiagnosticConsumers;
+typedef std::vector<PathDiagnosticConsumer*> PathDiagnosticConsumers;
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) \
void CREATEFN(PathDiagnosticConsumerOptions Diagopts, \
PathDiagnosticConsumers &C, const std::string &Prefix, \
- const Preprocessor &PP, const CrossTUAnalysisHelper &CTU);
-#include "clang/Analysis/PathDiagnosticConsumers.def"
+ const Preprocessor &PP, \
+ const cross_tu::CrossTranslationUnitContext &CTU);
+#include "clang/StaticAnalyzer/Core/Analyses.def"
} // end 'ento' namespace
} // end 'clang' namespace
#include "clang/Analysis/AnalysisDeclContext.h"
#include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
namespace clang {
umbrella "Analysis"
textual header "Analysis/Analyses/ThreadSafetyOps.def"
- textual header "Analysis/PathDiagnosticConsumers.def"
module * { export * }
CodeInjector.cpp
Dominators.cpp
ExprMutationAnalyzer.cpp
- HTMLPathDiagnosticConsumer.cpp
IssueHash.cpp
LiveVariables.cpp
ObjCNoReturn.cpp
PathDiagnostic.cpp
- PlistPathDiagnosticConsumer.cpp
- PlistHTMLPathDiagnosticConsumer.cpp
PostOrderCFGView.cpp
ProgramPoint.cpp
ReachableCode.cpp
RetainSummaryManager.cpp
- SarifPathDiagnosticConsumer.cpp
- TextPathDiagnosticConsumer.cpp
ThreadSafety.cpp
ThreadSafetyCommon.cpp
ThreadSafetyLogical.cpp
clangASTMatchers
clangBasic
clangLex
- clangRewrite
- clangToolingCore
DEPENDS
omp_gen
+++ /dev/null
-//===--- PlistHTMLDiagnostics.cpp - The Plist-HTML Diagnostic Consumer. ---===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This diagnostic consumer produces both the HTML output and the Plist output.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Lex/Preprocessor.h"
-#include "llvm/Support/Path.h"
-
-using namespace clang;
-using namespace ento;
-
-namespace clang {
-class CrossTUAnalysisHelper;
-}
-
-void ento::createPlistHTMLDiagnosticConsumer(
- PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
- const std::string &Prefix, const Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU) {
- createHTMLDiagnosticConsumer(
- DiagOpts, C, std::string(llvm::sys::path::parent_path(Prefix)), PP, CTU);
- createPlistMultiFileDiagnosticConsumer(DiagOpts, C, Prefix, PP, CTU);
- createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, Prefix, PP,
- CTU);
-}
llvm::Optional<std::pair<SourceLocation, ASTUnit *>>
CrossTranslationUnitContext::getImportedFromSourceLocation(
- SourceLocation ToLoc) const {
+ const clang::SourceLocation &ToLoc) const {
const SourceManager &SM = Context.getSourceManager();
auto DecToLoc = SM.getDecomposedLoc(ToLoc);
return std::make_pair(FromLoc, Unit);
}
-llvm::Optional<std::pair<SourceLocation, Preprocessor *>>
-CrossTranslationUnitContext::getImportedFromSourceLocationWithPreprocessor(
- SourceLocation ToLoc) const {
- if (llvm::Optional<std::pair<SourceLocation, ASTUnit *>> LocAndUnit =
- getImportedFromSourceLocation(ToLoc)) {
- return std::make_pair(LocAndUnit->first,
- &LocAndUnit->second->getPreprocessor());
- }
- return None;
-}
-
} // namespace cross_tu
} // namespace clang
AnalysisDiagClients Value = llvm::StringSwitch<AnalysisDiagClients>(Name)
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) \
.Case(CMDFLAG, PD_##NAME)
-#include "clang/Analysis/PathDiagnosticConsumers.def"
+#include "clang/StaticAnalyzer/Core/Analyses.def"
.Default(NUM_ANALYSIS_DIAG_CLIENTS);
if (Value == NUM_ANALYSIS_DIAG_CLIENTS) {
Diags.Report(diag::err_drv_invalid_value)
ExprEngineCallAndReturn.cpp
ExprEngineObjC.cpp
FunctionSummary.cpp
+ HTMLDiagnostics.cpp
LoopUnrolling.cpp
LoopWidening.cpp
MemRegion.cpp
+ PlistDiagnostics.cpp
ProgramState.cpp
RangeConstraintManager.cpp
RangedConstraintManager.cpp
RegionStore.cpp
+ SarifDiagnostics.cpp
SimpleConstraintManager.cpp
SimpleSValBuilder.cpp
SMTConstraintManager.cpp
SValBuilder.cpp
SVals.cpp
SymbolManager.cpp
+ TextDiagnostics.cpp
WorkList.cpp
LINK_LIBS
-//===- HTMLPathDiagnosticConsumer.cpp - HTML Diagnostics for Paths --------===//
+//===- HTMLDiagnostics.cpp - HTML Diagnostics for Paths -------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//
//
-// This file defines the HTMLPathDiagnosticConsumer object.
+// This file defines the HTMLDiagnostics object.
//
//===----------------------------------------------------------------------===//
#include "clang/Analysis/IssueHash.h"
#include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/Stmt.h"
#include "clang/Lex/Token.h"
#include "clang/Rewrite/Core/HTMLRewrite.h"
#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
using namespace clang;
using namespace ento;
-namespace clang {
-class CrossTUAnalysisHelper;
-}
-
//===----------------------------------------------------------------------===//
// Boilerplate.
//===----------------------------------------------------------------------===//
namespace {
-class HTMLPathDiagnosticConsumer : public PathDiagnosticConsumer {
+class HTMLDiagnostics : public PathDiagnosticConsumer {
PathDiagnosticConsumerOptions DiagOpts;
std::string Directory;
bool createdDir = false;
const bool SupportsCrossFileDiagnostics;
public:
- HTMLPathDiagnosticConsumer(PathDiagnosticConsumerOptions DiagOpts,
- const std::string &OutputDir,
- const Preprocessor &PP, bool SupportsMultipleFiles)
- : DiagOpts(std::move(DiagOpts)), Directory(OutputDir), PP(PP),
- SupportsCrossFileDiagnostics(SupportsMultipleFiles) {}
+ HTMLDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
+ const std::string &OutputDir, const Preprocessor &pp,
+ bool supportsMultipleFiles)
+ : DiagOpts(std::move(DiagOpts)), Directory(OutputDir), PP(pp),
+ SupportsCrossFileDiagnostics(supportsMultipleFiles) {}
- ~HTMLPathDiagnosticConsumer() override { FlushDiagnostics(nullptr); }
+ ~HTMLDiagnostics() override { FlushDiagnostics(nullptr); }
void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
FilesMade *filesMade) override;
- StringRef getName() const override { return "HTMLPathDiagnosticConsumer"; }
+ StringRef getName() const override {
+ return "HTMLDiagnostics";
+ }
bool supportsCrossFileDiagnostics() const override {
return SupportsCrossFileDiagnostics;
void ento::createHTMLDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputDir, const Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU) {
+ const cross_tu::CrossTranslationUnitContext &CTU) {
// FIXME: HTML is currently our default output type, but if the output
// directory isn't specified, it acts like if it was in the minimal text
if (OutputDir.empty())
return;
- C.push_back(
- new HTMLPathDiagnosticConsumer(std::move(DiagOpts), OutputDir, PP, true));
+ C.push_back(new HTMLDiagnostics(std::move(DiagOpts), OutputDir, PP, true));
}
void ento::createHTMLSingleFileDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputDir, const Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU) {
+ const cross_tu::CrossTranslationUnitContext &CTU) {
createTextMinimalPathDiagnosticConsumer(DiagOpts, C, OutputDir, PP, CTU);
// TODO: Emit an error here.
if (OutputDir.empty())
return;
- C.push_back(new HTMLPathDiagnosticConsumer(std::move(DiagOpts), OutputDir, PP,
- false));
+ C.push_back(new HTMLDiagnostics(std::move(DiagOpts), OutputDir, PP, false));
+}
+
+void ento::createPlistHTMLDiagnosticConsumer(
+ PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+ const std::string &prefix, const Preprocessor &PP,
+ const cross_tu::CrossTranslationUnitContext &CTU) {
+ createHTMLDiagnosticConsumer(
+ DiagOpts, C, std::string(llvm::sys::path::parent_path(prefix)), PP,
+ CTU);
+ createPlistMultiFileDiagnosticConsumer(DiagOpts, C, prefix, PP, CTU);
+ createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, prefix, PP,
+ CTU);
}
//===----------------------------------------------------------------------===//
// Report processing.
//===----------------------------------------------------------------------===//
-void HTMLPathDiagnosticConsumer::FlushDiagnosticsImpl(
- std::vector<const PathDiagnostic *> &Diags, FilesMade *filesMade) {
+void HTMLDiagnostics::FlushDiagnosticsImpl(
+ std::vector<const PathDiagnostic *> &Diags,
+ FilesMade *filesMade) {
for (const auto Diag : Diags)
ReportDiag(*Diag, filesMade);
}
-void HTMLPathDiagnosticConsumer::ReportDiag(const PathDiagnostic &D,
- FilesMade *filesMade) {
+void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
+ FilesMade *filesMade) {
// Create the HTML directory if it is missing.
if (!createdDir) {
createdDir = true;
os << report;
}
-std::string HTMLPathDiagnosticConsumer::GenerateHTML(const PathDiagnostic &D,
- Rewriter &R,
- const SourceManager &SMgr,
- const PathPieces &path,
- const char *declName) {
+std::string HTMLDiagnostics::GenerateHTML(const PathDiagnostic& D, Rewriter &R,
+ const SourceManager& SMgr, const PathPieces& path, const char *declName) {
// Rewrite source files as HTML for every new file the path crosses
std::vector<FileID> FileIDs;
for (auto I : path) {
return os.str();
}
-void HTMLPathDiagnosticConsumer::dumpCoverageData(
- const PathDiagnostic &D, const PathPieces &path,
+void HTMLDiagnostics::dumpCoverageData(
+ const PathDiagnostic &D,
+ const PathPieces &path,
llvm::raw_string_ostream &os) {
const FilesToLineNumsMap &ExecutedLines = D.getExecutedLines();
os << "};";
}
-std::string HTMLPathDiagnosticConsumer::showRelevantLinesJavascript(
- const PathDiagnostic &D, const PathPieces &path) {
+std::string HTMLDiagnostics::showRelevantLinesJavascript(
+ const PathDiagnostic &D, const PathPieces &path) {
std::string s;
llvm::raw_string_ostream os(s);
os << "<script type='text/javascript'>\n";
return os.str();
}
-void HTMLPathDiagnosticConsumer::FinalizeHTML(
- const PathDiagnostic &D, Rewriter &R, const SourceManager &SMgr,
- const PathPieces &path, FileID FID, const FileEntry *Entry,
- const char *declName) {
+void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R,
+ const SourceManager& SMgr, const PathPieces& path, FileID FID,
+ const FileEntry *Entry, const char *declName) {
// This is a cludge; basically we want to append either the full
// working directory if we have no directory information. This is
// a work in progress.
html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName());
}
-StringRef HTMLPathDiagnosticConsumer::showHelpJavascript() {
+StringRef HTMLDiagnostics::showHelpJavascript() {
return R"<<<(
<script type='text/javascript'>
}
}
-void HTMLPathDiagnosticConsumer::RewriteFile(Rewriter &R,
- const PathPieces &path,
- FileID FID) {
+void HTMLDiagnostics::RewriteFile(Rewriter &R,
+ const PathPieces& path, FileID FID) {
// Process the path.
// Maintain the counts of extra note pieces separately.
unsigned TotalPieces = path.size();
html::HighlightMacros(R, FID, PP);
}
-void HTMLPathDiagnosticConsumer::HandlePiece(
- Rewriter &R, FileID BugFileID, const PathDiagnosticPiece &P,
- const std::vector<SourceRange> &PopUpRanges, unsigned num, unsigned max) {
+void HTMLDiagnostics::HandlePiece(Rewriter &R, FileID BugFileID,
+ const PathDiagnosticPiece &P,
+ const std::vector<SourceRange> &PopUpRanges,
+ unsigned num, unsigned max) {
// For now, just draw a box above the line in question, and emit the
// warning.
FullSourceLoc Pos = P.getLocation().asLocation();
os << char('a' + x);
}
-unsigned HTMLPathDiagnosticConsumer::ProcessMacroPiece(
- raw_ostream &os, const PathDiagnosticMacroPiece &P, unsigned num) {
+unsigned HTMLDiagnostics::ProcessMacroPiece(raw_ostream &os,
+ const PathDiagnosticMacroPiece& P,
+ unsigned num) {
for (const auto &subPiece : P.subPieces) {
if (const auto *MP = dyn_cast<PathDiagnosticMacroPiece>(subPiece.get())) {
num = ProcessMacroPiece(os, *MP, num);
return num;
}
-void HTMLPathDiagnosticConsumer::HighlightRange(Rewriter &R, FileID BugFileID,
- SourceRange Range,
- const char *HighlightStart,
- const char *HighlightEnd) {
+void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
+ SourceRange Range,
+ const char *HighlightStart,
+ const char *HighlightEnd) {
SourceManager &SM = R.getSourceMgr();
const LangOptions &LangOpts = R.getLangOpts();
html::HighlightRange(R, InstantiationStart, E, HighlightStart, HighlightEnd);
}
-StringRef HTMLPathDiagnosticConsumer::generateKeyboardNavigationJavascript() {
+StringRef HTMLDiagnostics::generateKeyboardNavigationJavascript() {
return R"<<<(
<script type='text/javascript'>
var digitMatcher = new RegExp("[0-9]+");
-//===--- PlistPathDiagnosticConsumer.cpp - Plist Diagnostics ----*- C++ -*-===//
+//===--- PlistDiagnostics.cpp - Plist Diagnostics for Paths -----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//
//
-// This file defines the PlistPathDiagnosticConsumer object.
+// This file defines the PlistDiagnostics object.
//
//===----------------------------------------------------------------------===//
-#include "clang/Analysis/CrossTUAnalysisHelper.h"
#include "clang/Analysis/IssueHash.h"
#include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/PlistSupport.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Version.h"
+#include "clang/CrossTU/CrossTranslationUnit.h"
+#include "clang/Frontend/ASTUnit.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/TokenConcatenation.h"
#include "clang/Rewrite/Core/HTMLRewrite.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
//===----------------------------------------------------------------------===//
namespace {
- class PlistPathDiagnosticConsumer : public PathDiagnosticConsumer {
+ class PlistDiagnostics : public PathDiagnosticConsumer {
PathDiagnosticConsumerOptions DiagOpts;
const std::string OutputFile;
const Preprocessor &PP;
- const CrossTUAnalysisHelper &CTU;
+ const cross_tu::CrossTranslationUnitContext &CTU;
const bool SupportsCrossFileDiagnostics;
void printBugPath(llvm::raw_ostream &o, const FIDMap &FM,
const PathPieces &Path);
public:
- PlistPathDiagnosticConsumer(PathDiagnosticConsumerOptions DiagOpts,
+ PlistDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
const std::string &OutputFile, const Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU,
+ const cross_tu::CrossTranslationUnitContext &CTU,
bool supportsMultipleFiles);
- ~PlistPathDiagnosticConsumer() override {}
+ ~PlistDiagnostics() override {}
void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
FilesMade *filesMade) override;
StringRef getName() const override {
- return "PlistPathDiagnosticConsumer";
+ return "PlistDiagnostics";
}
PathGenerationScheme getGenerationScheme() const override {
class PlistPrinter {
const FIDMap& FM;
const Preprocessor &PP;
- const CrossTUAnalysisHelper &CTU;
+ const cross_tu::CrossTranslationUnitContext &CTU;
llvm::SmallVector<const PathDiagnosticMacroPiece *, 0> MacroPieces;
public:
PlistPrinter(const FIDMap& FM,
const Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU)
+ const cross_tu::CrossTranslationUnitContext &CTU)
: FM(FM), PP(PP), CTU(CTU) {
}
static ExpansionInfo
getExpandedMacro(SourceLocation MacroLoc, const Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU);
+ const cross_tu::CrossTranslationUnitContext &CTU);
//===----------------------------------------------------------------------===//
// Methods of PlistPrinter.
}
//===----------------------------------------------------------------------===//
-// Methods of PlistPathDiagnosticConsumer.
+// Methods of PlistDiagnostics.
//===----------------------------------------------------------------------===//
-PlistPathDiagnosticConsumer::PlistPathDiagnosticConsumer(
+PlistDiagnostics::PlistDiagnostics(
PathDiagnosticConsumerOptions DiagOpts, const std::string &output,
- const Preprocessor &PP, const CrossTUAnalysisHelper &CTU,
+ const Preprocessor &PP, const cross_tu::CrossTranslationUnitContext &CTU,
bool supportsMultipleFiles)
: DiagOpts(std::move(DiagOpts)), OutputFile(output), PP(PP), CTU(CTU),
SupportsCrossFileDiagnostics(supportsMultipleFiles) {
void ento::createPlistDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputFile, const Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU) {
+ const cross_tu::CrossTranslationUnitContext &CTU) {
// TODO: Emit an error here.
if (OutputFile.empty())
return;
- C.push_back(new PlistPathDiagnosticConsumer(DiagOpts, OutputFile, PP, CTU,
- /*supportsMultipleFiles=*/false));
+ C.push_back(new PlistDiagnostics(DiagOpts, OutputFile, PP, CTU,
+ /*supportsMultipleFiles=*/false));
createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, OutputFile,
PP, CTU);
}
void ento::createPlistMultiFileDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputFile, const Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU) {
+ const cross_tu::CrossTranslationUnitContext &CTU) {
// TODO: Emit an error here.
if (OutputFile.empty())
return;
- C.push_back(new PlistPathDiagnosticConsumer(DiagOpts, OutputFile, PP, CTU,
- /*supportsMultipleFiles=*/true));
+ C.push_back(new PlistDiagnostics(DiagOpts, OutputFile, PP, CTU,
+ /*supportsMultipleFiles=*/true));
createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, OutputFile,
PP, CTU);
}
-void PlistPathDiagnosticConsumer::printBugPath(llvm::raw_ostream &o,
- const FIDMap &FM,
- const PathPieces &Path) {
+void PlistDiagnostics::printBugPath(llvm::raw_ostream &o, const FIDMap &FM,
+ const PathPieces &Path) {
PlistPrinter Printer(FM, PP, CTU);
assert(std::is_partitioned(Path.begin(), Path.end(),
[](const PathDiagnosticPieceRef &E) {
o << " </array>\n";
}
-void PlistPathDiagnosticConsumer::FlushDiagnosticsImpl(
- std::vector<const PathDiagnostic *> &Diags, FilesMade *filesMade) {
+void PlistDiagnostics::FlushDiagnosticsImpl(
+ std::vector<const PathDiagnostic *> &Diags,
+ FilesMade *filesMade) {
// Build up a set of FIDs that we use by scanning the locations and
// ranges of the diagnostics.
FIDMap FM;
static ExpansionInfo
getExpandedMacro(SourceLocation MacroLoc, const Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU) {
+ const cross_tu::CrossTranslationUnitContext &CTU) {
const Preprocessor *PPToUse = &PP;
- if (auto LocAndUnit =
- CTU.getImportedFromSourceLocationWithPreprocessor(MacroLoc)) {
+ if (auto LocAndUnit = CTU.getImportedFromSourceLocation(MacroLoc)) {
MacroLoc = LocAndUnit->first;
- PPToUse = LocAndUnit->second;
+ PPToUse = &LocAndUnit->second->getPreprocessor();
}
llvm::SmallString<200> ExpansionBuf;
-//===--- SarifPathDiagnosticConsumer.cpp - Sarif Diagnostics ---*- C++ -*-===//
+//===--- SarifDiagnostics.cpp - Sarif Diagnostics for Paths -----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//
//
-// This file defines the SarifPathDiagnosticConsumer object.
+// This file defines the SarifDiagnostics object.
//
//===----------------------------------------------------------------------===//
#include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/Version.h"
#include "clang/Lex/Preprocessor.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/ConvertUTF.h"
using namespace clang;
using namespace ento;
-namespace clang {
-class CrossTUAnalysisHelper;
-}
-
namespace {
-class SarifPathDiagnosticConsumer : public PathDiagnosticConsumer {
+class SarifDiagnostics : public PathDiagnosticConsumer {
std::string OutputFile;
const LangOptions &LO;
public:
- SarifPathDiagnosticConsumer(const std::string &Output, const LangOptions &LO)
+ SarifDiagnostics(const std::string &Output, const LangOptions &LO)
: OutputFile(Output), LO(LO) {}
- ~SarifPathDiagnosticConsumer() override = default;
+ ~SarifDiagnostics() override = default;
void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
FilesMade *FM) override;
- StringRef getName() const override { return "SarifPathDiagnosticConsumer"; }
+ StringRef getName() const override { return "SarifDiagnostics"; }
PathGenerationScheme getGenerationScheme() const override { return Minimal; }
bool supportsLogicalOpControlFlow() const override { return true; }
bool supportsCrossFileDiagnostics() const override { return true; }
void ento::createSarifDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &Output, const Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU) {
+ const cross_tu::CrossTranslationUnitContext &CTU) {
// TODO: Emit an error here.
if (Output.empty())
return;
- C.push_back(new SarifPathDiagnosticConsumer(Output, PP.getLangOpts()));
+ C.push_back(new SarifDiagnostics(Output, PP.getLangOpts()));
createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, Output, PP,
CTU);
}
}
static StringRef getRuleDescription(StringRef CheckName) {
- // FIXME: This is a layering violation; it only works for the particular
- // use-case of clang static analyzer. This info should be provided
- // as part of PathDiagnostic itself.
return llvm::StringSwitch<StringRef>(CheckName)
#define GET_CHECKERS
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN) \
}
static StringRef getRuleHelpURIStr(StringRef CheckName) {
- // FIXME: This is a layering violation; it only works for the particular
- // use-case of clang static analyzer. This info should be provided
- // as part of PathDiagnostic itself.
return llvm::StringSwitch<StringRef>(CheckName)
#define GET_CHECKERS
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN) \
{"columnKind", "unicodeCodePoints"}};
}
-void SarifPathDiagnosticConsumer::FlushDiagnosticsImpl(
+void SarifDiagnostics::FlushDiagnosticsImpl(
std::vector<const PathDiagnostic *> &Diags, FilesMade *) {
// We currently overwrite the file if it already exists. However, it may be
// useful to add a feature someday that allows the user to append a run to an
-//===--- TextPathDiagnosticConsumer.cpp - Text Diagnostics ------*- C++ -*-===//
+//===--- TextDiagnostics.cpp - Text Diagnostics for Paths -------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//
//
-// This file defines the TextPathDiagnosticConsumer object.
+// This file defines the TextDiagnostics object.
//
//===----------------------------------------------------------------------===//
#include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Version.h"
+#include "clang/CrossTU/CrossTranslationUnit.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
#include "clang/Tooling/Core/Replacement.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/SmallPtrSet.h"
using namespace ento;
using namespace tooling;
-namespace clang {
-class CrossTUAnalysisHelper;
-}
-
namespace {
-/// Emits minimal diagnostics (report message + notes) for the 'none' output
+/// Emitsd minimal diagnostics (report message + notes) for the 'none' output
/// type to the standard error, or to to compliment many others. Emits detailed
/// diagnostics in textual format for the 'text' output type.
-class TextPathDiagnosticConsumer : public PathDiagnosticConsumer {
+class TextDiagnostics : public PathDiagnosticConsumer {
PathDiagnosticConsumerOptions DiagOpts;
DiagnosticsEngine &DiagEng;
const LangOptions &LO;
bool ShouldDisplayPathNotes;
public:
- TextPathDiagnosticConsumer(PathDiagnosticConsumerOptions DiagOpts,
- DiagnosticsEngine &DiagEng, const LangOptions &LO,
- bool ShouldDisplayPathNotes)
+ TextDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
+ DiagnosticsEngine &DiagEng, const LangOptions &LO,
+ bool ShouldDisplayPathNotes)
: DiagOpts(std::move(DiagOpts)), DiagEng(DiagEng), LO(LO),
ShouldDisplayPathNotes(ShouldDisplayPathNotes) {}
- ~TextPathDiagnosticConsumer() override {}
+ ~TextDiagnostics() override {}
- StringRef getName() const override { return "TextPathDiagnosticConsumer"; }
+ StringRef getName() const override { return "TextDiagnostics"; }
bool supportsLogicalOpControlFlow() const override { return true; }
bool supportsCrossFileDiagnostics() const override { return true; }
void ento::createTextPathDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &Prefix, const clang::Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU) {
- C.emplace_back(new TextPathDiagnosticConsumer(
- std::move(DiagOpts), PP.getDiagnostics(), PP.getLangOpts(),
- /*ShouldDisplayPathNotes=*/true));
+ const cross_tu::CrossTranslationUnitContext &CTU) {
+ C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
+ PP.getLangOpts(),
+ /*ShouldDisplayPathNotes=*/true));
}
void ento::createTextMinimalPathDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &Prefix, const clang::Preprocessor &PP,
- const CrossTUAnalysisHelper &CTU) {
- C.emplace_back(new TextPathDiagnosticConsumer(
- std::move(DiagOpts), PP.getDiagnostics(), PP.getLangOpts(),
- /*ShouldDisplayPathNotes=*/false));
+ const cross_tu::CrossTranslationUnitContext &CTU) {
+ C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
+ PP.getLangOpts(),
+ /*ShouldDisplayPathNotes=*/false));
}
#include "clang/Analysis/CallGraph.h"
#include "clang/Analysis/CodeInjector.h"
#include "clang/Analysis/PathDiagnostic.h"
-#include "clang/Analysis/PathDiagnosticConsumers.h"
#include "clang/Basic/SourceManager.h"
#include "clang/CrossTU/CrossTranslationUnit.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
#include "llvm/ADT/PostOrderIterator.h"
case PD_##NAME: \
CREATEFN(Opts->getDiagOpts(), PathConsumers, OutDir, PP, CTU); \
break;
-#include "clang/Analysis/PathDiagnosticConsumers.def"
+#include "clang/StaticAnalyzer/Core/Analyses.def"
default:
llvm_unreachable("Unknown analyzer output type!");
}