#include "BugDriver.h"
#include "ListReducer.h"
+#include "ToolRunner.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
DisableLoopExtraction("disable-loop-extraction",
cl::desc("Don't extract loops when searching for miscompilations"),
cl::init(false));
+ static llvm::cl::opt<bool>
+ DisableBlockExtraction("disable-block-extraction",
+ cl::desc("Don't extract blocks when searching for miscompilations"),
+ cl::init(false));
class ReduceMiscompilingPasses : public ListReducer<const PassInfo*> {
BugDriver &BD;
I->setName(Mang.getMangledName(I));
}
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {
- // Don't mangle asm names.
- if (!I->hasName() || I->getName()[0] != 1)
+ // Don't mangle asm names or intrinsics.
+ if ((!I->hasName() || I->getName()[0] != 1) &&
+ I->getIntrinsicID() == 0)
I->setName(Mang.getMangledName(I));
}
}
outs() << '\n';
}
- if (!BugpointIsInterrupted &&
+ if (!BugpointIsInterrupted && !DisableBlockExtraction &&
ExtractBlocks(BD, TestFn, MiscompiledFunctions)) {
// Okay, we extracted some blocks and the problem still appears. See if we
// can eliminate some of the created functions from being candidates.
///
static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
Module *Safe) {
- LLVMContext &Context = BD.getContext();
-
// Clean up the modules, removing extra cruft that we don't need anymore...
Test = BD.performFinalCleanups(Test);
}
// Call the old main function and return its result
- BasicBlock *BB = BasicBlock::Create("entry", newMain);
+ BasicBlock *BB = BasicBlock::Create(Safe->getContext(), "entry", newMain);
CallInst *call = CallInst::Create(oldMainProto, args.begin(), args.end(),
"", BB);
// If the type of old function wasn't void, return value of call
- ReturnInst::Create(call, BB);
+ ReturnInst::Create(Safe->getContext(), call, BB);
}
// The second nasty issue we must deal with in the JIT is that the Safe
// Prototype: void *getPointerToNamedFunction(const char* Name)
Constant *resolverFunc =
Safe->getOrInsertFunction("getPointerToNamedFunction",
- Context.getPointerTypeUnqual(Type::Int8Ty),
- Context.getPointerTypeUnqual(Type::Int8Ty), (Type *)0);
+ PointerType::getUnqual(Type::getInt8Ty(Safe->getContext())),
+ PointerType::getUnqual(Type::getInt8Ty(Safe->getContext())),
+ (Type *)0);
// Use the function we just added to get addresses of functions we need.
for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) {
// Don't forward functions which are external in the test module too.
if (TestFn && !TestFn->isDeclaration()) {
// 1. Add a string constant with its name to the global file
- Constant *InitArray = Context.getConstantArray(F->getName());
+ Constant *InitArray = ConstantArray::get(F->getContext(), F->getName());
GlobalVariable *funcName =
new GlobalVariable(*Safe, InitArray->getType(), true /*isConstant*/,
GlobalValue::InternalLinkage, InitArray,
// sbyte* so it matches the signature of the resolver function.
// GetElementPtr *funcName, ulong 0, ulong 0
- std::vector<Constant*> GEPargs(2, Context.getNullValue(Type::Int32Ty));
+ std::vector<Constant*> GEPargs(2,
+ Constant::getNullValue(Type::getInt32Ty(F->getContext())));
Value *GEP =
- Context.getConstantExprGetElementPtr(funcName, &GEPargs[0], 2);
+ ConstantExpr::getGetElementPtr(funcName, &GEPargs[0], 2);
std::vector<Value*> ResolverArgs;
ResolverArgs.push_back(GEP);
// function that dynamically resolves the calls to F via our JIT API
if (!F->use_empty()) {
// Create a new global to hold the cached function pointer.
- Constant *NullPtr = Context.getConstantPointerNull(F->getType());
+ Constant *NullPtr = ConstantPointerNull::get(F->getType());
GlobalVariable *Cache =
new GlobalVariable(*F->getParent(), F->getType(),
false, GlobalValue::InternalLinkage,
GlobalValue::InternalLinkage,
F->getName() + "_wrapper",
F->getParent());
- BasicBlock *EntryBB = BasicBlock::Create("entry", FuncWrapper);
- BasicBlock *DoCallBB = BasicBlock::Create("usecache", FuncWrapper);
- BasicBlock *LookupBB = BasicBlock::Create("lookupfp", FuncWrapper);
+ BasicBlock *EntryBB = BasicBlock::Create(F->getContext(),
+ "entry", FuncWrapper);
+ BasicBlock *DoCallBB = BasicBlock::Create(F->getContext(),
+ "usecache", FuncWrapper);
+ BasicBlock *LookupBB = BasicBlock::Create(F->getContext(),
+ "lookupfp", FuncWrapper);
// Check to see if we already looked up the value.
Value *CachedVal = new LoadInst(Cache, "fpcache", EntryBB);
// Cast the result from the resolver to correctly-typed function.
CastInst *CastedResolver =
new BitCastInst(Resolver,
- Context.getPointerTypeUnqual(F->getFunctionType()),
+ PointerType::getUnqual(F->getFunctionType()),
"resolverCast", LookupBB);
// Save the value in our cache.
Args.push_back(i);
// Pass on the arguments to the real function, return its result
- if (F->getReturnType() == Type::VoidTy) {
+ if (F->getReturnType() == Type::getVoidTy(F->getContext())) {
CallInst::Create(FuncPtr, Args.begin(), Args.end(), "", DoCallBB);
- ReturnInst::Create(DoCallBB);
+ ReturnInst::Create(F->getContext(), DoCallBB);
} else {
CallInst *Call = CallInst::Create(FuncPtr, Args.begin(), Args.end(),
"retval", DoCallBB);
- ReturnInst::Create(Call, DoCallBB);
+ ReturnInst::Create(F->getContext(),Call, DoCallBB);
}
// Use the wrapper function instead of the old function
outs() << '\n';
outs() << "The shared object was created with:\n llc -march=c "
<< SafeModuleBC << " -o temporary.c\n"
- << " gcc -xc temporary.c -O2 -o " << SharedObject
-#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
- << " -G" // Compile a shared library, `-G' for Sparc
-#else
- << " -fPIC -shared" // `-shared' for Linux/X86, maybe others
-#endif
- << " -fno-strict-aliasing\n";
+ << " gcc -xc temporary.c -O2 -o " << SharedObject;
+ if (TargetTriple.getArch() == Triple::sparc)
+ outs() << " -G"; // Compile a shared library, `-G' for Sparc
+ else
+ outs() << " -fPIC -shared"; // `-shared' for Linux/X86, maybe others
+
+ outs() << " -fno-strict-aliasing\n";
return false;
}