summaryrefslogtreecommitdiffstats
path: root/llvm/lib/FuzzMutate/OpDescriptor.cpp
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2017-08-21 17:44:36 +0000
committerJustin Bogner <mail@justinbogner.com>2017-08-21 17:44:36 +0000
commit02336370858e69cee50019f6bcea89de041c7df3 (patch)
treef78de55d532e82bf4fe7c8d351e4029d0ee91904 /llvm/lib/FuzzMutate/OpDescriptor.cpp
parentd5ac1812b7fa2f748b900de09b9160cf8a5c5a12 (diff)
downloadbcm5719-llvm-02336370858e69cee50019f6bcea89de041c7df3.tar.gz
bcm5719-llvm-02336370858e69cee50019f6bcea89de041c7df3.zip
Introduce FuzzMutate library
This introduces the FuzzMutate library, which provides structured fuzzing for LLVM IR, as described in my [EuroLLVM 2017 talk][1]. Most of the basic mutators to inject and delete IR are provided, with support for most basic operations. I will follow up with the instruction selection fuzzer, which is implemented in terms of this library. [1]: http://llvm.org/devmtg/2017-03//2017/02/20/accepted-sessions.html#2 llvm-svn: 311356
Diffstat (limited to 'llvm/lib/FuzzMutate/OpDescriptor.cpp')
-rw-r--r--llvm/lib/FuzzMutate/OpDescriptor.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/llvm/lib/FuzzMutate/OpDescriptor.cpp b/llvm/lib/FuzzMutate/OpDescriptor.cpp
new file mode 100644
index 00000000000..1c5d8f606ae
--- /dev/null
+++ b/llvm/lib/FuzzMutate/OpDescriptor.cpp
@@ -0,0 +1,38 @@
+//===-- OpDescriptor.cpp --------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/FuzzMutate/OpDescriptor.h"
+#include "llvm/IR/Constants.h"
+
+using namespace llvm;
+using namespace fuzzerop;
+
+void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {
+ if (auto *IntTy = dyn_cast<IntegerType>(T)) {
+ uint64_t W = IntTy->getBitWidth();
+ Cs.push_back(ConstantInt::get(IntTy, APInt::getMaxValue(W)));
+ Cs.push_back(ConstantInt::get(IntTy, APInt::getMinValue(W)));
+ Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMaxValue(W)));
+ Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMinValue(W)));
+ Cs.push_back(ConstantInt::get(IntTy, APInt::getOneBitSet(W, W / 2)));
+ } else if (T->isFloatingPointTy()) {
+ auto &Ctx = T->getContext();
+ auto &Sem = T->getFltSemantics();
+ Cs.push_back(ConstantFP::get(Ctx, APFloat::getZero(Sem)));
+ Cs.push_back(ConstantFP::get(Ctx, APFloat::getLargest(Sem)));
+ Cs.push_back(ConstantFP::get(Ctx, APFloat::getSmallest(Sem)));
+ } else
+ Cs.push_back(UndefValue::get(T));
+}
+
+std::vector<Constant *> fuzzerop::makeConstantsWithType(Type *T) {
+ std::vector<Constant *> Result;
+ makeConstantsWithType(T, Result);
+ return Result;
+}
OpenPOWER on IntegriCloud