blob: 188ce7084ce1834c7f9ebed261306581fd6ee5ba [file] [log] [blame]
Ted Kremenek2fff37e2008-03-06 00:08:09 +00001// CFRefCount.cpp - Transfer functions for tracking simple values -*- 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 files defines the methods for CFRefCount, which implements
11// a reference count checker for Core Foundation (Mac OS X).
12//
13//===----------------------------------------------------------------------===//
14
15#include "CFRefCount.h"
16#include "clang/Analysis/PathSensitive/ValueState.h"
17#include "clang/Basic/Diagnostic.h"
18#include "clang/Analysis/LocalCheckers.h"
19
20
21using namespace clang;
22
23
24namespace clang {
25
26void CheckCFRefCount(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
27 Diagnostic& Diag) {
28
29 if (Diag.hasErrorOccurred())
30 return;
31
32 // FIXME: Refactor some day so this becomes a single function invocation.
33
34 GRCoreEngine<GRExprEngine> Engine(cfg, FD, Ctx);
35 GRExprEngine* CS = &Engine.getCheckerState();
36 CFRefCount TF;
37 CS->setTransferFunctions(TF);
38 Engine.ExecuteWorkList(20000);
39
40}
41
42}
43
44void CFRefCount::EvalCall(ExplodedNodeSet<ValueState>& Dst,
45 ValueStateManager& StateMgr,
46 GRStmtNodeBuilder<ValueState>& Builder,
47 ValueManager& ValMgr,
48 CallExpr* CE, LVal L,
49 ExplodedNode<ValueState>* Pred) {
50
51 ValueState* St = Pred->getState();
52
53 // Invalidate all arguments passed in by reference (LVals).
54
55 for (CallExpr::arg_iterator I = CE->arg_begin(), E = CE->arg_end();
56 I != E; ++I) {
57
58 RVal V = StateMgr.GetRVal(St, *I);
59
60 if (isa<LVal>(V))
61 St = StateMgr.SetRVal(St, cast<LVal>(V), UnknownVal());
62 }
63
64 Builder.Nodify(Dst, CE, Pred, St);
65}