return Interpreter == 0;
}
-/// compileProgram - Try to compile the specified module, throwing an exception
-/// if an error occurs, or returning normally if not. This is used for code
-/// generation crash testing.
+/// compileProgram - Try to compile the specified module, returning false and
+/// setting Error if an error occurs. This is used for code generation
+/// crash testing.
///
-void BugDriver::compileProgram(Module *M) {
+void BugDriver::compileProgram(Module *M, std::string *Error) {
// Emit the program to a bitcode file...
sys::Path BitcodeFile (OutputPrefix + "-test-program.bc");
std::string ErrMsg;
- if (BitcodeFile.makeUnique(true,&ErrMsg)) {
+ if (BitcodeFile.makeUnique(true, &ErrMsg)) {
errs() << ToolName << ": Error making unique filename: " << ErrMsg
<< "\n";
exit(1);
exit(1);
}
- // Remove the temporary bitcode file when we are done.
+ // Remove the temporary bitcode file when we are done.
FileRemover BitcodeFileRemover(BitcodeFile, !SaveTemps);
// Actually compile the program!
- Interpreter->compileProgram(BitcodeFile.str());
+ Interpreter->compileProgram(BitcodeFile.str(), Error);
}
std::string BugDriver::executeProgram(std::string OutputFile,
std::string BitcodeFile,
const std::string &SharedObj,
- AbstractInterpreter *AI) {
+ AbstractInterpreter *AI,
+ std::string *Error) {
if (AI == 0) AI = Interpreter;
assert(AI && "Interpreter should have been created already!");
bool CreatedBitcode = false;
if (!SharedObj.empty())
SharedObjs.push_back(SharedObj);
- int RetVal = AI->ExecuteProgram(BitcodeFile, InputArgv, InputFile,
- OutputFile, AdditionalLinkerArgs, SharedObjs,
+ int RetVal = AI->ExecuteProgram(BitcodeFile, InputArgv, InputFile, OutputFile,
+ Error, AdditionalLinkerArgs, SharedObjs,
Timeout, MemoryLimit);
+ if (!Error->empty())
+ return OutputFile;
if (RetVal == -1) {
errs() << "<timeout>";
/// executeProgramSafely - Used to create reference output with the "safe"
/// backend, if reference output is not provided.
///
-std::string BugDriver::executeProgramSafely(std::string OutputFile) {
- std::string outFN = executeProgram(OutputFile, "", "", SafeInterpreter);
- return outFN;
+std::string BugDriver::executeProgramSafely(std::string OutputFile,
+ std::string *Error) {
+ return executeProgram(OutputFile, "", "", SafeInterpreter, Error);
}
-std::string BugDriver::compileSharedObject(const std::string &BitcodeFile) {
+std::string BugDriver::compileSharedObject(const std::string &BitcodeFile,
+ std::string &Error) {
assert(Interpreter && "Interpreter should have been created already!");
sys::Path OutputFile;
// Using the known-good backend.
- GCC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile);
+ GCC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile,
+ Error);
+ if (!Error.empty())
+ return "";
std::string SharedObjectFile;
- if (gcc->MakeSharedObject(OutputFile.str(), FT,
- SharedObjectFile, AdditionalLinkerArgs))
+ bool Failure = gcc->MakeSharedObject(OutputFile.str(), FT, SharedObjectFile,
+ AdditionalLinkerArgs, Error);
+ if (!Error.empty())
+ return "";
+ if (Failure)
exit(1);
// Remove the intermediate C file
/// this function.
///
bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
- try {
- compileProgram(Program);
- } catch (ToolExecutionError &) {
+ std::string Error;
+ compileProgram(Program, &Error);
+ if (!Error.empty())
return false;
- }
- try {
- ReferenceOutputFile = executeProgramSafely(Filename);
- outs() << "\nReference output is: " << ReferenceOutputFile << "\n\n";
- } catch (ToolExecutionError &TEE) {
- errs() << TEE.what();
+
+ ReferenceOutputFile = executeProgramSafely(Filename, &Error);
+ if (!Error.empty()) {
+ errs() << Error;
if (Interpreter != SafeInterpreter) {
errs() << "*** There is a bug running the \"safe\" backend. Either"
<< " debug it (for example with the -run-cbe bugpoint option,"
}
return false;
}
+ outs() << "\nReference output is: " << ReferenceOutputFile << "\n\n";
return true;
}
/// diffProgram - This method executes the specified module and diffs the
/// output against the file specified by ReferenceOutputFile. If the output
-/// is different, true is returned. If there is a problem with the code
-/// generator (e.g., llc crashes), this will throw an exception.
+/// is different, 1 is returned. If there is a problem with the code
+/// generator (e.g., llc crashes), this will return -1 and set Error.
///
bool BugDriver::diffProgram(const std::string &BitcodeFile,
const std::string &SharedObject,
- bool RemoveBitcode) {
+ bool RemoveBitcode,
+ std::string *ErrMsg) {
// Execute the program, generating an output file...
- sys::Path Output(executeProgram("", BitcodeFile, SharedObject, 0));
+ sys::Path Output(executeProgram("", BitcodeFile, SharedObject, 0, ErrMsg));
+ if (!ErrMsg->empty())
+ return false;
std::string Error;
bool FilesDifferent = false;