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 | |
Ted Kremenek | 1309f9a | 2010-01-25 04:41:41 +0000 | [diff] [blame] | 14 | #include "clang/Checker/PathSensitive/CheckerVisitor.h" |
| 15 | #include "clang/Checker/PathSensitive/GRState.h" |
Ted Kremenek | 9705309 | 2010-01-26 22:59:55 +0000 | [diff] [blame] | 16 | #include "clang/Checker/Checkers/LocalCheckers.h" |
Zhongxing Xu | 66847a2 | 2009-09-11 04:13:42 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace clang; |
| 19 | |
| 20 | namespace { |
Zhongxing Xu | 3ff8481 | 2009-12-23 08:56:18 +0000 | [diff] [blame] | 21 | class CallInliner : public Checker { |
Zhongxing Xu | 66847a2 | 2009-09-11 04:13:42 +0000 | [diff] [blame] | 22 | public: |
Zhongxing Xu | 3ff8481 | 2009-12-23 08:56:18 +0000 | [diff] [blame] | 23 | static void *getTag() { |
| 24 | static int x; |
| 25 | return &x; |
| 26 | } |
Zhongxing Xu | 66847a2 | 2009-09-11 04:13:42 +0000 | [diff] [blame] | 27 | |
Zhongxing Xu | 3ff8481 | 2009-12-23 08:56:18 +0000 | [diff] [blame] | 28 | virtual bool EvalCallExpr(CheckerContext &C, const CallExpr *CE); |
Zhongxing Xu | 66847a2 | 2009-09-11 04:13:42 +0000 | [diff] [blame] | 29 | }; |
Zhongxing Xu | 66847a2 | 2009-09-11 04:13:42 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Zhongxing Xu | 3ff8481 | 2009-12-23 08:56:18 +0000 | [diff] [blame] | 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(); |
Ted Kremenek | 1397663 | 2010-02-08 16:18:51 +0000 | [diff] [blame] | 39 | SVal L = state->getSVal(Callee); |
Zhongxing Xu | 62d399e | 2009-12-24 03:34:38 +0000 | [diff] [blame] | 40 | |
Zhongxing Xu | 3ff8481 | 2009-12-23 08:56:18 +0000 | [diff] [blame] | 41 | const FunctionDecl *FD = L.getAsFunctionDecl(); |
Zhongxing Xu | c9f4af6 | 2009-10-13 02:36:42 +0000 | [diff] [blame] | 42 | if (!FD) |
Zhongxing Xu | 3ff8481 | 2009-12-23 08:56:18 +0000 | [diff] [blame] | 43 | return false; |
| 44 | |
| 45 | if (!FD->isThisDeclarationADefinition()) |
| 46 | return false; |
Zhongxing Xu | c9f4af6 | 2009-10-13 02:36:42 +0000 | [diff] [blame] | 47 | |
Douglas Gregor | 102acd5 | 2010-02-25 19:01:53 +0000 | [diff] [blame^] | 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); |
Zhongxing Xu | 3ff8481 | 2009-12-23 08:56:18 +0000 | [diff] [blame] | 51 | |
| 52 | return true; |
Zhongxing Xu | 66847a2 | 2009-09-11 04:13:42 +0000 | [diff] [blame] | 53 | } |
Zhongxing Xu | 3ff8481 | 2009-12-23 08:56:18 +0000 | [diff] [blame] | 54 | |