[llvm] 7cbb6e9 - [llvm-reduce] Assert that the number of chunks does not change with reductions
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 1 15:40:40 PST 2021
Author: Arthur Eubanks
Date: 2021-12-01T15:40:05-08:00
New Revision: 7cbb6e9a8f6ff3dff4b0353dfcbbdabab8865228
URL: https://github.com/llvm/llvm-project/commit/7cbb6e9a8f6ff3dff4b0353dfcbbdabab8865228
DIFF: https://github.com/llvm/llvm-project/commit/7cbb6e9a8f6ff3dff4b0353dfcbbdabab8865228.diff
LOG: [llvm-reduce] Assert that the number of chunks does not change with reductions
Followup to D113537.
Reviewed By: Meinersbur
Differential Revision: https://reviews.llvm.org/D113816
Added:
Modified:
llvm/tools/llvm-reduce/deltas/Delta.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp
index 8666d8baac66d..1bab82f823c02 100644
--- a/llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -211,35 +211,52 @@ SmallString<0> ProcessChunkFromSerializedBitcode(
/// Runs the Delta Debugging algorithm, splits the code into chunks and
/// reduces the amount of chunks that are considered interesting by the
-/// given test.
+/// given test. The number of chunks is determined by a preliminary run of the
+/// reduction pass where no change must be made to the module.
template <typename T>
void runDeltaPassInt(
TestRunner &Test,
function_ref<void(Oracle &, T &)> ExtractChunksFromModule) {
+ assert(!verifyReducerWorkItem(Test.getProgram(), &errs()) &&
+ "input module is broken before making changes");
+
+ SmallString<128> CurrentFilepath;
+ if (!isReduced(Test.getProgram(), Test, CurrentFilepath)) {
+ errs() << "\nInput isn't interesting! Verify interesting-ness test\n";
+ exit(1);
+ }
+
int Targets;
{
- // Count the number of targets by counting the number of calls to
+ // Count the number of chunks by counting the number of calls to
// Oracle::shouldKeep() but always returning true so no changes are
// made.
std::vector<Chunk> AllChunks = {{0, INT_MAX}};
Oracle Counter(AllChunks);
ExtractChunksFromModule(Counter, Test.getProgram());
Targets = Counter.count();
+
+ assert(!verifyReducerWorkItem(Test.getProgram(), &errs()) &&
+ "input module is broken after counting chunks");
+ assert(isReduced(Test.getProgram(), Test, CurrentFilepath) &&
+ "input module no longer interesting after counting chunks");
+
+#ifndef NDEBUG
+ // Make sure that the number of chunks does not change as we reduce.
+ std::vector<Chunk> NoChunks;
+ Oracle NoChunksCounter(NoChunks);
+ std::unique_ptr<ReducerWorkItem> Clone =
+ cloneReducerWorkItem(Test.getProgram());
+ ExtractChunksFromModule(NoChunksCounter, *Clone);
+ assert(Targets == NoChunksCounter.count() &&
+ "number of chunks changes when reducing");
+#endif
}
if (!Targets) {
errs() << "\nNothing to reduce\n";
return;
}
- SmallString<128> CurrentFilepath;
- if (!isReduced(Test.getProgram(), Test, CurrentFilepath)) {
- errs() << "\nInput isn't interesting! Verify interesting-ness test\n";
- exit(1);
- }
-
- assert(!verifyReducerWorkItem(Test.getProgram(), &errs()) &&
- "input module is broken before making changes");
-
std::vector<Chunk> ChunksStillConsideredInteresting = {{0, Targets - 1}};
std::unique_ptr<ReducerWorkItem> ReducedProgram;
More information about the llvm-commits
mailing list