Skip to content

Commit 32f220c

Browse files
committed
[CrossTU] Added CTU argument to diagnostic consumer create fn.
Summary: The PListDiagnosticConsumer needs a new CTU parameter that is passed through the create functions. Reviewers: NoQ, Szelethus, xazax.hun, martong Reviewed By: Szelethus Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64635 llvm-svn: 366782
1 parent 2d654df commit 32f220c

File tree

5 files changed

+55
-48
lines changed

5 files changed

+55
-48
lines changed

clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ namespace clang {
2020

2121
class AnalyzerOptions;
2222
class Preprocessor;
23+
namespace cross_tu {
24+
class CrossTranslationUnitContext;
25+
}
2326

2427
namespace ento {
2528

2629
class PathDiagnosticConsumer;
2730
typedef std::vector<PathDiagnosticConsumer*> PathDiagnosticConsumers;
2831

29-
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)\
30-
void CREATEFN(AnalyzerOptions &AnalyzerOpts,\
31-
PathDiagnosticConsumers &C,\
32-
const std::string &Prefix,\
33-
const Preprocessor &PP);
32+
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) \
33+
void CREATEFN(AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C, \
34+
const std::string &Prefix, const Preprocessor &PP, \
35+
const cross_tu::CrossTranslationUnitContext &CTU);
3436
#include "clang/StaticAnalyzer/Core/Analyses.def"
3537

3638
} // end 'ento' namespace

clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,17 @@ class HTMLDiagnostics : public PathDiagnosticConsumer {
134134

135135
} // namespace
136136

