[cfe-commits] r53002 - in /cfe/trunk/Driver: ASTConsumers.cpp ASTConsumers.h AnalysisConsumer.cpp AnalysisConsumer.h clang.cpp
Ted Kremenek
kremenek at apple.com
Tue Jul 1 17:44:58 PDT 2008
Author: kremenek
Date: Tue Jul 1 19:44:58 2008
New Revision: 53002
URL: http://llvm.org/viewvc/llvm-project?rev=53002&view=rev
Log:
Migrated driver logic for running the CF retain/release checker over to the new AnalysisConsumer interface.
Modified:
cfe/trunk/Driver/ASTConsumers.cpp
cfe/trunk/Driver/ASTConsumers.h
cfe/trunk/Driver/AnalysisConsumer.cpp
cfe/trunk/Driver/AnalysisConsumer.h
cfe/trunk/Driver/clang.cpp
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=53002&r1=53001&r2=53002&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Tue Jul 1 19:44:58 2008
@@ -765,58 +765,6 @@
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
Modified: cfe/trunk/Driver/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=53002&r1=53001&r2=53002&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Tue Jul 1 19:44:58 2008
@@ -45,13 +45,6 @@
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,
Modified: cfe/trunk/Driver/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/AnalysisConsumer.cpp?rev=53002&r1=53001&r2=53002&view=diff
==============================================================================
--- cfe/trunk/Driver/AnalysisConsumer.cpp (original)
+++ cfe/trunk/Driver/AnalysisConsumer.cpp Tue Jul 1 19:44:58 2008
@@ -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 @@
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 @@
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 @@
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 @@
C->addCodeAction(&ActionUninitVals);
break;
+ case CheckerCFRef:
+ C->addCodeAction(&ActionRefLeakChecker);
+ break;
+
default: break;
}
Modified: cfe/trunk/Driver/AnalysisConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/AnalysisConsumer.h?rev=53002&r1=53001&r2=53002&view=diff
==============================================================================
--- cfe/trunk/Driver/AnalysisConsumer.h (original)
+++ cfe/trunk/Driver/AnalysisConsumer.h Tue Jul 1 19:44:58 2008
@@ -18,7 +18,8 @@
enum Analyses {
WarnDeadStores,
- WarnUninitVals
+ WarnUninitVals,
+ CheckerCFRef
};
ASTConsumer* CreateAnalysisConsumer(Analyses* Beg, Analyses* End,
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=53002&r1=53001&r2=53002&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Tue Jul 1 19:44:58 2008
@@ -77,7 +77,6 @@
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 @@
"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 @@
"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 @@
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);
More information about the cfe-commits
mailing list