[PATCH] D113816: [llvm-reduce] Assert that the number of chunks does not change with reductions

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 12 16:10:23 PST 2021


aeubanks updated this revision to Diff 386977.
aeubanks added a comment.

remove logging


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113816/new/

https://reviews.llvm.org/D113816

Files:
  llvm/tools/llvm-reduce/deltas/Delta.cpp


Index: llvm/tools/llvm-reduce/deltas/Delta.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -99,35 +99,52 @@
 
 /// 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;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113816.386977.patch
Type: text/x-patch
Size: 2647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211113/8952681f/attachment.bin>


More information about the llvm-commits mailing list