From: Tom Care Date: Thu, 2 Sep 2010 20:58:38 +0000 (+0000) Subject: Reverting 112850 and 112839 due to test failures on some systems X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=066d66096520c015036ef20bbbfe100b88e2a2d1;p=clang Reverting 112850 and 112839 due to test failures on some systems git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112857 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Checker/BugReporter/BugReporter.h b/include/clang/Checker/BugReporter/BugReporter.h index 370d96552c..3749b43d7e 100644 --- a/include/clang/Checker/BugReporter/BugReporter.h +++ b/include/clang/Checker/BugReporter/BugReporter.h @@ -471,9 +471,6 @@ void registerFindLastStore(BugReporterContext& BRC, const void *memregion, void registerNilReceiverVisitor(BugReporterContext &BRC); -void registerVarDeclsLastStore(BugReporterContext &BRC, const void *stmt, - const ExplodedNode *N); - } // end namespace clang::bugreporter //===----------------------------------------------------------------------===// diff --git a/lib/Checker/BugReporterVisitors.cpp b/lib/Checker/BugReporterVisitors.cpp index 91cf349107..cddc86ee9d 100644 --- a/lib/Checker/BugReporterVisitors.cpp +++ b/lib/Checker/BugReporterVisitors.cpp @@ -419,40 +419,3 @@ public: void clang::bugreporter::registerNilReceiverVisitor(BugReporterContext &BRC) { BRC.addVisitor(new NilReceiverVisitor()); } - -// Registers every VarDecl inside a Stmt with a last store vistor. -void clang::bugreporter::registerVarDeclsLastStore(BugReporterContext &BRC, - const void *stmt, - const ExplodedNode *N) { - const Stmt *S = static_cast(stmt); - - std::deque WorkList; - - WorkList.push_back(S); - - while (!WorkList.empty()) { - const Stmt *Head = WorkList.front(); - WorkList.pop_front(); - - GRStateManager &StateMgr = BRC.getStateManager(); - const GRState *state = N->getState(); - - if (const DeclRefExpr *DR = dyn_cast(Head)) { - if (const VarDecl *VD = dyn_cast(DR->getDecl())) { - const VarRegion *R = - StateMgr.getRegionManager().getVarRegion(VD, N->getLocationContext()); - - // What did we load? - SVal V = state->getSVal(S); - - if (isa(V) || isa(V)) { - ::registerFindLastStore(BRC, R, V); - } - } - } - - for (Stmt::const_child_iterator I = Head->child_begin(); - I != Head->child_end(); ++I) - WorkList.push_back(*I); - } -} diff --git a/lib/Checker/IdempotentOperationChecker.cpp b/lib/Checker/IdempotentOperationChecker.cpp index 1a0197683e..3d4be1a119 100644 --- a/lib/Checker/IdempotentOperationChecker.cpp +++ b/lib/Checker/IdempotentOperationChecker.cpp @@ -45,7 +45,6 @@ #include "GRExprEngineExperimentalChecks.h" #include "clang/Analysis/CFGStmtMap.h" #include "clang/Analysis/Analyses/PseudoConstantAnalysis.h" -#include "clang/Checker/BugReporter/BugReporter.h" #include "clang/Checker/BugReporter/BugType.h" #include "clang/Checker/PathSensitive/CheckerHelpers.h" #include "clang/Checker/PathSensitive/CheckerVisitor.h" @@ -65,7 +64,6 @@ class IdempotentOperationChecker public: static void *getTag(); void PreVisitBinaryOperator(CheckerContext &C, const BinaryOperator *B); - void PostVisitBinaryOperator(CheckerContext &C, const BinaryOperator *B); void VisitEndAnalysis(ExplodedGraph &G, BugReporter &B, GRExprEngine &Eng); private: @@ -89,15 +87,10 @@ class IdempotentOperationChecker AnalysisContext *AC); static bool containsNonLocalVarDecl(const Stmt *S); - // Hash table and related data structures - struct BinaryOperatorData { - Assumption assumption; - AnalysisContext *analysisContext; - ExplodedNodeSet explodedNodes; // Set of ExplodedNodes that refer to a - // BinaryOperator - }; - typedef llvm::DenseMap - AssumptionMap; + // Hash table + typedef llvm::DenseMap > + AssumptionMap; AssumptionMap hash; }; } @@ -116,12 +109,11 @@ void IdempotentOperationChecker::PreVisitBinaryOperator( const BinaryOperator *B) { // Find or create an entry in the hash for this BinaryOperator instance. // If we haven't done a lookup before, it will get default initialized to - // 'Possible'. At this stage we do not store the ExplodedNode, as it has not - // been created yet. - BinaryOperatorData &Data = hash[B]; - Assumption &A = Data.assumption; + // 'Possible'. + std::pair &Data = hash[B]; + Assumption &A = Data.first; AnalysisContext *AC = C.getCurrentAnalysisContext(); - Data.analysisContext = AC; + Data.second = AC; // If we already have visited this node on a path that does not contain an // idempotent operation, return immediately. @@ -325,29 +317,16 @@ void IdempotentOperationChecker::PreVisitBinaryOperator( A = Impossible; } -// At the post visit stage, the predecessor ExplodedNode will be the -// BinaryOperator that was just created. We use this hook to collect the -// ExplodedNode. -void IdempotentOperationChecker::PostVisitBinaryOperator( - CheckerContext &C, - const BinaryOperator *B) { - // Add the ExplodedNode we just visited - BinaryOperatorData &Data = hash[B]; - Data.explodedNodes.Add(C.getPredecessor()); -} - void IdempotentOperationChecker::VisitEndAnalysis(ExplodedGraph &G, BugReporter &BR, GRExprEngine &Eng) { - BugType *BT = new BugType("Idempotent operation", "Dead code"); // Iterate over the hash to see if we have any paths with definite // idempotent operations. for (AssumptionMap::const_iterator i = hash.begin(); i != hash.end(); ++i) { // Unpack the hash contents - const BinaryOperatorData &Data = i->second; - const Assumption &A = Data.assumption; - AnalysisContext *AC = Data.analysisContext; - const ExplodedNodeSet &ES = Data.explodedNodes; + const std::pair &Data = i->second; + const Assumption &A = Data.first; + AnalysisContext *AC = Data.second; const BinaryOperator *B = i->first; @@ -369,14 +348,11 @@ void IdempotentOperationChecker::VisitEndAnalysis(ExplodedGraph &G, delete CBM; } - // Select the error message and SourceRanges to report. + // Select the error message. llvm::SmallString<128> buf; llvm::raw_svector_ostream os(buf); - bool LHSRelevant = false, RHSRelevant = false; switch (A) { case Equal: - LHSRelevant = true; - RHSRelevant = true; if (B->getOpcode() == BO_Assign) os << "Assigned value is always the same as the existing value"; else @@ -384,19 +360,15 @@ void IdempotentOperationChecker::VisitEndAnalysis(ExplodedGraph &G, << "' always have the same value"; break; case LHSis1: - LHSRelevant = true; os << "The left operand to '" << B->getOpcodeStr() << "' is always 1"; break; case RHSis1: - RHSRelevant = true; os << "The right operand to '" << B->getOpcodeStr() << "' is always 1"; break; case LHSis0: - LHSRelevant = true; os << "The left operand to '" << B->getOpcodeStr() << "' is always 0"; break; case RHSis0: - RHSRelevant = true; os << "The right operand to '" << B->getOpcodeStr() << "' is always 0"; break; case Possible: @@ -405,24 +377,11 @@ void IdempotentOperationChecker::VisitEndAnalysis(ExplodedGraph &G, llvm_unreachable(0); } - // Add a report for each ExplodedNode - for (ExplodedNodeSet::iterator I = ES.begin(), E = ES.end(); I != E; ++I) { - EnhancedBugReport *report = new EnhancedBugReport(*BT, os.str(), *I); - - // Add source ranges and visitor hooks - if (LHSRelevant) { - const Expr *LHS = i->first->getLHS(); - report->addRange(LHS->getSourceRange()); - report->addVisitorCreator(bugreporter::registerVarDeclsLastStore, LHS); - } - if (RHSRelevant) { - const Expr *RHS = i->first->getRHS(); - report->addRange(i->first->getRHS()->getSourceRange()); - report->addVisitorCreator(bugreporter::registerVarDeclsLastStore, RHS); - } - - BR.EmitReport(report); - } + // Create the SourceRange Arrays + SourceRange S[2] = { i->first->getLHS()->getSourceRange(), + i->first->getRHS()->getSourceRange() }; + BR.EmitBasicReport("Idempotent operation", "Dead code", + os.str(), i->first->getOperatorLoc(), S, 2); } }