From: Ted Kremenek Date: Fri, 23 Jan 2009 20:06:20 +0000 (+0000) Subject: When using -analyzer-output-plist always output a plist file even if it contains... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c472d79e3aa3a81825f0e0c358dfd0317d6060ed;p=clang When using -analyzer-output-plist always output a plist file even if it contains no error reports. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62871 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/Analyses.def b/Driver/Analyses.def index 1f702cc0e9..3beaa73bcb 100644 --- a/Driver/Analyses.def +++ b/Driver/Analyses.def @@ -56,11 +56,11 @@ ANALYSIS_STORE(BasicStore, "basic", "Use basic analyzer store") ANALYSIS_STORE(RegionStore, "region", "Use region-based analyzer store") #ifndef ANALYSIS_DIAGNOSTICS -#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) +#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN, AUTOCREATE) #endif -ANALYSIS_DIAGNOSTICS(HTML, "html", "Output analysis results using HTML", CreateHTMLDiagnosticClient) -ANALYSIS_DIAGNOSTICS(PLIST, "plist", "Output analysis results using Plists", CreatePlistDiagnosticClient) +ANALYSIS_DIAGNOSTICS(HTML, "html", "Output analysis results using HTML", CreateHTMLDiagnosticClient, false) +ANALYSIS_DIAGNOSTICS(PLIST, "plist", "Output analysis results using Plists", CreatePlistDiagnosticClient, true) #undef ANALYSIS #undef ANALYSIS_STORE diff --git a/Driver/AnalysisConsumer.cpp b/Driver/AnalysisConsumer.cpp index 1ada515c10..236cc1d865 100644 --- a/Driver/AnalysisConsumer.cpp +++ b/Driver/AnalysisConsumer.cpp @@ -207,7 +207,7 @@ namespace { if (C.PD.get() == 0 && !C.HTMLDir.empty()) { switch (C.DC) { default: -#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)\ +#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN, AUTOCREATE)\ case PD_##NAME: C.PD.reset(CREATEFN(C.HTMLDir, C.PP, C.PPF)); break; #include "Analyses.def" } @@ -288,6 +288,15 @@ case PD_##NAME: C.PD.reset(CREATEFN(C.HTMLDir, C.PP, C.PPF)); break; CreateConstraintMgr = ManagerRegistry::ConstraintMgrCreator; else CreateConstraintMgr = CreateBasicConstraintManager; + + // Some DiagnosticClients should be created all the time instead of + // lazily. Create those now. + switch (C.DC) { + default: break; +#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN, AUTOCREATE)\ +case PD_##NAME: if (AUTOCREATE) getPathDiagnosticClient(); break; +#include "Analyses.def" + } } }; diff --git a/Driver/AnalysisConsumer.h b/Driver/AnalysisConsumer.h index 27c8e6e07a..1e08240220 100644 --- a/Driver/AnalysisConsumer.h +++ b/Driver/AnalysisConsumer.h @@ -29,7 +29,7 @@ NumStores }; enum AnalysisDiagClients { -#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) PD_##NAME, +#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREAT) PD_##NAME, #include "Analyses.def" NUM_ANALYSIS_DIAG_CLIENTS }; diff --git a/Driver/clang.cpp b/Driver/clang.cpp index cf58f34e7c..cc3788b5f3 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -239,7 +239,7 @@ static llvm::cl::opt AnalysisDiagOpt(llvm::cl::desc("SCA Output Options:"), llvm::cl::init(PD_HTML), llvm::cl::values( -#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN)\ +#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREATE)\ clEnumValN(PD_##NAME, "analyzer-output-" CMDFLAG, DESC), #include "Analyses.def" clEnumValEnd)); diff --git a/lib/Driver/PlistDiagnostics.cpp b/lib/Driver/PlistDiagnostics.cpp index ab5b5a394a..72d64ed1a8 100644 --- a/lib/Driver/PlistDiagnostics.cpp +++ b/lib/Driver/PlistDiagnostics.cpp @@ -50,17 +50,17 @@ clang::CreatePlistDiagnosticClient(const std::string& s, } static void AddFID(FIDMap &FIDs, llvm::SmallVectorImpl &V, - SourceManager& SM, SourceLocation L) { + SourceManager* SM, SourceLocation L) { - FileID FID = SM.getFileID(SM.getInstantiationLoc(L)); + FileID FID = SM->getFileID(SM->getInstantiationLoc(L)); FIDMap::iterator I = FIDs.find(FID); if (I != FIDs.end()) return; FIDs[FID] = V.size(); V.push_back(FID); } -static unsigned GetFID(const FIDMap& FIDs, SourceManager& SM, SourceLocation L){ - FileID FID = SM.getFileID(SM.getInstantiationLoc(L)); +static unsigned GetFID(const FIDMap& FIDs, SourceManager* SM, SourceLocation L){ + FileID FID = SM->getFileID(SM->getInstantiationLoc(L)); FIDMap::const_iterator I = FIDs.find(FID); assert(I != FIDs.end()); return I->second; @@ -72,21 +72,21 @@ static llvm::raw_ostream& Indent(llvm::raw_ostream& o, const unsigned indent) { return o; } -static void EmitLocation(llvm::raw_ostream& o, SourceManager& SM, +static void EmitLocation(llvm::raw_ostream& o, SourceManager* SM, SourceLocation L, const FIDMap& FM, const unsigned indent) { Indent(o, indent) << "\n"; Indent(o, indent) << " line" - << SM.getInstantiationLineNumber(L) << "\n"; + << SM->getInstantiationLineNumber(L) << "\n"; Indent(o, indent) << " col" - << SM.getInstantiationColumnNumber(L) << "\n"; + << SM->getInstantiationColumnNumber(L) << "\n"; Indent(o, indent) << " file" << GetFID(FM, SM, L) << "\n"; Indent(o, indent) << "\n"; } -static void EmitRange(llvm::raw_ostream& o, SourceManager& SM, SourceRange R, +static void EmitRange(llvm::raw_ostream& o, SourceManager* SM, SourceRange R, const FIDMap& FM, const unsigned indent) { Indent(o, indent) << "\n"; @@ -96,7 +96,7 @@ static void EmitRange(llvm::raw_ostream& o, SourceManager& SM, SourceRange R, } static void ReportDiag(llvm::raw_ostream& o, const PathDiagnosticPiece& P, - const FIDMap& FM, SourceManager& SM) { + const FIDMap& FM, SourceManager* SM) { unsigned indent = 2; Indent(o, indent) << "\n"; @@ -154,7 +154,10 @@ PlistDiagnostics::~PlistDiagnostics() { // ranges of the diagnostics. FIDMap FM; llvm::SmallVector Fids; - SourceManager& SM = (*BatchedDiags.begin())->begin()->getLocation().getManager(); + SourceManager* SM = 0; + + if (!BatchedDiags.empty()) + SM = &(*BatchedDiags.begin())->begin()->getLocation().getManager(); for (std::vector::iterator DI = BatchedDiags.begin(), DE = BatchedDiags.end(); DI != DE; ++DI) { @@ -195,7 +198,7 @@ PlistDiagnostics::~PlistDiagnostics() { for (llvm::SmallVectorImpl::iterator I=Fids.begin(), E=Fids.end(); I!=E; ++I) - o << " " << SM.getFileEntryForID(*I)->getName() << "\n"; + o << " " << SM->getFileEntryForID(*I)->getName() << "\n"; o << " \n" " diagnostics\n"