forked from OSchip/llvm-project
[FuzzMutate] Avoid zero sized aggregates
Differential Revision: https://reviews.llvm.org/D41110 llvm-svn: 320572
This commit is contained in:
parent
541f9707a5
commit
f39a29265c
|
@ -160,6 +160,14 @@ static inline SourcePred sizedPtrType() {
|
|||
|
||||
static inline SourcePred anyAggregateType() {
|
||||
auto Pred = [](ArrayRef<Value *>, const Value *V) {
|
||||
// We can't index zero sized arrays.
|
||||
if (isa<ArrayType>(V->getType()))
|
||||
return V->getType()->getArrayNumElements() > 0;
|
||||
|
||||
// Structs can also be zero sized. I.e opaque types.
|
||||
if (isa<StructType>(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
|
||||
|
|
|
@ -336,6 +336,7 @@ TEST(OperationsTest, ExtractAndInsertValue) {
|
|||
|
||||
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);
|
||||
|
||||
|
@ -346,17 +347,22 @@ TEST(OperationsTest, ExtractAndInsertValue) {
|
|||
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)));
|
||||
|
|
Loading…
Reference in New Issue