From: Jordan Rose Date: Mon, 14 Jan 2013 18:58:42 +0000 (+0000) Subject: [analyzer] Add ProgramStatePartialTrait. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bdc691f1d61765dd806d5ae3b75ae004f676a7c9;p=clang [analyzer] Add ProgramStatePartialTrait. This should fix cast-away-const warnings reported by David Greene. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172446 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h index 8c3ecc1eee..ba63620afb 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h @@ -555,7 +555,7 @@ private: struct ReplayWithoutInlining{}; template <> struct ProgramStateTrait : - public ProgramStatePartialTrait { + public ProgramStatePartialTrait { static void *GDMIndex() { static int index = 0; return &index; } }; diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h index 34f450f4fb..eb52ae47bd 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h @@ -167,7 +167,7 @@ namespace ento { } static inline void *MakeVoidPtr(data_type D) { - return const_cast >(D.getInternalPointer()); + return const_cast *>(D.getInternalPointer()); } static inline context_type MakeContext(void *p) { @@ -223,7 +223,20 @@ namespace ento { } }; -} // end GR namespace + // Partial specialization for const void *. + template <> struct ProgramStatePartialTrait { + typedef const void *data_type; + + static inline data_type MakeData(void * const *p) { + return p ? *p : data_type(); + } + + static inline void *MakeVoidPtr(data_type d) { + return const_cast(d); + } + }; + +} // end ento namespace } // end clang namespace diff --git a/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp b/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp index 7c1c26e8f7..af93baa0a2 100644 --- a/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp @@ -608,11 +608,11 @@ bool ExprEngine::inlineCall(const CallEvent &Call, const Decl *D, static ProgramStateRef getInlineFailedState(ProgramStateRef State, const Stmt *CallE) { - void *ReplayState = State->get(); + const void *ReplayState = State->get(); if (!ReplayState) return 0; - assert(ReplayState == (const void*)CallE && "Backtracked to the wrong call."); + assert(ReplayState == CallE && "Backtracked to the wrong call."); (void)CallE; return State->remove();