X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fbugpoint%2FMiscompilation.cpp;h=5574303321c822ebdeb40b4e7b56bfb2fe333883;hb=566fb9fe3ed767be7218fb1608ec6a284067d3b0;hp=f0ba24014cd08a4897dfe43974940de0e7291ac3;hpb=dab3d29605a5c83db41b28176273ef55961120c1;p=oota-llvm.git diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index f0ba24014cd..5574303321c 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -15,17 +15,17 @@ #include "BugDriver.h" #include "ListReducer.h" #include "ToolRunner.h" -#include "llvm/Constants.h" -#include "llvm/DerivedTypes.h" -#include "llvm/Instructions.h" +#include "llvm/Analysis/Verifier.h" +#include "llvm/Config/config.h" // for HAVE_LINK_R +#include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Module.h" #include "llvm/Linker.h" -#include "llvm/Module.h" #include "llvm/Pass.h" -#include "llvm/Analysis/Verifier.h" -#include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileUtilities.h" -#include "llvm/Config/config.h" // for HAVE_LINK_R +#include "llvm/Transforms/Utils/Cloning.h" using namespace llvm; namespace llvm { @@ -120,7 +120,7 @@ ReduceMiscompilingPasses::doTest(std::vector &Prefix, return InternalError; if (Diff) { outs() << " nope.\n"; - sys::Path(BitcodeResult).eraseFromDisk(); + sys::fs::remove(BitcodeResult); return KeepPrefix; } outs() << " yup.\n"; // No miscompilation! @@ -130,12 +130,12 @@ ReduceMiscompilingPasses::doTest(std::vector &Prefix, // OwningPtr PrefixOutput(ParseInputFile(BitcodeResult, BD.getContext())); - if (PrefixOutput == 0) { + if (!PrefixOutput) { errs() << BD.getToolName() << ": Error reading bitcode file '" << BitcodeResult << "'!\n"; exit(1); } - sys::Path(BitcodeResult).eraseFromDisk(); // No longer need the file on disk + sys::fs::remove(BitcodeResult); // Don't check if there are no passes in the suffix. if (Suffix.empty()) @@ -222,7 +222,7 @@ static Module *TestMergedProgram(const BugDriver &BD, Module *M1, Module *M2, M1 = CloneModule(M1); M2 = CloneModule(M2); } - if (Linker::LinkModules(M1, M2, &ErrorMsg)) { + if (Linker::LinkModules(M1, M2, Linker::DestroySource, &ErrorMsg)) { errs() << BD.getToolName() << ": Error linking modules together:" << ErrorMsg << '\n'; exit(1); @@ -396,7 +396,8 @@ static bool ExtractLoops(BugDriver &BD, // Replace the current program with the loop extracted version, and try to // extract another loop. std::string ErrorMsg; - if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted, &ErrorMsg)){ + if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted, + Linker::DestroySource, &ErrorMsg)){ errs() << BD.getToolName() << ": Error linking modules together:" << ErrorMsg << '\n'; exit(1); @@ -411,8 +412,6 @@ static bool ExtractLoops(BugDriver &BD, Function *NewF = ToNotOptimize->getFunction(MisCompFunctions[i].first); assert(NewF && "Function not found??"); - assert(NewF->getFunctionType() == MisCompFunctions[i].second && - "found wrong function type?"); MiscompiledFunctions.push_back(NewF); } @@ -577,7 +576,8 @@ static bool ExtractBlocks(BugDriver &BD, I->getFunctionType())); std::string ErrorMsg; - if (Linker::LinkModules(ProgClone, Extracted, &ErrorMsg)) { + if (Linker::LinkModules(ProgClone, Extracted, Linker::DestroySource, + &ErrorMsg)) { errs() << BD.getToolName() << ": Error linking modules together:" << ErrorMsg << '\n'; exit(1); @@ -593,8 +593,6 @@ static bool ExtractBlocks(BugDriver &BD, for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) { Function *NewF = ProgClone->getFunction(MisCompFunctions[i].first); assert(NewF && "Function not found??"); - assert(NewF->getFunctionType() == MisCompFunctions[i].second && - "Function has wrong type??"); MiscompiledFunctions.push_back(NewF); } @@ -822,7 +820,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, // 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 = ConstantArray::get(F->getContext(), F->getName()); + Constant *InitArray = + ConstantDataArray::getString(F->getContext(), F->getName()); GlobalVariable *funcName = new GlobalVariable(*Safe, InitArray->getType(), true /*isConstant*/, GlobalValue::InternalLinkage, InitArray, @@ -927,14 +926,16 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe, std::string &Error) { CleanupAndPrepareModules(BD, Test, Safe); - sys::Path TestModuleBC("bugpoint.test.bc"); - std::string ErrMsg; - if (TestModuleBC.makeUnique(true, &ErrMsg)) { + SmallString<128> TestModuleBC; + int TestModuleFD; + error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc", + TestModuleFD, TestModuleBC); + if (EC) { errs() << BD.getToolName() << "Error making unique filename: " - << ErrMsg << "\n"; + << EC.message() << "\n"; exit(1); } - if (BD.writeProgramToFile(TestModuleBC.str(), Test)) { + if (BD.writeProgramToFile(TestModuleBC.str(), TestModuleFD, Test)) { errs() << "Error writing bitcode to `" << TestModuleBC.str() << "'\nExiting."; exit(1); @@ -944,14 +945,17 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe, FileRemover TestModuleBCRemover(TestModuleBC.str(), !SaveTemps); // Make the shared library - sys::Path SafeModuleBC("bugpoint.safe.bc"); - if (SafeModuleBC.makeUnique(true, &ErrMsg)) { + SmallString<128> SafeModuleBC; + int SafeModuleFD; + EC = sys::fs::createTemporaryFile("bugpoint.safe", "bc", SafeModuleFD, + SafeModuleBC); + if (EC) { errs() << BD.getToolName() << "Error making unique filename: " - << ErrMsg << "\n"; + << EC.message() << "\n"; exit(1); } - if (BD.writeProgramToFile(SafeModuleBC.str(), Safe)) { + if (BD.writeProgramToFile(SafeModuleBC.str(), SafeModuleFD, Safe)) { errs() << "Error writing bitcode to `" << SafeModuleBC.str() << "'\nExiting."; exit(1); @@ -1016,15 +1020,17 @@ bool BugDriver::debugCodeGenerator(std::string *Error) { // Condition the modules CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen); - sys::Path TestModuleBC("bugpoint.test.bc"); - std::string ErrMsg; - if (TestModuleBC.makeUnique(true, &ErrMsg)) { + SmallString<128> TestModuleBC; + int TestModuleFD; + error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc", + TestModuleFD, TestModuleBC); + if (EC) { errs() << getToolName() << "Error making unique filename: " - << ErrMsg << "\n"; + << EC.message() << "\n"; exit(1); } - if (writeProgramToFile(TestModuleBC.str(), ToCodeGen)) { + if (writeProgramToFile(TestModuleBC.str(), TestModuleFD, ToCodeGen)) { errs() << "Error writing bitcode to `" << TestModuleBC.str() << "'\nExiting."; exit(1); @@ -1032,14 +1038,17 @@ bool BugDriver::debugCodeGenerator(std::string *Error) { delete ToCodeGen; // Make the shared library - sys::Path SafeModuleBC("bugpoint.safe.bc"); - if (SafeModuleBC.makeUnique(true, &ErrMsg)) { + SmallString<128> SafeModuleBC; + int SafeModuleFD; + EC = sys::fs::createTemporaryFile("bugpoint.safe", "bc", SafeModuleFD, + SafeModuleBC); + if (EC) { errs() << getToolName() << "Error making unique filename: " - << ErrMsg << "\n"; + << EC.message() << "\n"; exit(1); } - if (writeProgramToFile(SafeModuleBC.str(), ToNotCodeGen)) { + if (writeProgramToFile(SafeModuleBC.str(), SafeModuleFD, ToNotCodeGen)) { errs() << "Error writing bitcode to `" << SafeModuleBC.str() << "'\nExiting."; exit(1);