Migrated driver logic for running the CF retain/release checker over to the new AnalysisConsumer interface.

llvm-svn: 53002
This commit is contained in:
Ted Kremenek 2008-07-02 00:44:58 +00:00
parent 82a9321f56
commit 8e631a0267
5 changed files with 62 additions and 68 deletions

View File

@ -765,58 +765,6 @@ ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags,
Visualize, TrimGraph, AnalyzeAll);
}
//===----------------------------------------------------------------------===//
// Core Foundation Reference Counting Checker
namespace {
class CFRefCountCheckerVisitor : public CheckerConsumer {
const LangOptions& LangOpts;
public:
CFRefCountCheckerVisitor(Diagnostic &diags, Preprocessor* pp,
PreprocessorFactory* ppf,
const LangOptions& lopts,
const std::string& fname,
const std::string& htmldir,
bool visualize, bool trim, bool analyzeAll)
: CheckerConsumer(diags, pp, ppf, fname, htmldir, visualize,
trim, analyzeAll), LangOpts(lopts) {}
virtual const char* getCheckerName() { return "CFRefCountChecker"; }
virtual void getTransferFunctions(std::vector<GRTransferFuncs*>& TFs) {
switch (LangOpts.getGCMode()) {
case LangOptions::NonGC:
TFs.push_back(MakeCFRefCountTF(*Ctx, false, true, LangOpts));
break;
case LangOptions::GCOnly:
TFs.push_back(MakeCFRefCountTF(*Ctx, true, true, LangOpts));
break;
case LangOptions::HybridGC:
TFs.push_back(MakeCFRefCountTF(*Ctx, false, true, LangOpts));
TFs.push_back(MakeCFRefCountTF(*Ctx, true, false, LangOpts));
break;
}
}
};
} // end anonymous namespace
ASTConsumer* clang::CreateCFRefChecker(Diagnostic &Diags,
Preprocessor* PP,
PreprocessorFactory* PPF,
const LangOptions& LangOpts,
const std::string& FunctionName,
const std::string& HTMLDir,
bool Visualize, bool TrimGraph,
bool AnalyzeAll) {
return new CFRefCountCheckerVisitor(Diags, PP, PPF, LangOpts, FunctionName,
HTMLDir, Visualize, TrimGraph,
AnalyzeAll);
}
//===----------------------------------------------------------------------===//
// AST Serializer

View File

