aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/FuzzMutate/Operations.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/FuzzMutate/Operations.cpp')
-rw-r--r--llvm/lib/FuzzMutate/Operations.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/llvm/lib/FuzzMutate/Operations.cpp b/llvm/lib/FuzzMutate/Operations.cpp
index 221a3a84b49b..7443d49967c5 100644
--- a/llvm/lib/FuzzMutate/Operations.cpp
+++ b/llvm/lib/FuzzMutate/Operations.cpp
@@ -169,14 +169,21 @@ OpDescriptor llvm::fuzzerop::splitBlockDescriptor(unsigned Weight) {
OpDescriptor llvm::fuzzerop::gepDescriptor(unsigned Weight) {
auto buildGEP = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
- Type *Ty = Srcs[0]->getType()->getPointerElementType();
- auto Indices = makeArrayRef(Srcs).drop_front(1);
+ // TODO: It would be better to generate a random type here, rather than
+ // generating a random value and picking its type.
+ Type *Ty = Srcs[0]->getType()->isOpaquePointerTy()
+ ? Srcs[1]->getType()
+ : Srcs[0]->getType()->getNonOpaquePointerElementType();
+ auto Indices = makeArrayRef(Srcs).drop_front(2);
return GetElementPtrInst::Create(Ty, Srcs[0], Indices, "G", Inst);
};
// TODO: Handle aggregates and vectors
// TODO: Support multiple indices.
// TODO: Try to avoid meaningless accesses.
- return {Weight, {sizedPtrType(), anyIntType()}, buildGEP};
+ SourcePred sizedType(
+ [](ArrayRef<Value *>, const Value *V) { return V->getType()->isSized(); },
+ None);
+ return {Weight, {sizedPtrType(), sizedType, anyIntType()}, buildGEP};
}
static uint64_t getAggregateNumElements(Type *T) {
@@ -302,12 +309,12 @@ static SourcePred validShuffleVectorIndex() {
return ShuffleVectorInst::isValidOperands(Cur[0], Cur[1], V);
};
auto Make = [](ArrayRef<Value *> Cur, ArrayRef<Type *> Ts) {
- auto *FirstTy = cast<FixedVectorType>(Cur[0]->getType());
+ auto *FirstTy = cast<VectorType>(Cur[0]->getType());
auto *Int32Ty = Type::getInt32Ty(Cur[0]->getContext());
// TODO: It's straighforward to make up reasonable values, but listing them
// exhaustively would be insane. Come up with a couple of sensible ones.
return std::vector<Constant *>{UndefValue::get(
- FixedVectorType::get(Int32Ty, FirstTy->getNumElements()))};
+ VectorType::get(Int32Ty, FirstTy->getElementCount()))};
};
return {Pred, Make};
}