From 2d8a2a91b195420c48763217436698997147519d Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Tue, 24 Aug 2021 10:22:34 -0700 Subject: [PATCH] [llvm-reduce] Check if module data strings are empty before attempting to reduce --- .../llvm-reduce/deltas/ReduceModuleData.cpp | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp b/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp index 8aa3c5ff8860b..c51386938d6c9 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp @@ -17,20 +17,36 @@ using namespace llvm; static void clearModuleData(std::vector ChunksToKeep, Module *Program) { Oracle O(ChunksToKeep); - if (!O.shouldKeep()) + if (!Program->getModuleIdentifier().empty() && !O.shouldKeep()) Program->setModuleIdentifier(""); - if (!O.shouldKeep()) + if (!Program->getSourceFileName().empty() && !O.shouldKeep()) Program->setSourceFileName(""); - if (!O.shouldKeep()) + if (!Program->getDataLayoutStr().empty() && !O.shouldKeep()) Program->setDataLayout(""); - if (!O.shouldKeep()) + if (!Program->getTargetTriple().empty() && !O.shouldKeep()) Program->setTargetTriple(""); // TODO: clear line by line rather than all at once - if (!O.shouldKeep()) + if (!Program->getModuleInlineAsm().empty() && !O.shouldKeep()) Program->setModuleInlineAsm(""); } +static int countModuleData(Module *M) { + int Count = 0; + if (!M->getModuleIdentifier().empty()) + ++Count; + if (!M->getSourceFileName().empty()) + ++Count; + if (!M->getDataLayoutStr().empty()) + ++Count; + if (!M->getTargetTriple().empty()) + ++Count; + if (!M->getModuleInlineAsm().empty()) + ++Count; + return Count; +} + void llvm::reduceModuleDataDeltaPass(TestRunner &Test) { outs() << "*** Reducing Module Data...\n"; - runDeltaPass(Test, 5, clearModuleData); + int Count = countModuleData(Test.getProgram()); + runDeltaPass(Test, Count, clearModuleData); }