137-
void ento::createHTMLDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
138-
PathDiagnosticConsumers &C,
139-
const std::string& prefix,
140-
const Preprocessor &PP) {
137+
void ento::createHTMLDiagnosticConsumer(
138+
AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
139+
const std::string &prefix, const Preprocessor &PP,
140+
const cross_tu::CrossTranslationUnitContext &) {
141141
C.push_back(new HTMLDiagnostics(AnalyzerOpts, prefix, PP, true));
142142
}
143143

144-
void ento::createHTMLSingleFileDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
145-
PathDiagnosticConsumers &C,
146-
const std::string& prefix,
147-
const Preprocessor &PP) {
144+
void ento::createHTMLSingleFileDiagnosticConsumer(
145+
AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
146+
const std::string &prefix, const Preprocessor &PP,
147+
const cross_tu::CrossTranslationUnitContext &) {
148148
C.push_back(new HTMLDiagnostics(AnalyzerOpts, prefix, PP, false));
149149
}
150150

clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

+25-20
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
#include "clang/Basic/PlistSupport.h"
1515
#include "clang/Basic/SourceManager.h"
1616
#include "clang/Basic/Version.h"
17+
#include "clang/CrossTU/CrossTranslationUnit.h"
1718
#include "clang/Lex/Preprocessor.h"
1819
#include "clang/Lex/TokenConcatenation.h"
1920
#include "clang/Rewrite/Core/HTMLRewrite.h"
2021
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
2122
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
2223
#include "clang/StaticAnalyzer/Core/IssueHash.h"
2324
#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
24-
#include "llvm/ADT/Statistic.h"
2525
#include "llvm/ADT/SmallPtrSet.h"
2626
#include "llvm/ADT/SmallVector.h"
27+
#include "llvm/ADT/Statistic.h"
2728
#include "llvm/Support/Casting.h"
2829

2930
using namespace clang;
@@ -39,12 +40,13 @@ namespace {
3940
class PlistDiagnostics : public PathDiagnosticConsumer {
4041
const std::string OutputFile;
4142
const Preprocessor &PP;
43+
const cross_tu::CrossTranslationUnitContext &CTU;
4244
AnalyzerOptions &AnOpts;
4345
const bool SupportsCrossFileDiagnostics;
4446
public:
45-
PlistDiagnostics(AnalyzerOptions &AnalyzerOpts,
46-
const std::string& prefix,
47+
PlistDiagnostics(AnalyzerOptions &AnalyzerOpts, const std::string &prefix,
4748
const Preprocessor &PP,
49+
const cross_tu::CrossTranslationUnitContext &CTU,
4850
bool supportsMultipleFiles);
4951

5052
~PlistDiagnostics() override {}
@@ -518,26 +520,29 @@ static void printBugPath(llvm::raw_ostream &o, const FIDMap& FM,
518520
// Methods of PlistDiagnostics.
519521
//===----------------------------------------------------------------------===//
520522

521-
PlistDiagnostics::PlistDiagnostics(AnalyzerOptions &AnalyzerOpts,
522-
const std::string& output,
523-
const Preprocessor &PP,
524-
bool supportsMultipleFiles)
525-
: OutputFile(output), PP(PP), AnOpts(AnalyzerOpts),
526-
SupportsCrossFileDiagnostics(supportsMultipleFiles) {}
527-
528-
void ento::createPlistDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
529-
PathDiagnosticConsumers &C,
530-
const std::string& s,
531-
const Preprocessor &PP) {
532-
C.push_back(new PlistDiagnostics(AnalyzerOpts, s, PP,
523+
PlistDiagnostics::PlistDiagnostics(
524+
AnalyzerOptions &AnalyzerOpts, const std::string &output,
525+
const Preprocessor &PP, const cross_tu::CrossTranslationUnitContext &CTU,
526+
bool supportsMultipleFiles)
527+
: OutputFile(output), PP(PP), CTU(CTU), AnOpts(AnalyzerOpts),
528+
SupportsCrossFileDiagnostics(supportsMultipleFiles) {
529+
// FIXME: Will be used by a later planned change.
530+
(void)CTU;
531+
}
532+
533+
void ento::createPlistDiagnosticConsumer(
534+
AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
535+
const std::string &s, const Preprocessor &PP,
536+
const cross_tu::CrossTranslationUnitContext &CTU) {
537+
C.push_back(new PlistDiagnostics(AnalyzerOpts, s, PP, CTU,
533538
/*supportsMultipleFiles*/ false));
534539
}
535540

536-
void ento::createPlistMultiFileDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
537-
PathDiagnosticConsumers &C,
538-
const std::string &s,
539-
const Preprocessor &PP) {
540-
C.push_back(new PlistDiagnostics(AnalyzerOpts, s, PP,
541+
void ento::createPlistMultiFileDiagnosticConsumer(
542+
AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
543+
const std::string &s, const Preprocessor &PP,
544+
const cross_tu::CrossTranslationUnitContext &CTU) {
545+
C.push_back(new PlistDiagnostics(AnalyzerOpts, s, PP, CTU,
541546
/*supportsMultipleFiles*/ true));
542547
}
543548
void PlistDiagnostics::FlushDiagnosticsImpl(

clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ class SarifDiagnostics : public PathDiagnosticConsumer {
4343
};
4444
} // end anonymous namespace
4545

46-
void ento::createSarifDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
47-
PathDiagnosticConsumers &C,
48-
const std::string &Output,
49-
const Preprocessor &) {
46+
void ento::createSarifDiagnosticConsumer(
47+
AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
48+
const std::string &Output, const Preprocessor &,
49+
const cross_tu::CrossTranslationUnitContext &) {
5050
C.push_back(new SarifDiagnostics(AnalyzerOpts, Output));
5151
}
5252

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ STATISTIC(MaxCFGSize, "The maximum number of basic blocks in a function.");
6464
// Special PathDiagnosticConsumers.
6565
//===----------------------------------------------------------------------===//
6666

67-
void ento::createPlistHTMLDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
68-
PathDiagnosticConsumers &C,
69-
const std::string &prefix,
70-
const Preprocessor &PP) {
67+
void ento::createPlistHTMLDiagnosticConsumer(
68+
AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
69+
const std::string &prefix, const Preprocessor &PP,
70+
const cross_tu::CrossTranslationUnitContext &CTU) {
7171
createHTMLDiagnosticConsumer(AnalyzerOpts, C,
72-
llvm::sys::path::parent_path(prefix), PP);
73-
createPlistMultiFileDiagnosticConsumer(AnalyzerOpts, C, prefix, PP);
72+
llvm::sys::path::parent_path(prefix), PP, CTU);
73+
createPlistMultiFileDiagnosticConsumer(AnalyzerOpts, C, prefix, PP, CTU);
7474
}
7575

76-
void ento::createTextPathDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
77-
PathDiagnosticConsumers &C,
78-
const std::string &Prefix,
79-
const clang::Preprocessor &PP) {
76+
void ento::createTextPathDiagnosticConsumer(
77+
AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C,
78+
const std::string &Prefix, const clang::Preprocessor &PP,
79+
const cross_tu::CrossTranslationUnitContext &CTU) {
8080
llvm_unreachable("'text' consumer should be enabled on ClangDiags");
8181
}
8282

@@ -249,7 +249,7 @@ class AnalysisConsumer : public AnalysisASTConsumer,
249249
default:
250250
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) \
251251
case PD_##NAME: \
252-
CREATEFN(*Opts.get(), PathConsumers, OutDir, PP); \
252+
CREATEFN(*Opts.get(), PathConsumers, OutDir, PP, CTU); \
253253
break;
254254
#include "clang/StaticAnalyzer/Core/Analyses.def"
255255
}

0 commit comments

Comments
 (0)