[IRMutator] Handle module with only declarations
authorNikita Popov <npopov@redhat.com>
Fri, 11 Mar 2022 13:14:16 +0000 (14:14 +0100)
committerNikita Popov <npopov@redhat.com>
Fri, 11 Mar 2022 13:20:39 +0000 (14:20 +0100)
There was a mismatch here, with one check checking whether there
are any functions, and the other collecting only non-declaration
functions.

llvm/lib/FuzzMutate/IRMutator.cpp

index 0cd0f53..8078b36 100644 (file)
@@ -33,14 +33,15 @@ static void createEmptyFunction(Module &M) {
 }
 
 void IRMutationStrategy::mutate(Module &M, RandomIRBuilder &IB) {
-  if (M.empty())
-    createEmptyFunction(M);
-
   auto RS = makeSampler<Function *>(IB.Rand);
   for (Function &F : M)
     if (!F.isDeclaration())
       RS.sample(&F, /*Weight=*/1);
-  mutate(*RS.getSelection(), IB);
+
+  if (RS.isEmpty())
+    createEmptyFunction(M);
+  else
+    mutate(*RS.getSelection(), IB);
 }
 
 void IRMutationStrategy::mutate(Function &F, RandomIRBuilder &IB) {