aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorLukas Zaoral <lzaoral@redhat.com>2020-09-12 11:02:29 +0200
committerCristian Cadar <c.cadar@imperial.ac.uk>2020-09-26 21:31:49 +0100
commit3983b23eac93b0e6f28ffba4b626401c5280c10f (patch)
tree5589ff2a11f892cb4911c235e7856ef965cc4059 /lib
parente9aaebb43b5789692377e7b367813e8b3b728484 (diff)
downloadklee-3983b23eac93b0e6f28ffba4b626401c5280c10f.tar.gz
Replace llvm::CallSite with llvm::CallBase on LLVM 8+
This is in preparation for LLVM 11 as the llvm:CallSite class has been removed.
Diffstat (limited to 'lib')
-rw-r--r--lib/Core/Executor.cpp36
-rw-r--r--lib/Core/ExternalDispatcher.cpp18
-rw-r--r--lib/Core/Searcher.cpp1
-rw-r--r--lib/Core/StatsTracker.cpp19
-rw-r--r--lib/Module/KModule.cpp10
-rw-r--r--lib/Module/ModuleUtil.cpp17
6 files changed, 75 insertions, 26 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index ea3fffb7..48252dbd 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -55,7 +55,9 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
+#if LLVM_VERSION_CODE < LLVM_VERSION(8, 0)
#include "llvm/IR/CallSite.h"
+#endif
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
@@ -1570,13 +1572,17 @@ void Executor::executeCall(ExecutionState &state, KInstruction *ki, Function *f,
uint64_t offsets[callingArgs]; // offsets of variadic arguments
uint64_t argWidth; // width of current variadic argument
- CallSite cs(i);
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+ const CallBase &cs = cast<CallBase>(*i);
+#else
+ const CallSite cs(i);
+#endif
for (unsigned k = funcArgs; k < callingArgs; k++) {
if (cs.isByValArgument(k)) {
#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0)
Type *t = cs.getParamByValType(k);
#else
- auto arg = cs.getArgument(k);
+ auto arg = cs.getArgOperand(k);
Type *t = arg->getType();
assert(t->isPointerTy());
t = t->getPointerElementType();
@@ -1770,8 +1776,13 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
Expr::Width to = getWidthForLLVMType(t);
if (from != to) {
- CallSite cs = (isa<InvokeInst>(caller) ? CallSite(cast<InvokeInst>(caller)) :
- CallSite(cast<CallInst>(caller)));
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+ const CallBase &cs = cast<CallBase>(*caller);
+#else
+ const CallSite cs(isa<InvokeInst>(caller)
+ ? CallSite(cast<InvokeInst>(caller))
+ : CallSite(cast<CallInst>(caller)));
+#endif
// XXX need to check other param attrs ?
#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
@@ -2036,7 +2047,12 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
// Ignore debug intrinsic calls
if (isa<DbgInfoIntrinsic>(i))
break;
- CallSite cs(i);
+
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+ const CallBase &cs = cast<CallBase>(*i);
+#else
+ const CallSite cs(i);
+#endif
unsigned numArgs = cs.arg_size();
Value *fp = cs.getCalledValue();
@@ -4138,10 +4154,14 @@ size_t Executor::getAllocationAlignment(const llvm::Value *allocSite) const {
type = AI->getAllocatedType();
} else if (isa<InvokeInst>(allocSite) || isa<CallInst>(allocSite)) {
// FIXME: Model the semantics of the call to use the right alignment
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+ const CallBase &cs = cast<CallBase>(*allocSite);
+#else
llvm::Value *allocSiteNonConst = const_cast<llvm::Value *>(allocSite);
- const CallSite cs = (isa<InvokeInst>(allocSiteNonConst)
- ? CallSite(cast<InvokeInst>(allocSiteNonConst))
- : CallSite(cast<CallInst>(allocSiteNonConst)));
+ const CallSite cs(isa<InvokeInst>(allocSiteNonConst)
+ ? CallSite(cast<InvokeInst>(allocSiteNonConst))
+ : CallSite(cast<CallInst>(allocSiteNonConst)));
+#endif
llvm::Function *fn =
klee::getDirectCallTarget(cs, /*moduleIsFullyLinked=*/true);
if (fn)
diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp
index 2b537b7d..7ba8df53 100644
--- a/lib/Core/ExternalDispatcher.cpp
+++ b/lib/Core/ExternalDispatcher.cpp
@@ -10,7 +10,9 @@
#include "ExternalDispatcher.h"
#include "klee/Config/Version.h"
+#if LLVM_VERSION_CODE < LLVM_VERSION(8, 0)
#include "llvm/IR/CallSite.h"
+#endif
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
@@ -256,12 +258,13 @@ Function *ExternalDispatcherImpl::createDispatcher(Function *target,
if (!resolveSymbol(target->getName()))
return 0;
- CallSite cs;
- if (inst->getOpcode() == Instruction::Call) {
- cs = CallSite(cast<CallInst>(inst));
- } else {
- cs = CallSite(cast<InvokeInst>(inst));
- }
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+ const CallBase &cs = cast<CallBase>(*inst);
+#else
+ const CallSite cs(inst->getOpcode() == Instruction::Call
+ ? CallSite(cast<CallInst>(inst))
+ : CallSite(cast<InvokeInst>(inst)));
+#endif
Value **args = new Value *[cs.arg_size()];
@@ -292,8 +295,7 @@ Function *ExternalDispatcherImpl::createDispatcher(Function *target,
// Each argument will be passed by writing it into gTheArgsP[i].
unsigned i = 0, idx = 2;
- for (CallSite::arg_iterator ai = cs.arg_begin(), ae = cs.arg_end(); ai != ae;
- ++ai, ++i) {
+ for (auto ai = cs.arg_begin(), ae = cs.arg_end(); ai != ae; ++ai, ++i) {
// Determine the type the argument will be passed as. This accommodates for
// the corresponding code in Executor.cpp for handling calls to bitcasted
// functions.
diff --git a/lib/Core/Searcher.cpp b/lib/Core/Searcher.cpp
index 32a1e1bd..37c40897 100644
--- a/lib/Core/Searcher.cpp
+++ b/lib/Core/Searcher.cpp
@@ -26,7 +26,6 @@
#include "klee/Support/ModuleUtil.h"
#include "klee/System/Time.h"
-#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
index 4b4dc47c..a94bad9e 100644
--- a/lib/Core/StatsTracker.cpp
+++ b/lib/Core/StatsTracker.cpp
@@ -29,8 +29,10 @@
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/IR/BasicBlock.h"
-#include "llvm/IR/CFG.h"
+#if LLVM_VERSION_CODE < LLVM_VERSION(8, 0)
#include "llvm/IR/CallSite.h"
+#endif
+#include "llvm/IR/CFG.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/Instructions.h"
@@ -137,8 +139,13 @@ static bool instructionIsCoverable(Instruction *i) {
} else {
Instruction *prev = &*(--it);
if (isa<CallInst>(prev) || isa<InvokeInst>(prev)) {
- Function *target =
- getDirectCallTarget(CallSite(prev), /*moduleIsFullyLinked=*/true);
+ Function *target = getDirectCallTarget(
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+ cast<CallBase>(*prev),
+#else
+ CallSite(prev),
+#endif
+ /*moduleIsFullyLinked=*/true);
if (target && target->doesNotReturn())
return false;
}
@@ -788,7 +795,11 @@ void StatsTracker::computeReachableUncovered() {
it != ie; ++it) {
Instruction *inst = &*it;
if (isa<CallInst>(inst) || isa<InvokeInst>(inst)) {
- CallSite cs(inst);
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+ const CallBase &cs = cast<CallBase>(*inst);
+#else
+ const CallSite cs(inst);
+#endif
if (isa<InlineAsm>(cs.getCalledValue())) {
// We can never call through here so assume no targets
// (which should be correct anyhow).
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index 04c8f09f..b16be68a 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -27,7 +27,9 @@
#else
#include "llvm/Bitcode/ReaderWriter.h"
#endif
+#if LLVM_VERSION_CODE < LLVM_VERSION(8, 0)
#include "llvm/IR/CallSite.h"
+#endif
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
@@ -471,13 +473,17 @@ KFunction::KFunction(llvm::Function *_function,
ki->dest = registerMap[inst];
if (isa<CallInst>(it) || isa<InvokeInst>(it)) {
- CallSite cs(inst);
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+ const CallBase &cs = cast<CallBase>(*inst);
+#else
+ const CallSite cs(inst);
+#endif
unsigned numArgs = cs.arg_size();
ki->operands = new int[numArgs+1];
ki->operands[0] = getOperandNum(cs.getCalledValue(), registerMap, km,
ki);
for (unsigned j=0; j<numArgs; j++) {
- Value *v = cs.getArgument(j);
+ Value *v = cs.getArgOperand(j);
ki->operands[j+1] = getOperandNum(v, registerMap, km, ki);
}
} else {
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
index f369258a..bce6de97 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -251,7 +251,13 @@ klee::linkModules(std::vector<std::unique_ptr<llvm::Module>> &modules,
return composite;
}
-Function *klee::getDirectCallTarget(CallSite cs, bool moduleIsFullyLinked) {
+Function *klee::getDirectCallTarget(
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+ const CallBase &cs,
+#else
+ const CallSite &cs,
+#endif
+ bool moduleIsFullyLinked) {
Value *v = cs.getCalledValue();
bool viaConstantExpr = false;
// Walk through aliases and bitcasts to try to find
@@ -287,11 +293,16 @@ Function *klee::getDirectCallTarget(CallSite cs, bool moduleIsFullyLinked) {
static bool valueIsOnlyCalled(const Value *v) {
for (auto user : v->users()) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+ // Make sure the instruction is a call or invoke.
+ if (const auto *cs_ptr = dyn_cast<CallBase>(user)) {
+ const CallBase &cs = *cs_ptr;
+#else
if (const auto *instr = dyn_cast<Instruction>(user)) {
// Make sure the instruction is a call or invoke.
- CallSite cs(const_cast<Instruction *>(instr));
+ const CallSite cs(const_cast<Instruction *>(instr));
if (!cs) return false;
-
+#endif
// Make sure that the value is only the target of this call and
// not an argument.
if (cs.hasArgument(v))