From 302da83fc2890d4dcef9dcd49ae247c47fd208b5 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Tue, 30 Oct 2012 04:17:40 +0000 Subject: [PATCH] [analyzer] Fix a bug in REGISTER_MAP_WITH_PROGRAMSTATE The ImmutableMap should not be the key into the GDM map as there could be several entries with the same map type. Thanks, Jordan. This complicates the usage of the macro a bit. When we want to retrieve the whole map, we need to use another name. Currently, I set it to be Name ## Ty as in "type of the map we are storing in the ProgramState". llvm-svn: 167000 --- .../StaticAnalyzer/Core/PathSensitive/CheckerContext.h | 13 +++++++------ clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp | 12 +++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h index e1d30ec..5960ace 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h @@ -18,20 +18,21 @@ #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h" #include "llvm/ADT/ImmutableMap.h" -/// Declare an immutable map suitable for placement into the ProgramState. -#define REGISTER_MAP_WITH_PROGRAMSTATE(Map, Key, Value) \ - typedef llvm::ImmutableMap Map; \ +/// Declares an immutable map of type NameTy, suitable for placement into +/// the ProgramState. The macro should not be used inside namespaces. +#define REGISTER_MAP_WITH_PROGRAMSTATE(Name, Key, Value) \ + class Name {}; \ + typedef llvm::ImmutableMap Name ## Ty; \ namespace clang { \ namespace ento { \ template <> \ - struct ProgramStateTrait \ - : public ProgramStatePartialTrait { \ + struct ProgramStateTrait \ + : public ProgramStatePartialTrait { \ static void *GDMIndex() { static int Index; return &Index; } \ }; \ } \ } - namespace clang { namespace ento { diff --git a/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp index 50b9fe0..5721b10 100644 --- a/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp @@ -106,9 +106,7 @@ void SimpleStreamChecker::checkPreStmt(const CallExpr *Call, CheckerContext &C) const { initIdentifierInfo(C.getASTContext()); - if (C.getCalleeIdentifier(Call) != IIfclose) - return; - if (Call->getNumArgs() != 1) + if (C.getCalleeIdentifier(Call) != IIfclose || Call->getNumArgs() != 1) return; // Get the symbolic value corresponding to the file handle. @@ -130,9 +128,9 @@ void SimpleStreamChecker::checkPreStmt(const CallExpr *Call, void SimpleStreamChecker::checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const { ProgramStateRef State = C.getState(); - StreamMap TrackedStreams = State->get(); + StreamMapTy TrackedStreams = State->get(); SymbolVector LeakedStreams; - for (StreamMap::iterator I = TrackedStreams.begin(), + for (StreamMapTy::iterator I = TrackedStreams.begin(), E = TrackedStreams.end(); I != E; ++I) { SymbolRef Sym = I->first; if (SymReaper.isDead(Sym)) { @@ -154,9 +152,9 @@ void SimpleStreamChecker::checkDeadSymbols(SymbolReaper &SymReaper, ProgramStateRef SimpleStreamChecker::evalAssume(ProgramStateRef State, SVal Cond, bool Assumption) const { - StreamMap TrackedStreams = State->get(); + StreamMapTy TrackedStreams = State->get(); SymbolVector LeakedStreams; - for (StreamMap::iterator I = TrackedStreams.begin(), + for (StreamMapTy::iterator I = TrackedStreams.begin(), E = TrackedStreams.end(); I != E; ++I) { SymbolRef Sym = I->first; if (State->getConstraintManager().isNull(State, Sym).isTrue()) -- 2.7.4