zcov: / lib/Checker/GRBlockCounter.cpp


Files: 1 Branches Taken: 83.3% 5 / 6
Generated: 2010-02-10 01:31 Branches Executed: 66.7% 4 / 6
Line Coverage: 94.7% 18 / 19


Programs: 1 Runs 2897


       1                 : //==- GRBlockCounter.h - ADT for counting block visits -------------*- C++ -*-//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : //  This file defines GRBlockCounter, an abstract data type used to count
      11                 : //  the number of times a given block has been visited along a path
      12                 : //  analyzed by GRCoreEngine.
      13                 : //
      14                 : //===----------------------------------------------------------------------===//
      15                 : 
      16                 : #include "clang/Checker/PathSensitive/GRBlockCounter.h"
      17                 : #include "llvm/ADT/ImmutableMap.h"
      18                 : 
      19                 : using namespace clang;
      20                 : 
      21                 : typedef llvm::ImmutableMap<unsigned,unsigned> CountMap;
      22                 : 
      23            22483: static inline CountMap GetMap(void* D) {
      24            22483:   return CountMap(static_cast<CountMap::TreeTy*>(D));
      25                 : }
      26                 : 
      27             8682: static inline CountMap::Factory& GetFactory(void* F) {
      28             8682:   return *static_cast<CountMap::Factory*>(F);
      29                 : }
      30                 : 
      31            15939: unsigned GRBlockCounter::getNumVisited(unsigned BlockID) const {
      32            15939:   CountMap M = GetMap(Data);
      33            15939:   CountMap::data_type* T = M.lookup(BlockID);
                     5327: branch 0 taken
                    10612: branch 1 taken
      34            15939:   return T ? *T : 0;
      35                 : }
      36                 : 
      37             2138: GRBlockCounter::Factory::Factory(llvm::BumpPtrAllocator& Alloc) {
      38             2138:   F = new CountMap::Factory(Alloc);
      39             2138: }
      40                 : 
      41             2138: GRBlockCounter::Factory::~Factory() {
                     2138: branch 0 taken
                        0: branch 1 not taken
                     2138: branch 4 taken
                     2138: branch 5 taken
      42             2138:   delete static_cast<CountMap::Factory*>(F);
      43             2138: }
      44                 : 
      45                 : GRBlockCounter
      46             6544: GRBlockCounter::Factory::IncrementCount(GRBlockCounter BC, unsigned BlockID) {
      47                 :   return GRBlockCounter(GetFactory(F).Add(GetMap(BC.Data), BlockID,
      48             6544:                                         BC.getNumVisited(BlockID)+1).getRoot());
      49                 : }
      50                 : 
      51                 : GRBlockCounter
      52             2138: GRBlockCounter::Factory::GetEmptyCounter() {
      53             2138:   return GRBlockCounter(GetFactory(F).GetEmptyMap().getRoot());
      54                0: }

Generated: 2010-02-10 01:31 by zcov