]> granicus.if.org Git - clang/commitdiff
[analyzer] Add ProgramStatePartialTrait<const void *>.
authorJordan Rose <jordan_rose@apple.com>
Mon, 14 Jan 2013 18:58:42 +0000 (18:58 +0000)
committerJordan Rose <jordan_rose@apple.com>
Mon, 14 Jan 2013 18:58:42 +0000 (18:58 +0000)
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

include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h
lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

index 8c3ecc1eee20730f6900001815501807dad046c6..ba63620afb6eb0544161acc64850e80e047a2f05 100644 (file)
@@ -555,7 +555,7 @@ private:
 struct ReplayWithoutInlining{};
 template <>
 struct ProgramStateTrait<ReplayWithoutInlining> :
-  public ProgramStatePartialTrait<void*> {
+  public ProgramStatePartialTrait<const void*> {
   static void *GDMIndex() { static int index = 0; return &index; }
 };
 
index 34f450f4fb78cda5b971934aa1c5d33212a22ff0..eb52ae47bdf23dc874c50d9f058fc888c2ed08d0 100644 (file)
@@ -167,7 +167,7 @@ namespace ento {
     }
 
     static inline void *MakeVoidPtr(data_type D) {
-      return const_cast<llvm::ImmutableListImpl<T> >(D.getInternalPointer());
+      return const_cast<llvm::ImmutableListImpl<T> *>(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<const void *> {
+    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<void *>(d);
+    }
+  };
+
+} // end ento namespace
 
 } // end clang namespace
 
index 7c1c26e8f77f87face662a2f340f43714ddf235a..af93baa0a292ad59268693a3ff6bb0ccdd685dc8 100644 (file)
@@ -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<ReplayWithoutInlining>();
+  const void *ReplayState = State->get<ReplayWithoutInlining>();
   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<ReplayWithoutInlining>();