1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

UnitTests: Do not use assert() for error checking

Use `if (!X) report_fatal_error()` instead of `assert()` for the ad-hoc
error handling in two unittests. This reduces unnecessary differences
between release and debug builds (motivated by unused variable warnings
triggered in release builds).

llvm-svn: 304814
This commit is contained in:
Matthias Braun 2017-06-06 19:00:54 +00:00
parent 19b1b3ab88
commit b284315918
2 changed files with 12 additions and 7 deletions

View File

@ -151,7 +151,8 @@ body: |
std::unique_ptr<MIRParser> MIR;
std::unique_ptr<Module> M = parseMIR(Context, PM, MIR, *TM, MIRString,
"func");
assert(M && "MIR parsing successfull");
if (!M)
report_fatal_error("Could not parse MIR code\n");
PM.add(new TestPass(T));

View File

@ -21,7 +21,8 @@ std::unique_ptr<TargetMachine> createTargetMachine() {
std::string Error;
const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
assert(TheTarget && "Target not registered");
if (!TheTarget)
report_fatal_error("Target not registered");
return std::unique_ptr<TargetMachine>(
TheTarget->createTargetMachine(TT, CPU, FS, TargetOptions(), None,
@ -58,21 +59,24 @@ void runChecks(
std::unique_ptr<MemoryBuffer> MBuffer = MemoryBuffer::getMemBuffer(MIRString);
std::unique_ptr<MIRParser> MParser =
createMIRParser(std::move(MBuffer), Context);
assert(MParser && "Couldn't create MIR parser");
if (!MParser)
report_fatal_error("Couldn't create MIR parser");
std::unique_ptr<Module> M = MParser->parseIRModule();
assert(M && "Couldn't parse module");
if (!M)
report_fatal_error("Couldn't parse module");
M->setTargetTriple(TM->getTargetTriple().getTriple());
M->setDataLayout(TM->createDataLayout());
MachineModuleInfo MMI(TM);
bool Res = MParser->parseMachineFunctions(*M, MMI);
(void)Res;
assert(!Res && "Couldn't parse MIR functions");
if (Res)
report_fatal_error("Couldn't parse MIR functions");
auto F = M->getFunction("sizes");
assert(F && "Couldn't find intended function");
if (!F)
report_fatal_error("Couldn't find intended function");
auto &MF = MMI.getOrCreateMachineFunction(*F);
Checks(*II, MF);