opnsense-src/lib/Checker/CallInliner.cpp

55 lines
1.4 KiB
C++
Raw Normal View History

2009-10-14 14:03:49 -04: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-02-16 04:31:36 -05:00
#include "clang/Checker/PathSensitive/CheckerVisitor.h"
#include "clang/Checker/PathSensitive/GRState.h"
#include "clang/Checker/Checkers/LocalCheckers.h"
2009-10-14 14:03:49 -04:00
using namespace clang;
namespace {
2010-01-01 05:34:51 -05:00
class CallInliner : public Checker {
2009-10-14 14:03:49 -04:00
public:
2010-01-01 05:34:51 -05:00
static void *getTag() {
static int x;
return &x;
}
2009-10-14 14:03:49 -04:00
2010-01-01 05:34:51 -05:00
virtual bool EvalCallExpr(CheckerContext &C, const CallExpr *CE);
2009-10-14 14:03:49 -04:00
};
2010-01-01 05:34:51 -05:00
}
2009-10-14 14:03:49 -04:00
2010-01-01 05:34:51 -05:00
void clang::RegisterCallInliner(GRExprEngine &Eng) {
Eng.registerCheck(new CallInliner());
2009-10-14 14:03:49 -04:00
}
2010-01-01 05:34:51 -05:00
bool CallInliner::EvalCallExpr(CheckerContext &C, const CallExpr *CE) {
const GRState *state = C.getState();
const Expr *Callee = CE->getCallee();
SVal L = state->getSVal(Callee);
const FunctionDecl *FD = L.getAsFunctionDecl();
2009-10-14 14:03:49 -04:00
if (!FD)
2010-01-01 05:34:51 -05:00
return false;
2010-03-03 12:28:16 -05:00
if (!FD->getBody(FD))
2010-01-01 05:34:51 -05:00
return false;
2009-10-14 14:03:49 -04:00
2010-03-03 12:28:16 -05:00
// Now we have the definition of the callee, create a CallEnter node.
CallEnter Loc(CE, FD, C.getPredecessor()->getLocationContext());
C.addTransition(state, Loc);
2010-01-01 05:34:51 -05:00
return true;
2009-10-14 14:03:49 -04:00
}
2010-01-01 05:34:51 -05:00