@ -45,13 +45,6 @@ ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags,
const std::string& Function,
const std::string& HTMLDir, bool Visualize,
bool TrimGraph, bool AnalyzeAll);
ASTConsumer *CreateCFRefChecker(Diagnostic &Diags,
Preprocessor* PP, PreprocessorFactory* PPF,
const LangOptions& LangOpts,
const std::string& Function,
const std::string& HTMLDir, bool Visualize,
bool TrimGraph, bool AnalyzeAll);
ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
const std::string& OutFile,

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "ASTConsumers.h"
#include "HTMLDiagnostics.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
@ -104,6 +105,7 @@ namespace {
llvm::OwningPtr<CFG> cfg;
llvm::OwningPtr<LiveVariables> liveness;
llvm::OwningPtr<ParentMap> PM;
llvm::OwningPtr<PathDiagnosticClient> PD;
public:
AnalysisManager(AnalysisConsumer& c, Decl* d, Stmt* b)
@ -130,6 +132,17 @@ namespace {
Diagnostic& getDiagnostic() {
return C.Diags;
}
const LangOptions& getLangOptions() const {
return C.LOpts;
}
PathDiagnosticClient* getPathDiagnosticClient() {
if (PD.get() == 0 && !C.HTMLDir.empty())
PD.reset(CreateHTMLDiagnosticClient(C.HTMLDir, C.PP, C.PPF));
return PD.get();
}
LiveVariables* getLiveVariables() {
if (!liveness) liveness.reset(new LiveVariables(*getCFG()));
@ -213,6 +226,47 @@ static void ActionUninitVals(AnalysisManager& mgr) {
mgr.getDiagnostic());
}
static void ActionRefLeakCheckerAux(AnalysisManager& mgr, bool GCEnabled,
bool StandardWarnings) {
// Construct the analysis engine.
GRExprEngine Eng(*mgr.getCFG(), *mgr.getCodeDecl(), mgr.getContext());
// Construct the transfer function object.
llvm::OwningPtr<GRTransferFuncs>
TF(MakeCFRefCountTF(mgr.getContext(), GCEnabled, StandardWarnings,
mgr.getLangOptions()));
Eng.setTransferFunctions(TF.get());
// Execute the worklist algorithm.
Eng.ExecuteWorkList();
// Display warnings.
Eng.EmitWarnings(mgr.getDiagnostic(), mgr.getPathDiagnosticClient());
}
static void ActionRefLeakChecker(AnalysisManager& mgr) {
switch (mgr.getLangOptions().getGCMode()) {
default:
assert (false && "Invalid GC mode.");
case LangOptions::NonGC:
ActionRefLeakCheckerAux(mgr, false, true);
break;
case LangOptions::GCOnly:
ActionRefLeakCheckerAux(mgr, true, true);
break;
case LangOptions::HybridGC:
ActionRefLeakCheckerAux(mgr, false, true);
ActionRefLeakCheckerAux(mgr, true, false);
break;
}
}
//===----------------------------------------------------------------------===//
// AnalysisConsumer creation.
//===----------------------------------------------------------------------===//
@ -240,6 +294,10 @@ ASTConsumer* clang::CreateAnalysisConsumer(Analyses* Beg, Analyses* End,
C->addCodeAction(&ActionUninitVals);
break;
case CheckerCFRef:
C->addCodeAction(&ActionRefLeakChecker);
break;
default: break;
}

View File

@ -18,7 +18,8 @@ namespace clang {
enum Analyses {
WarnDeadStores,
WarnUninitVals
WarnUninitVals,
CheckerCFRef
};
ASTConsumer* CreateAnalysisConsumer(Analyses* Beg, Analyses* End,

View File

@ -77,7 +77,6 @@ enum ProgActions {
AnalysisLiveVariables, // Print results of live-variable analysis.
AnalysisGRSimpleVals, // Perform graph-reachability constant prop.
AnalysisGRSimpleValsView, // Visualize results of path-sens. analysis.
CheckerCFRef, // Run the Core Foundation Ref. Count Checker.
TestSerialization, // Run experimental serialization code.
ParsePrintCallbacks, // Parse and print each callback.
ParseSyntaxOnly, // Parse and perform semantic analysis.
@ -120,8 +119,6 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
"Print results of live variable analysis"),
clEnumValN(AnalysisGRSimpleVals, "checker-simple",
"Perform path-sensitive constant propagation"),
clEnumValN(CheckerCFRef, "checker-cfref",
"Run the Core Foundation reference count checker"),
clEnumValN(TestSerialization, "test-pickling",
"Run prototype serialization code"),
clEnumValN(EmitLLVM, "emit-llvm",
@ -182,6 +179,8 @@ clEnumValN(WarnDeadStores, "warn-dead-stores",
"Flag warnings of stores to dead variables"),
clEnumValN(WarnUninitVals, "warn-uninit-values",
"Flag warnings of uses of unitialized variables"),
clEnumValN(CheckerCFRef, "checker-cfref",
"Run the [Core] Foundation reference count checker"),
clEnumValEnd));
//===----------------------------------------------------------------------===//
@ -1206,11 +1205,6 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
return CreateGRSimpleVals(Diag, PP, PPF, AnalyzeSpecificFunction,
OutputFile, VisualizeEG, TrimGraph, AnalyzeAll);
case CheckerCFRef:
return CreateCFRefChecker(Diag, PP, PPF, LangOpts,
AnalyzeSpecificFunction,
OutputFile, VisualizeEG, TrimGraph, AnalyzeAll);
case TestSerialization:
return CreateSerializationTest(Diag, FileMgr);