zcov: / lib/Checker/BuiltinFunctionChecker.cpp


Files: 1 Branches Taken: 69.2% 9 / 13
Generated: 2010-02-10 01:31 Branches Executed: 84.6% 11 / 13
Line Coverage: 100.0% 27 / 27


Programs: 1 Runs 2897


       1                 : //=== BuiltinFunctionChecker.cpp --------------------------------*- 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 checker evaluates clang builtin functions.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #include "GRExprEngineInternalChecks.h"
      15                 : #include "clang/Checker/PathSensitive/Checker.h"
      16                 : #include "clang/Basic/Builtins.h"
      17                 : #include "llvm/ADT/StringSwitch.h"
      18                 : 
      19                 : using namespace clang;
      20                 : 
      21                 : namespace {
      22                 : 
                     2138: branch 2 taken
                        0: branch 3 not taken
                        0: branch 6 not taken
                        0: branch 7 not taken
      23             4276: class BuiltinFunctionChecker : public Checker {
      24                 : public:
      25             2138:   static void *getTag() { static int tag = 0; return &tag; }
      26                 :   virtual bool EvalCallExpr(CheckerContext &C, const CallExpr *CE);
      27                 : };
      28                 : 
      29                 : }
      30                 : 
      31             2138: void clang::RegisterBuiltinFunctionChecker(GRExprEngine &Eng) {
      32             2138:   Eng.registerCheck(new BuiltinFunctionChecker());
      33             2138: }
      34                 : 
      35             1620: bool BuiltinFunctionChecker::EvalCallExpr(CheckerContext &C,const CallExpr *CE){
      36             1620:   const GRState *state = C.getState();
      37             1620:   const Expr *Callee = CE->getCallee();
      38             1620:   SVal L = state->getSVal(Callee);
      39             1620:   const FunctionDecl *FD = L.getAsFunctionDecl();
      40                 : 
                       56: branch 0 taken
                     1564: branch 1 taken
      41             1620:   if (!FD)
      42               56:     return false;
      43                 : 
      44             1564:   unsigned id = FD->getBuiltinID();
      45                 : 
                     1452: branch 0 taken
                      112: branch 1 taken
      46             1564:   if (!id)
      47             1452:     return false;
      48                 : 
                        1: branch 0 taken
                       14: branch 1 taken
                       97: branch 2 taken
      49              112:   switch (id) {
      50                 :   case Builtin::BI__builtin_expect: {
      51                 :     // For __builtin_expect, just return the value of the subexpression.
                        0: branch 3 not taken
                        1: branch 4 taken
      52                1:     assert (CE->arg_begin() != CE->arg_end());
      53                1:     SVal X = state->getSVal(*(CE->arg_begin()));
      54                1:     C.GenerateNode(state->BindExpr(CE, X));
      55                1:     return true;
      56                 :   }
      57                 : 
      58                 :   case Builtin::BI__builtin_alloca: {
      59                 :     // FIXME: Refactor into StoreManager itself?
      60               14:     MemRegionManager& RM = C.getStoreManager().getRegionManager();
      61                 :     const MemRegion* R =
      62                 :       RM.getAllocaRegion(CE, C.getNodeBuilder().getCurrentBlockCount(),
      63               14:                          C.getPredecessor()->getLocationContext());
      64                 : 
      65                 :     // Set the extent of the region in bytes. This enables us to use the
      66                 :     // SVal of the argument directly. If we save the extent in bits, we
      67                 :     // cannot represent values like symbol*8.
      68               14:     SVal Extent = state->getSVal(*(CE->arg_begin()));
      69               14:     state = C.getStoreManager().setExtent(state, R, Extent);
      70               14:     C.GenerateNode(state->BindExpr(CE, loc::MemRegionVal(R)));
      71               14:     return true;
      72                 :   }
      73                 :   }
      74                 : 
      75               97:   return false;
      76                 : }

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