[llvm] [FuzzMutate] Only use undef when explictly asked to (PR #84959)

Peter Rong via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 10:38:14 PDT 2024


https://github.com/DataCorrupted created https://github.com/llvm/llvm-project/pull/84959

Per discussion in https://github.com/SecurityLab-UCD/IRFuzzer/issues/49, generating undef during fuzzing seems to be left fruitful. Let's eliminate undef in favor of poison unless the user explictly asked for it.

>From 0fe6c2a647abbcfc494e19a3da0fcfe6e1089eea Mon Sep 17 00:00:00 2001
From: Peter Rong <PeterRong96 at gmail.com>
Date: Tue, 12 Mar 2024 17:32:47 +0000
Subject: [PATCH] [FuzzMutate] Only use undef when explictly asked to

Per discussion in https://github.com/SecurityLab-UCD/IRFuzzer/issues/49, generating undef during
fuzzing seems to be left fruitful. Let's eliminate undef in favor of poison unless the user
explictly asked for it.

Signed-off-by: Peter Rong <PeterRong96 at gmail.com>
---
 llvm/lib/FuzzMutate/OpDescriptor.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/FuzzMutate/OpDescriptor.cpp b/llvm/lib/FuzzMutate/OpDescriptor.cpp
index 4baf45284de105..6ec70d917918f3 100644
--- a/llvm/lib/FuzzMutate/OpDescriptor.cpp
+++ b/llvm/lib/FuzzMutate/OpDescriptor.cpp
@@ -8,10 +8,15 @@
 
 #include "llvm/FuzzMutate/OpDescriptor.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/Support/CommandLine.h"
 
 using namespace llvm;
 using namespace fuzzerop;
 
+static cl::opt<bool> UseUndef("use-undef",
+                              cl::desc("Use undef when generating programs."),
+                              cl::init(false));
+
 void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {
   if (auto *IntTy = dyn_cast<IntegerType>(T)) {
     uint64_t W = IntTy->getBitWidth();
@@ -42,7 +47,8 @@ void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {
       Cs.push_back(ConstantVector::getSplat(EC, Elt));
     }
   } else {
-    Cs.push_back(UndefValue::get(T));
+    if (UseUndef)
+      Cs.push_back(UndefValue::get(T));
     Cs.push_back(PoisonValue::get(T));
   }
 }



More information about the llvm-commits mailing list