[llvm] r320572 - [FuzzMutate] Avoid zero sized aggregates
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 13 03:47:35 PST 2017
Author: igor.laevsky
Date: Wed Dec 13 03:47:35 2017
New Revision: 320572
URL: http://llvm.org/viewvc/llvm-project?rev=320572&view=rev
Log:
[FuzzMutate] Avoid zero sized aggregates
Differential Revision: https://reviews.llvm.org/D41110
Modified:
llvm/trunk/include/llvm/FuzzMutate/OpDescriptor.h
llvm/trunk/unittests/FuzzMutate/OperationsTest.cpp
Modified: llvm/trunk/include/llvm/FuzzMutate/OpDescriptor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/FuzzMutate/OpDescriptor.h?rev=320572&r1=320571&r2=320572&view=diff
==============================================================================
--- llvm/trunk/include/llvm/FuzzMutate/OpDescriptor.h (original)
+++ llvm/trunk/include/llvm/FuzzMutate/OpDescriptor.h Wed Dec 13 03:47:35 2017
@@ -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
Modified: llvm/trunk/unittests/FuzzMutate/OperationsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/FuzzMutate/OperationsTest.cpp?rev=320572&r1=320571&r2=320572&view=diff
==============================================================================
--- llvm/trunk/unittests/FuzzMutate/OperationsTest.cpp (original)
+++ llvm/trunk/unittests/FuzzMutate/OperationsTest.cpp Wed Dec 13 03:47:35 2017
@@ -336,6 +336,7 @@ TEST(OperationsTest, ExtractAndInsertVal
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, ExtractAndInsertVal
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)));
More information about the llvm-commits
mailing list