blob: 43523c293d585fcc8c4bb57eeec630cc9ed40838 [file] [log] [blame]
Zhongxing Xu66847a22009-09-11 04:13:42 +00001//===--- CallInliner.cpp - Transfer function that inlines callee ----------===//
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 implements the callee inlining transfer function.
11//
12//===----------------------------------------------------------------------===//
13
Zhongxing Xuc9f4af62009-10-13 02:36:42 +000014#include "clang/Analysis/PathSensitive/GRExprEngine.h"
Zhongxing Xu66847a22009-09-11 04:13:42 +000015#include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
16
17using namespace clang;
18
19namespace {
20
Kovarththanan Rajaratnamba5fb5a2009-11-28 06:07:30 +000021class CallInliner : public GRTransferFuncs {
Zhongxing Xu66847a22009-09-11 04:13:42 +000022 ASTContext &Ctx;
23public:
24 CallInliner(ASTContext &ctx) : Ctx(ctx) {}
25
26 void EvalCall(ExplodedNodeSet& Dst, GRExprEngine& Engine,
27 GRStmtNodeBuilder& Builder, CallExpr* CE, SVal L,
28 ExplodedNode* Pred);
29
30};
31
32}
33
34void CallInliner::EvalCall(ExplodedNodeSet& Dst, GRExprEngine& Engine,
35 GRStmtNodeBuilder& Builder, CallExpr* CE, SVal L,
36 ExplodedNode* Pred) {
Zhongxing Xuc9f4af62009-10-13 02:36:42 +000037 FunctionDecl const *FD = L.getAsFunctionDecl();
38 if (!FD)
39 return; // GRExprEngine is responsible for the autotransition.
40
41 // Make a new LocationContext.
42 StackFrameContext const *LocCtx =
43 Engine.getAnalysisManager().getStackFrame(FD, Pred->getLocationContext(), CE);
44
45 CFGBlock const *Entry = &(LocCtx->getCFG()->getEntry());
46
47 assert (Entry->empty() && "Entry block must be empty.");
48
49 assert (Entry->succ_size() == 1 && "Entry block must have 1 successor.");
50
51 // Get the solitary successor.
52 CFGBlock const *SuccB = *(Entry->succ_begin());
53
54 // Construct an edge representing the starting location in the function.
55 BlockEdge Loc(Entry, SuccB, LocCtx);
56
57 GRState const *state = Builder.GetState(Pred);
58 state = Engine.getStoreManager().EnterStackFrame(state, LocCtx);
59
60 bool isNew;
61 ExplodedNode *SuccN = Engine.getGraph().getNode(Loc, state, &isNew);
62 SuccN->addPredecessor(Pred, Engine.getGraph());
63
64 Builder.Deferred.erase(Pred);
65
66 // This is a hack. We really should not use the GRStmtNodeBuilder.
67 if (isNew)
68 Builder.getWorkList()->Enqueue(SuccN);
69
70 Builder.HasGeneratedNode = true;
Zhongxing Xu66847a22009-09-11 04:13:42 +000071}
72
73GRTransferFuncs *clang::CreateCallInliner(ASTContext &ctx) {
74 return new CallInliner(ctx);
75}