Index: include/llvm/FuzzMutate/OpDescriptor.h =================================================================== --- include/llvm/FuzzMutate/OpDescriptor.h +++ include/llvm/FuzzMutate/OpDescriptor.h @@ -164,6 +164,14 @@ static inline SourcePred anyAggregateType() { auto Pred = [](ArrayRef, const Value *V) { + // We can't index zero sized arrays. + if (isa(V->getType())) + return V->getType()->getArrayNumElements() > 0; + + // Structs can also be zero sized. I.e opaque types. + if (isa(V->getType())) + return V->getType()->getStructNumElements() > 0; + return V->getType()->isAggregateType(); }; // TODO: For now we only find aggregates in BaseTypes. It might be better to Index: unittests/FuzzMutate/OperationsTest.cpp =================================================================== --- unittests/FuzzMutate/OperationsTest.cpp +++ unittests/FuzzMutate/OperationsTest.cpp @@ -307,6 +307,7 @@ Type *StructTy = StructType::create(Ctx, {Int8PtrTy, Int32Ty}); Type *OpaqueTy = StructType::create(Ctx, "OpaqueStruct"); + Type *ZeroSizedArrayTy = ArrayType::get(Int64Ty, 0); Type *ArrayTy = ArrayType::get(Int64Ty, 4); Type *VectorTy = VectorType::get(Int32Ty, 2); @@ -317,17 +318,22 @@ Constant *SVal = UndefValue::get(StructTy); Constant *OVal = UndefValue::get(OpaqueTy); Constant *AVal = UndefValue::get(ArrayTy); + Constant *ZAVal = UndefValue::get(ZeroSizedArrayTy); Constant *VVal = UndefValue::get(VectorTy); EXPECT_TRUE(EVOp.SourcePreds[0].matches({}, SVal)); - EXPECT_TRUE(EVOp.SourcePreds[0].matches({}, OVal)); + EXPECT_FALSE(EVOp.SourcePreds[0].matches({}, OVal)); EXPECT_TRUE(EVOp.SourcePreds[0].matches({}, AVal)); EXPECT_FALSE(EVOp.SourcePreds[0].matches({}, VVal)); EXPECT_TRUE(IVOp.SourcePreds[0].matches({}, SVal)); - EXPECT_TRUE(IVOp.SourcePreds[0].matches({}, OVal)); + EXPECT_FALSE(IVOp.SourcePreds[0].matches({}, OVal)); EXPECT_TRUE(IVOp.SourcePreds[0].matches({}, AVal)); EXPECT_FALSE(IVOp.SourcePreds[0].matches({}, VVal)); + // Don't consider zero sized arrays as viable sources + EXPECT_FALSE(EVOp.SourcePreds[0].matches({}, ZAVal)); + EXPECT_FALSE(IVOp.SourcePreds[0].matches({}, ZAVal)); + // Make sure we're range checking appropriately. EXPECT_TRUE( EVOp.SourcePreds[1].matches({SVal}, ConstantInt::get(Int32Ty, 0)));