diff --git a/llvm/include/llvm/FuzzMutate/FuzzerCLI.h b/llvm/include/llvm/FuzzMutate/FuzzerCLI.h index db0168d3e6758..d6518107b24b6 100644 --- a/llvm/include/llvm/FuzzMutate/FuzzerCLI.h +++ b/llvm/include/llvm/FuzzMutate/FuzzerCLI.h @@ -48,8 +48,9 @@ using FuzzerInitFun = int (*)(int *argc, char ***argv); /// /// Useful for testing fuzz targets without linking to libFuzzer. Finds inputs /// in the argument list in a libFuzzer compatible way. -int runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne, - FuzzerInitFun Init = [](int *, char ***) { return 0; }); +int runFuzzerOnInputs( + int ArgC, char *ArgV[], FuzzerTestFun TestOne, + FuzzerInitFun Init = [](int *, char ***) { return 0; }); } // namespace llvm diff --git a/llvm/include/llvm/FuzzMutate/IRMutator.h b/llvm/include/llvm/FuzzMutate/IRMutator.h index ade76f1b5845d..72bf44179b6e2 100644 --- a/llvm/include/llvm/FuzzMutate/IRMutator.h +++ b/llvm/include/llvm/FuzzMutate/IRMutator.h @@ -95,6 +95,7 @@ class InjectorIRStrategy : public IRMutationStrategy { void mutate(BasicBlock &BB, RandomIRBuilder &IB) override; }; +/// Strategy that deletes instructions when the Module is too large. class InstDeleterIRStrategy : public IRMutationStrategy { public: uint64_t getWeight(size_t CurrentSize, size_t MaxSize, @@ -105,6 +106,7 @@ class InstDeleterIRStrategy : public IRMutationStrategy { void mutate(Instruction &Inst, RandomIRBuilder &IB) override; }; +/// Strategy that modifies instruction attributes and operands. class InstModificationIRStrategy : public IRMutationStrategy { public: uint64_t getWeight(size_t CurrentSize, size_t MaxSize, @@ -139,6 +141,6 @@ size_t writeModule(const Module &M, uint8_t *Dest, size_t MaxSize); std::unique_ptr parseAndVerify(const uint8_t *Data, size_t Size, LLVMContext &Context); -} // end llvm namespace +} // namespace llvm #endif // LLVM_FUZZMUTATE_IRMUTATOR_H diff --git a/llvm/include/llvm/FuzzMutate/OpDescriptor.h b/llvm/include/llvm/FuzzMutate/OpDescriptor.h index 847f975571bcf..11550bb7947fc 100644 --- a/llvm/include/llvm/FuzzMutate/OpDescriptor.h +++ b/llvm/include/llvm/FuzzMutate/OpDescriptor.h @@ -216,7 +216,7 @@ static inline SourcePred matchScalarOfFirstType() { return {Pred, Make}; } -} // end fuzzerop namespace -} // end llvm namespace +} // namespace fuzzerop +} // namespace llvm #endif // LLVM_FUZZMUTATE_OPDESCRIPTOR_H diff --git a/llvm/include/llvm/FuzzMutate/Operations.h b/llvm/include/llvm/FuzzMutate/Operations.h index 2eb4c38c2aeb4..d2a6180633ea2 100644 --- a/llvm/include/llvm/FuzzMutate/Operations.h +++ b/llvm/include/llvm/FuzzMutate/Operations.h @@ -46,8 +46,8 @@ OpDescriptor insertElementDescriptor(unsigned Weight); OpDescriptor shuffleVectorDescriptor(unsigned Weight); /// @} -} // end fuzzerop namespace +} // namespace fuzzerop -} // end llvm namespace +} // namespace llvm #endif // LLVM_FUZZMUTATE_OPERATIONS_H diff --git a/llvm/include/llvm/FuzzMutate/Random.h b/llvm/include/llvm/FuzzMutate/Random.h index 9d3af3accb151..6eba9ca9e8d3c 100644 --- a/llvm/include/llvm/FuzzMutate/Random.h +++ b/llvm/include/llvm/FuzzMutate/Random.h @@ -13,8 +13,8 @@ #ifndef LLVM_FUZZMUTATE_RANDOM_H #define LLVM_FUZZMUTATE_RANDOM_H -#include #include "llvm/Support/raw_ostream.h" +#include namespace llvm { /// Return a uniformly distributed random value between \c Min and \c Max @@ -46,7 +46,7 @@ template class ReservoirSampler { return Selection; } - explicit operator bool() const { return !isEmpty();} + explicit operator bool() const { return !isEmpty(); } const T &operator*() const { return getSelection(); } /// Sample each item in \c Items with unit weight @@ -91,6 +91,6 @@ ReservoirSampler makeSampler(GenT &RandGen) { return ReservoirSampler(RandGen); } -} // End llvm namespace +} // namespace llvm #endif // LLVM_FUZZMUTATE_RANDOM_H diff --git a/llvm/include/llvm/FuzzMutate/RandomIRBuilder.h b/llvm/include/llvm/FuzzMutate/RandomIRBuilder.h index aeb41baa8e077..61703be14771f 100644 --- a/llvm/include/llvm/FuzzMutate/RandomIRBuilder.h +++ b/llvm/include/llvm/FuzzMutate/RandomIRBuilder.h @@ -63,6 +63,6 @@ struct RandomIRBuilder { fuzzerop::SourcePred Pred); }; -} // end llvm namespace +} // namespace llvm #endif // LLVM_FUZZMUTATE_RANDOMIRBUILDER_H diff --git a/llvm/lib/FuzzMutate/IRMutator.cpp b/llvm/lib/FuzzMutate/IRMutator.cpp index b62a326a40cca..a879b09112623 100644 --- a/llvm/lib/FuzzMutate/IRMutator.cpp +++ b/llvm/lib/FuzzMutate/IRMutator.cpp @@ -162,8 +162,8 @@ void InstDeleterIRStrategy::mutate(Function &F, RandomIRBuilder &IB) { auto RS = makeSampler(IB.Rand); for (Instruction &Inst : instructions(F)) { // TODO: We can't handle these instructions. - if (Inst.isTerminator() || Inst.isEHPad() || - Inst.isSwiftError() || isa(Inst)) + if (Inst.isTerminator() || Inst.isEHPad() || Inst.isSwiftError() || + isa(Inst)) continue; RS.sample(&Inst, /*Weight=*/1); diff --git a/llvm/lib/FuzzMutate/Operations.cpp b/llvm/lib/FuzzMutate/Operations.cpp index 7443d49967c5c..0f618b3a097ad 100644 --- a/llvm/lib/FuzzMutate/Operations.cpp +++ b/llvm/lib/FuzzMutate/Operations.cpp @@ -298,7 +298,7 @@ OpDescriptor llvm::fuzzerop::insertElementDescriptor(unsigned Weight) { auto buildInsert = [](ArrayRef Srcs, Instruction *Inst) { return InsertElementInst::Create(Srcs[0], Srcs[1], Srcs[2], "I", Inst); }; - // TODO: Try to avoid undefined accesses. + // TODO: Try to avoid undefined accesses. return {Weight, {anyVectorType(), matchScalarOfFirstType(), anyIntType()}, buildInsert}; @@ -313,8 +313,8 @@ static SourcePred validShuffleVectorIndex() { 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{UndefValue::get( - VectorType::get(Int32Ty, FirstTy->getElementCount()))}; + return std::vector{ + UndefValue::get(VectorType::get(Int32Ty, FirstTy->getElementCount()))}; }; return {Pred, Make}; } diff --git a/llvm/unittests/FuzzMutate/OperationsTest.cpp b/llvm/unittests/FuzzMutate/OperationsTest.cpp index 4de3d43ba9602..91f4f492686da 100644 --- a/llvm/unittests/FuzzMutate/OperationsTest.cpp +++ b/llvm/unittests/FuzzMutate/OperationsTest.cpp @@ -44,18 +44,18 @@ using namespace llvm; using testing::AllOf; using testing::AnyOf; +using testing::Each; using testing::ElementsAre; using testing::Eq; using testing::Ge; -using testing::Each; -using testing::Truly; using testing::NotNull; using testing::PrintToString; using testing::SizeIs; +using testing::Truly; namespace { -std::unique_ptr parseAssembly( - const char *Assembly, LLVMContext &Context) { +std::unique_ptr parseAssembly(const char *Assembly, + LLVMContext &Context) { SMDiagnostic Error; std::unique_ptr M = parseAssemblyString(Assembly, Error, Context); @@ -88,8 +88,7 @@ TEST(OperationsTest, SourcePreds) { Constant *f16 = ConstantFP::getInfinity(Type::getHalfTy(Ctx)); Constant *f32 = ConstantFP::get(Type::getFloatTy(Ctx), 0.0); Constant *f64 = ConstantFP::get(Type::getDoubleTy(Ctx), 123.45); - Constant *s = - ConstantStruct::get(StructType::create(Ctx, "OpaqueStruct")); + Constant *s = ConstantStruct::get(StructType::create(Ctx, "OpaqueStruct")); Constant *a = ConstantArray::get(ArrayType::get(i32->getType(), 2), {i32, i32}); Constant *v8i8 = ConstantVector::getSplat(ElementCount::getFixed(8), i8); @@ -166,8 +165,7 @@ TEST(OperationsTest, SourcePreds) { EXPECT_FALSE(First.matches({v4f16, f64}, f64)); EXPECT_THAT(First.generate({i8}, {}), Each(TypesMatch(i8))); - EXPECT_THAT(First.generate({f16}, {i8->getType()}), - Each(TypesMatch(f16))); + EXPECT_THAT(First.generate({f16}, {i8->getType()}), Each(TypesMatch(f16))); EXPECT_THAT(First.generate({v8i8, i32}, {}), Each(TypesMatch(v8i8))); } @@ -235,7 +233,7 @@ TEST(OperationsTest, SplitEHBlock) { fuzzerop::OpDescriptor Descr = fuzzerop::splitBlockDescriptor(1); - Descr.BuilderFunc({ConstantInt::getTrue(Ctx)},&*BB.getFirstInsertionPt()); + Descr.BuilderFunc({ConstantInt::getTrue(Ctx)}, &*BB.getFirstInsertionPt()); ASSERT_TRUE(!verifyModule(*M, &errs())); } @@ -299,7 +297,6 @@ TEST(OperationsTest, GEP) { EXPECT_FALSE(verifyModule(M, &errs())); } - TEST(OperationsTest, GEPPointerOperand) { // Check that we only pick sized pointers for the GEP instructions @@ -401,4 +398,4 @@ TEST(OperationsTest, ExtractAndInsertValue) { ElementsAre(ConstantInt::get(Int32Ty, 1))); } -} +} // namespace diff --git a/llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp b/llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp index 1528be670fe85..95f01abf6576c 100644 --- a/llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp +++ b/llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp @@ -28,8 +28,8 @@ static constexpr int Seed = 5; namespace { -std::unique_ptr parseAssembly( - const char *Assembly, LLVMContext &Context) { +std::unique_ptr parseAssembly(const char *Assembly, + LLVMContext &Context) { SMDiagnostic Error; std::unique_ptr M = parseAssemblyString(Assembly, Error, Context); @@ -87,19 +87,18 @@ TEST(RandomIRBuilderTest, InsertValueIndexes) { // Check that we will generate correct indexes for the insertvalue operation LLVMContext Ctx; - const char *Source = - "%T = type {i8, i32, i64}\n" - "define void @test() {\n" - " %A = alloca %T\n" - " %L = load %T, %T* %A" - " ret void\n" - "}"; + const char *Source = "%T = type {i8, i32, i64}\n" + "define void @test() {\n" + " %A = alloca %T\n" + " %L = load %T, %T* %A" + " ret void\n" + "}"; auto M = parseAssembly(Source, Ctx); fuzzerop::OpDescriptor IVDescr = fuzzerop::insertValueDescriptor(1); - std::vector Types = - {Type::getInt8Ty(Ctx), Type::getInt32Ty(Ctx), Type::getInt64Ty(Ctx)}; + std::vector Types = {Type::getInt8Ty(Ctx), Type::getInt32Ty(Ctx), + Type::getInt64Ty(Ctx)}; RandomIRBuilder IB(Seed, Types); // Get first basic block of the first function @@ -115,15 +114,15 @@ TEST(RandomIRBuilderTest, InsertValueIndexes) { // Generate constants for each of the types and check that we pick correct // index for the given type - for (auto *T: Types) { + for (auto *T : Types) { // Loop to account for possible random decisions for (int i = 0; i < 10; ++i) { // Create value we want to insert. Only it's type matters. Srcs[1] = ConstantInt::get(T, 5); // Try to pick correct index - Value *Src = IB.findOrCreateSource( - BB, &*BB.begin(), Srcs, IVDescr.SourcePreds[2]); + Value *Src = + IB.findOrCreateSource(BB, &*BB.begin(), Srcs, IVDescr.SourcePreds[2]); ASSERT_TRUE(IVDescr.SourcePreds[2].matches(Srcs, Src)); } } @@ -167,18 +166,17 @@ TEST(RandomIRBuilderTest, InsertValueArray) { // Check that we can generate insertvalue for the vector operations LLVMContext Ctx; - const char *SourceCode = - "define void @test() {\n" - " %A = alloca [8 x i32]\n" - " %L = load [8 x i32], [8 x i32]* %A" - " ret void\n" - "}"; + const char *SourceCode = "define void @test() {\n" + " %A = alloca [8 x i32]\n" + " %L = load [8 x i32], [8 x i32]* %A" + " ret void\n" + "}"; auto M = parseAssembly(SourceCode, Ctx); fuzzerop::OpDescriptor Descr = fuzzerop::insertValueDescriptor(1); - std::vector Types = - {Type::getInt8Ty(Ctx), Type::getInt32Ty(Ctx), Type::getInt64Ty(Ctx)}; + std::vector Types = {Type::getInt8Ty(Ctx), Type::getInt32Ty(Ctx), + Type::getInt64Ty(Ctx)}; RandomIRBuilder IB(Seed, Types); // Get first basic block of the first function @@ -218,7 +216,6 @@ TEST(RandomIRBuilderTest, Invokes) { "}"; auto M = parseAssembly(SourceCode, Ctx); - std::vector Types = {Type::getInt8Ty(Ctx)}; RandomIRBuilder IB(Seed, Types); @@ -295,4 +292,4 @@ TEST(RandomIRBuilderTest, SwiftError) { } } -} +} // namespace diff --git a/llvm/unittests/FuzzMutate/ReservoirSamplerTest.cpp b/llvm/unittests/FuzzMutate/ReservoirSamplerTest.cpp index ac9270a265ec3..d3bf865870ff8 100644 --- a/llvm/unittests/FuzzMutate/ReservoirSamplerTest.cpp +++ b/llvm/unittests/FuzzMutate/ReservoirSamplerTest.cpp @@ -60,7 +60,7 @@ TEST(ReservoirSamplerTest, Uniform) { // v=9 | 2.088 | 3.325 | 5.899 | 8.343 | 11.39 | 16.92 | 21.67 | // // Check that we're in the likely range of results. - //if (V < 2.088 || V > 21.67) + // if (V < 2.088 || V > 21.67) if (V < 2.088 || V > 21.67) ++Failures; } diff --git a/llvm/unittests/FuzzMutate/StrategiesTest.cpp b/llvm/unittests/FuzzMutate/StrategiesTest.cpp index 562d08b9a1bd4..3f3f3c56c0386 100644 --- a/llvm/unittests/FuzzMutate/StrategiesTest.cpp +++ b/llvm/unittests/FuzzMutate/StrategiesTest.cpp @@ -31,9 +31,8 @@ std::unique_ptr createInjectorMutator() { Type::getInt64Ty, Type::getFloatTy, Type::getDoubleTy}; std::vector> Strategies; - Strategies.push_back( - std::make_unique( - InjectorIRStrategy::getDefaultOps())); + Strategies.push_back(std::make_unique( + InjectorIRStrategy::getDefaultOps())); return std::make_unique(std::move(Types), std::move(Strategies)); } @@ -60,8 +59,8 @@ std::unique_ptr createInstModifierMutator() { return std::make_unique(std::move(Types), std::move(Strategies)); } -std::unique_ptr parseAssembly( - const char *Assembly, LLVMContext &Context) { +std::unique_ptr parseAssembly(const char *Assembly, + LLVMContext &Context) { SMDiagnostic Error; std::unique_ptr M = parseAssemblyString(Assembly, Error, Context); @@ -104,15 +103,15 @@ TEST(InstDeleterIRStrategyTest, EmptyFunction) { // Test that we don't crash even if we can't remove from one of the functions. StringRef Source = "" - "define <8 x i32> @func1() {\n" - "ret <8 x i32> undef\n" - "}\n" - "\n" - "define i32 @func2() {\n" - "%A9 = alloca i32\n" - "%L6 = load i32, i32* %A9\n" - "ret i32 %L6\n" - "}\n"; + "define <8 x i32> @func1() {\n" + "ret <8 x i32> undef\n" + "}\n" + "\n" + "define i32 @func2() {\n" + "%A9 = alloca i32\n" + "%L6 = load i32, i32* %A9\n" + "ret i32 %L6\n" + "}\n"; auto Mutator = createDeleterMutator(); ASSERT_TRUE(Mutator); @@ -240,4 +239,4 @@ TEST(InstModificationIRStrategyTest, GEP) { EXPECT_TRUE(FoundInbounds); } -} +} // namespace