Skip to content

Commit 2d8a2a9

Browse files
committed
[llvm-reduce] Check if module data strings are empty before attempting to reduce
1 parent 266a8d5 commit 2d8a2a9

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,36 @@ using namespace llvm;
1717
static void clearModuleData(std::vector<Chunk> ChunksToKeep, Module *Program) {
1818
Oracle O(ChunksToKeep);
1919

20-
if (!O.shouldKeep())
20+
if (!Program->getModuleIdentifier().empty() && !O.shouldKeep())
2121
Program->setModuleIdentifier("");
22-
if (!O.shouldKeep())
22+
if (!Program->getSourceFileName().empty() && !O.shouldKeep())
2323
Program->setSourceFileName("");
24-
if (!O.shouldKeep())
24+
if (!Program->getDataLayoutStr().empty() && !O.shouldKeep())
2525
Program->setDataLayout("");
26-
if (!O.shouldKeep())
26+
if (!Program->getTargetTriple().empty() && !O.shouldKeep())
2727
Program->setTargetTriple("");
2828
// TODO: clear line by line rather than all at once
29-
if (!O.shouldKeep())
29+
if (!Program->getModuleInlineAsm().empty() && !O.shouldKeep())
3030
Program->setModuleInlineAsm("");
3131
}
3232

33+
static int countModuleData(Module *M) {
34+
int Count = 0;
35+
if (!M->getModuleIdentifier().empty())
36+
++Count;
37+
if (!M->getSourceFileName().empty())
38+
++Count;
39+
if (!M->getDataLayoutStr().empty())
40+
++Count;
41+
if (!M->getTargetTriple().empty())
42+
++Count;
43+
if (!M->getModuleInlineAsm().empty())
44+
++Count;
45+
return Count;
46+
}
47+
3348
void llvm::reduceModuleDataDeltaPass(TestRunner &Test) {
3449
outs() << "*** Reducing Module Data...\n";
35-
runDeltaPass(Test, 5, clearModuleData);
50+
int Count = countModuleData(Test.getProgram());
51+
runDeltaPass(Test, Count, clearModuleData);
3652
}

0 commit comments

Comments
 (0)