[llvm] r321062 - [FuzzMutate] Don't crash when mutator is unable to find operation
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 19 00:52:51 PST 2017
Author: igor.laevsky
Date: Tue Dec 19 00:52:51 2017
New Revision: 321062
URL: http://llvm.org/viewvc/llvm-project?rev=321062&view=rev
Log:
[FuzzMutate] Don't crash when mutator is unable to find operation
Differential Revision: https://reviews.llvm.org/D41009
Modified:
llvm/trunk/include/llvm/FuzzMutate/IRMutator.h
llvm/trunk/lib/FuzzMutate/IRMutator.cpp
Modified: llvm/trunk/include/llvm/FuzzMutate/IRMutator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/FuzzMutate/IRMutator.h?rev=321062&r1=321061&r2=321062&view=diff
==============================================================================
--- llvm/trunk/include/llvm/FuzzMutate/IRMutator.h (original)
+++ llvm/trunk/include/llvm/FuzzMutate/IRMutator.h Tue Dec 19 00:52:51 2017
@@ -16,6 +16,7 @@
#ifndef LLVM_FUZZMUTATE_IRMUTATOR_H
#define LLVM_FUZZMUTATE_IRMUTATOR_H
+#include "llvm/ADT/Optional.h"
#include "llvm/FuzzMutate/OpDescriptor.h"
#include "llvm/Support/ErrorHandling.h"
@@ -74,7 +75,8 @@ public:
class InjectorIRStrategy : public IRMutationStrategy {
std::vector<fuzzerop::OpDescriptor> Operations;
- fuzzerop::OpDescriptor chooseOperation(Value *Src, RandomIRBuilder &IB);
+ Optional<fuzzerop::OpDescriptor> chooseOperation(Value *Src,
+ RandomIRBuilder &IB);
public:
InjectorIRStrategy(std::vector<fuzzerop::OpDescriptor> &&Operations)
Modified: llvm/trunk/lib/FuzzMutate/IRMutator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/FuzzMutate/IRMutator.cpp?rev=321062&r1=321061&r2=321062&view=diff
==============================================================================
--- llvm/trunk/lib/FuzzMutate/IRMutator.cpp (original)
+++ llvm/trunk/lib/FuzzMutate/IRMutator.cpp Tue Dec 19 00:52:51 2017
@@ -8,15 +8,17 @@
//===----------------------------------------------------------------------===//
#include "llvm/FuzzMutate/IRMutator.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/FuzzMutate/Operations.h"
#include "llvm/FuzzMutate/Random.h"
#include "llvm/FuzzMutate/RandomIRBuilder.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Function.h"
-#include "llvm/IR/Instructions.h"
#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Scalar/DCE.h"
using namespace llvm;
@@ -90,14 +92,14 @@ std::vector<fuzzerop::OpDescriptor> Inje
return Ops;
}
-fuzzerop::OpDescriptor
+Optional<fuzzerop::OpDescriptor>
InjectorIRStrategy::chooseOperation(Value *Src, RandomIRBuilder &IB) {
auto OpMatchesPred = [&Src](fuzzerop::OpDescriptor &Op) {
return Op.SourcePreds[0].matches({}, Src);
};
auto RS = makeSampler(IB.Rand, make_filter_range(Operations, OpMatchesPred));
if (RS.isEmpty())
- report_fatal_error("No available operations for src type");
+ return None;
return *RS;
}
@@ -120,10 +122,15 @@ void InjectorIRStrategy::mutate(BasicBlo
// Choose an operation that's constrained to be valid for the type of the
// source, collect any other sources it needs, and then build it.
- fuzzerop::OpDescriptor OpDesc = chooseOperation(Srcs[0], IB);
- for (const auto &Pred : makeArrayRef(OpDesc.SourcePreds).slice(1))
+ auto OpDesc = chooseOperation(Srcs[0], IB);
+ // Bail if no operation was found
+ if (!OpDesc)
+ return;
+
+ for (const auto &Pred : makeArrayRef(OpDesc->SourcePreds).slice(1))
Srcs.push_back(IB.findOrCreateSource(BB, InstsBefore, Srcs, Pred));
- if (Value *Op = OpDesc.BuilderFunc(Srcs, Insts[IP])) {
+
+ if (Value *Op = OpDesc->BuilderFunc(Srcs, Insts[IP])) {
// Find a sink and wire up the results of the operation.
IB.connectToSink(BB, InstsAfter, Op);
}
More information about the llvm-commits
mailing list