Benjamin Kramer | ee30965 | 2010-07-17 13:51:58 +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 | |
| 14 | #include "clang/Checker/PathSensitive/CheckerVisitor.h" |
| 15 | #include "clang/Checker/PathSensitive/GRState.h" |
| 16 | #include "clang/Checker/Checkers/LocalCheckers.h" |
| 17 | |
| 18 | using namespace clang; |
| 19 | |
| 20 | namespace { |
| 21 | class CallInliner : public Checker { |
| 22 | public: |
| 23 | static void *getTag() { |
| 24 | static int x; |
| 25 | return &x; |
| 26 | } |
| 27 | |
| 28 | virtual bool EvalCallExpr(CheckerContext &C, const CallExpr *CE); |
| 29 | }; |
| 30 | } |
| 31 | |
| 32 | void clang::RegisterCallInliner(GRExprEngine &Eng) { |
| 33 | Eng.registerCheck(new CallInliner()); |
| 34 | } |
| 35 | |
| 36 | bool CallInliner::EvalCallExpr(CheckerContext &C, const CallExpr *CE) { |
| 37 | const GRState *state = C.getState(); |
| 38 | const Expr *Callee = CE->getCallee(); |
| 39 | SVal L = state->getSVal(Callee); |
| 40 | |
| 41 | const FunctionDecl *FD = L.getAsFunctionDecl(); |
| 42 | if (!FD) |
| 43 | return false; |
| 44 | |
| 45 | if (!FD->hasBody(FD)) |
| 46 | return false; |
| 47 | |
| 48 | // Now we have the definition of the callee, create a CallEnter node. |
| 49 | CallEnter Loc(CE, FD, C.getPredecessor()->getLocationContext()); |
| 50 | C.addTransition(state, Loc); |
| 51 | |
| 52 | return true; |
| 53 | } |
| 54 | |