2009-09-11 12:13:42 +08:00
|
|
|
//===--- CallInliner.cpp - Transfer function that inlines callee ----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the callee inlining transfer function.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-25 12:41:41 +08:00
|
|
|
#include "clang/Checker/PathSensitive/CheckerVisitor.h"
|
|
|
|
#include "clang/Checker/PathSensitive/GRState.h"
|
2010-01-27 06:59:55 +08:00
|
|
|
#include "clang/Checker/Checkers/LocalCheckers.h"
|
2009-09-11 12:13:42 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
namespace {
|
2009-12-23 16:56:18 +08:00
|
|
|
class CallInliner : public Checker {
|
2009-09-11 12:13:42 +08:00
|
|
|
public:
|
2009-12-23 16:56:18 +08:00
|
|
|
static void *getTag() {
|
|
|
|
static int x;
|
|
|
|
return &x;
|
|
|
|
}
|
2009-09-11 12:13:42 +08:00
|
|
|
|
2009-12-23 16:56:18 +08:00
|
|
|
virtual bool EvalCallExpr(CheckerContext &C, const CallExpr *CE);
|
2009-09-11 12:13:42 +08:00
|
|
|
};
|
2009-12-23 16:56:18 +08:00
|
|
|
}
|
2009-09-11 12:13:42 +08:00
|
|
|
|
2009-12-23 16:56:18 +08:00
|
|
|
void clang::RegisterCallInliner(GRExprEngine &Eng) {
|
|
|
|
Eng.registerCheck(new CallInliner());
|
2009-09-11 12:13:42 +08:00
|
|
|
}
|
|
|
|
|
2009-12-23 16:56:18 +08:00
|
|
|
bool CallInliner::EvalCallExpr(CheckerContext &C, const CallExpr *CE) {
|
|
|
|
const GRState *state = C.getState();
|
|
|
|
const Expr *Callee = CE->getCallee();
|
2010-02-09 00:18:51 +08:00
|
|
|
SVal L = state->getSVal(Callee);
|
2009-12-24 11:34:38 +08:00
|
|
|
|
2009-12-23 16:56:18 +08:00
|
|
|
const FunctionDecl *FD = L.getAsFunctionDecl();
|
2009-10-13 10:36:42 +08:00
|
|
|
if (!FD)
|
2009-12-23 16:56:18 +08:00
|
|
|
return false;
|
|
|
|
|
2010-02-28 14:39:11 +08:00
|
|
|
if (!FD->getBody(FD))
|
2009-12-23 16:56:18 +08:00
|
|
|
return false;
|
2009-10-13 10:36:42 +08:00
|
|
|
|
2010-02-26 03:01:53 +08:00
|
|
|
// Now we have the definition of the callee, create a CallEnter node.
|
|
|
|
CallEnter Loc(CE, FD, C.getPredecessor()->getLocationContext());
|
|
|
|
C.addTransition(state, Loc);
|
2009-12-23 16:56:18 +08:00
|
|
|
|
|
|
|
return true;
|
2009-09-11 12:13:42 +08:00
|
|
|
}
|
2009-12-23 16:56:18 +08:00
|
|
|
|