[PATCH] D41110: [FuzzMutate] Avoid zero sized aggregates

Igor Laevsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 12 04:34:11 PST 2017


igor-laevsky created this revision.
igor-laevsky added a reviewer: bogner.

`insertvalue/extractvalue` instructions expect aggregate index to be in bounds. There is no way we can generate valid index for the zero sized aggregate. This changes excludes them from the set of available sources.


Repository:
  rL LLVM

https://reviews.llvm.org/D41110

Files:
  include/llvm/FuzzMutate/OpDescriptor.h
  unittests/FuzzMutate/OperationsTest.cpp


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)));
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<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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41110.126528.patch
Type: text/x-patch
Size: 2396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171212/c2136996/attachment.bin>


More information about the llvm-commits mailing list