From 5c0660f0168c63a5482438367b08fca1ee655c44 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Tue, 6 Jun 2017 19:00:54 +0000 Subject: [PATCH] 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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304814 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/MI/LiveIntervalTest.cpp | 3 ++- unittests/Target/AArch64/InstSizes.cpp | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/unittests/MI/LiveIntervalTest.cpp b/unittests/MI/LiveIntervalTest.cpp index 0b9510ec43b..7118a43e6d8 100644 --- a/unittests/MI/LiveIntervalTest.cpp +++ b/unittests/MI/LiveIntervalTest.cpp @@ -151,7 +151,8 @@ body: | std::unique_ptr MIR; std::unique_ptr 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)); diff --git a/unittests/Target/AArch64/InstSizes.cpp b/unittests/Target/AArch64/InstSizes.cpp index a4bcd6821ec..c1fe7f22dc5 100644 --- a/unittests/Target/AArch64/InstSizes.cpp +++ b/unittests/Target/AArch64/InstSizes.cpp @@ -21,7 +21,8 @@ std::unique_ptr 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( TheTarget->createTargetMachine(TT, CPU, FS, TargetOptions(), None, @@ -58,21 +59,24 @@ void runChecks( std::unique_ptr MBuffer = MemoryBuffer::getMemBuffer(MIRString); std::unique_ptr 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 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); -- 2.50.1