Zhongxing Xu | 66847a2 | 2009-09-11 04:13:42 +0000 | [diff] [blame] | 1 | //===--- 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 Xu | c9f4af6 | 2009-10-13 02:36:42 +0000 | [diff] [blame] | 14 | #include "clang/Analysis/PathSensitive/GRExprEngine.h" |
Zhongxing Xu | 66847a2 | 2009-09-11 04:13:42 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/PathSensitive/GRTransferFuncs.h" |
| 16 | |
| 17 | using namespace clang; |
| 18 | |
| 19 | namespace { |
| 20 | |
| 21 | class VISIBILITY_HIDDEN CallInliner : public GRTransferFuncs { |
| 22 | ASTContext &Ctx; |
| 23 | public: |
| 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 | |
| 34 | void CallInliner::EvalCall(ExplodedNodeSet& Dst, GRExprEngine& Engine, |
| 35 | GRStmtNodeBuilder& Builder, CallExpr* CE, SVal L, |
| 36 | ExplodedNode* Pred) { |
Zhongxing Xu | c9f4af6 | 2009-10-13 02:36:42 +0000 | [diff] [blame] | 37 | 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 Xu | 66847a2 | 2009-09-11 04:13:42 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | GRTransferFuncs *clang::CreateCallInliner(ASTContext &ctx) { |
| 74 | return new CallInliner(ctx); |
| 75 | } |