From 750e7046bb8f408240cdc009b33d91bfc17ee04c Mon Sep 17 00:00:00 2001 From: Marcos Pividori Date: Tue, 13 Dec 2016 17:46:11 +0000 Subject: [PATCH] [libFuzzer] Clean up headers and file formatting of LibFuzzer files. Reorganize #includes to follow LLVM Coding Standards. Include some missing headers. Required to use `Printf()`. Aside from that, this patch contains no functional change. It is purely a re-organization. Differential Revision: https://reviews.llvm.org/D27363 llvm-svn: 289560 --- lib/Fuzzer/FuzzerCorpus.h | 6 +++--- lib/Fuzzer/FuzzerCrossOver.cpp | 3 +-- lib/Fuzzer/FuzzerDefs.h | 2 ++ lib/Fuzzer/FuzzerDictionary.h | 1 - lib/Fuzzer/FuzzerDriver.cpp | 1 - lib/Fuzzer/FuzzerExtFunctions.h | 2 ++ lib/Fuzzer/FuzzerExtFunctionsDlsym.cpp | 2 ++ lib/Fuzzer/FuzzerExtFunctionsWeak.cpp | 2 ++ lib/Fuzzer/FuzzerExtFunctionsWeakAlias.cpp | 2 ++ lib/Fuzzer/FuzzerFnAdapter.h | 3 +-- lib/Fuzzer/FuzzerIO.cpp | 3 ++- lib/Fuzzer/FuzzerIO.h | 2 ++ lib/Fuzzer/FuzzerIOPosix.cpp | 3 ++- lib/Fuzzer/FuzzerIOWindows.cpp | 5 +++-- lib/Fuzzer/FuzzerInternal.h | 13 ++++++------- lib/Fuzzer/FuzzerLoop.cpp | 1 - lib/Fuzzer/FuzzerSHA1.h | 2 ++ lib/Fuzzer/FuzzerTracePC.h | 3 +-- lib/Fuzzer/FuzzerUtil.h | 2 ++ lib/Fuzzer/FuzzerUtilDarwin.cpp | 5 ++++- lib/Fuzzer/FuzzerUtilLinux.cpp | 7 ++++++- lib/Fuzzer/FuzzerUtilPosix.cpp | 4 ++-- lib/Fuzzer/FuzzerUtilWindows.cpp | 2 +- 23 files changed, 48 insertions(+), 28 deletions(-) diff --git a/lib/Fuzzer/FuzzerCorpus.h b/lib/Fuzzer/FuzzerCorpus.h index bbe192f53f8..88e83b320c4 100644 --- a/lib/Fuzzer/FuzzerCorpus.h +++ b/lib/Fuzzer/FuzzerCorpus.h @@ -12,14 +12,14 @@ #ifndef LLVM_FUZZER_CORPUS #define LLVM_FUZZER_CORPUS -#include -#include - #include "FuzzerDefs.h" #include "FuzzerIO.h" #include "FuzzerRandom.h" #include "FuzzerSHA1.h" #include "FuzzerTracePC.h" +#include +#include +#include namespace fuzzer { diff --git a/lib/Fuzzer/FuzzerCrossOver.cpp b/lib/Fuzzer/FuzzerCrossOver.cpp index e86e23f81f0..8b0fd7d529a 100644 --- a/lib/Fuzzer/FuzzerCrossOver.cpp +++ b/lib/Fuzzer/FuzzerCrossOver.cpp @@ -9,11 +9,10 @@ // Cross over test inputs. //===----------------------------------------------------------------------===// -#include - #include "FuzzerDefs.h" #include "FuzzerMutate.h" #include "FuzzerRandom.h" +#include namespace fuzzer { diff --git a/lib/Fuzzer/FuzzerDefs.h b/lib/Fuzzer/FuzzerDefs.h index 89d675ac1a4..a699045842b 100644 --- a/lib/Fuzzer/FuzzerDefs.h +++ b/lib/Fuzzer/FuzzerDefs.h @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// // Basic definitions. //===----------------------------------------------------------------------===// + #ifndef LLVM_FUZZER_DEFS_H #define LLVM_FUZZER_DEFS_H @@ -77,4 +78,5 @@ inline uint32_t Bswap(uint32_t x) { return __builtin_bswap32(x); } inline uint64_t Bswap(uint64_t x) { return __builtin_bswap64(x); } } // namespace fuzzer + #endif // LLVM_FUZZER_DEFS_H diff --git a/lib/Fuzzer/FuzzerDictionary.h b/lib/Fuzzer/FuzzerDictionary.h index b23b4b022e3..eba0eabb683 100644 --- a/lib/Fuzzer/FuzzerDictionary.h +++ b/lib/Fuzzer/FuzzerDictionary.h @@ -122,4 +122,3 @@ bool ParseDictionaryFile(const std::string &Text, std::vector *Units); } // namespace fuzzer #endif // LLVM_FUZZER_DICTIONARY_H - diff --git a/lib/Fuzzer/FuzzerDriver.cpp b/lib/Fuzzer/FuzzerDriver.cpp index f4f1a4d47d1..fb86cbc1efa 100644 --- a/lib/Fuzzer/FuzzerDriver.cpp +++ b/lib/Fuzzer/FuzzerDriver.cpp @@ -15,7 +15,6 @@ #include "FuzzerIO.h" #include "FuzzerMutate.h" #include "FuzzerRandom.h" - #include #include #include diff --git a/lib/Fuzzer/FuzzerExtFunctions.h b/lib/Fuzzer/FuzzerExtFunctions.h index 2ec86cb9231..2672a385478 100644 --- a/lib/Fuzzer/FuzzerExtFunctions.h +++ b/lib/Fuzzer/FuzzerExtFunctions.h @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// // Defines an interface to (possibly optional) functions. //===----------------------------------------------------------------------===// + #ifndef LLVM_FUZZER_EXT_FUNCTIONS_H #define LLVM_FUZZER_EXT_FUNCTIONS_H @@ -30,4 +31,5 @@ struct ExternalFunctions { #undef EXT_FUNC }; } // namespace fuzzer + #endif diff --git a/lib/Fuzzer/FuzzerExtFunctionsDlsym.cpp b/lib/Fuzzer/FuzzerExtFunctionsDlsym.cpp index 65b0458dcee..06bddd5de38 100644 --- a/lib/Fuzzer/FuzzerExtFunctionsDlsym.cpp +++ b/lib/Fuzzer/FuzzerExtFunctionsDlsym.cpp @@ -46,5 +46,7 @@ ExternalFunctions::ExternalFunctions() { #undef EXT_FUNC } + } // namespace fuzzer + #endif // LIBFUZZER_APPLE diff --git a/lib/Fuzzer/FuzzerExtFunctionsWeak.cpp b/lib/Fuzzer/FuzzerExtFunctionsWeak.cpp index cb3b31105d5..7b02b6f0b70 100644 --- a/lib/Fuzzer/FuzzerExtFunctionsWeak.cpp +++ b/lib/Fuzzer/FuzzerExtFunctionsWeak.cpp @@ -47,5 +47,7 @@ ExternalFunctions::ExternalFunctions() { #undef EXT_FUNC } + } // namespace fuzzer + #endif // LIBFUZZER_LINUX diff --git a/lib/Fuzzer/FuzzerExtFunctionsWeakAlias.cpp b/lib/Fuzzer/FuzzerExtFunctionsWeakAlias.cpp index 3c42e539fcc..e10f7b4dcac 100644 --- a/lib/Fuzzer/FuzzerExtFunctionsWeakAlias.cpp +++ b/lib/Fuzzer/FuzzerExtFunctionsWeakAlias.cpp @@ -50,5 +50,7 @@ ExternalFunctions::ExternalFunctions() { #undef EXT_FUNC } + } // namespace fuzzer + #endif // LIBFUZZER_WINDOWS diff --git a/lib/Fuzzer/FuzzerFnAdapter.h b/lib/Fuzzer/FuzzerFnAdapter.h index eb2c219b870..e53b628ed21 100644 --- a/lib/Fuzzer/FuzzerFnAdapter.h +++ b/lib/Fuzzer/FuzzerFnAdapter.h @@ -15,10 +15,9 @@ #ifndef LLVM_FUZZER_ADAPTER_H #define LLVM_FUZZER_ADAPTER_H +#include #include #include - -#include #include #include #include diff --git a/lib/Fuzzer/FuzzerIO.cpp b/lib/Fuzzer/FuzzerIO.cpp index 5d4d415d49e..eda8e877293 100644 --- a/lib/Fuzzer/FuzzerIO.cpp +++ b/lib/Fuzzer/FuzzerIO.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// // IO functions. //===----------------------------------------------------------------------===// + #include "FuzzerIO.h" #include "FuzzerDefs.h" #include "FuzzerExtFunctions.h" @@ -15,8 +16,8 @@ #include #include #include -#include #include +#include namespace fuzzer { diff --git a/lib/Fuzzer/FuzzerIO.h b/lib/Fuzzer/FuzzerIO.h index 39634f93fec..f5651cfe9ed 100644 --- a/lib/Fuzzer/FuzzerIO.h +++ b/lib/Fuzzer/FuzzerIO.h @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// // IO interface. //===----------------------------------------------------------------------===// + #ifndef LLVM_FUZZER_IO_H #define LLVM_FUZZER_IO_H @@ -59,4 +60,5 @@ int DuplicateFile(int Fd); void DeleteFile(const std::string &Path); } // namespace fuzzer + #endif // LLVM_FUZZER_IO_H diff --git a/lib/Fuzzer/FuzzerIOPosix.cpp b/lib/Fuzzer/FuzzerIOPosix.cpp index a4290face97..53a58f96287 100644 --- a/lib/Fuzzer/FuzzerIOPosix.cpp +++ b/lib/Fuzzer/FuzzerIOPosix.cpp @@ -8,9 +8,9 @@ //===----------------------------------------------------------------------===// // IO functions implementation using Posix API. //===----------------------------------------------------------------------===// - #include "FuzzerDefs.h" #if LIBFUZZER_POSIX + #include "FuzzerExtFunctions.h" #include "FuzzerIO.h" #include @@ -84,4 +84,5 @@ std::string DirName(const std::string &FileName) { } } // namespace fuzzer + #endif // LIBFUZZER_POSIX diff --git a/lib/Fuzzer/FuzzerIOWindows.cpp b/lib/Fuzzer/FuzzerIOWindows.cpp index aaa2e34fb35..df530cdfbbc 100644 --- a/lib/Fuzzer/FuzzerIOWindows.cpp +++ b/lib/Fuzzer/FuzzerIOWindows.cpp @@ -8,9 +8,9 @@ //===----------------------------------------------------------------------===// // IO functions implementation for Windows. //===----------------------------------------------------------------------===// - #include "FuzzerDefs.h" #if LIBFUZZER_WINDOWS + #include "FuzzerExtFunctions.h" #include "FuzzerIO.h" #include @@ -18,8 +18,8 @@ #include #include #include -#include #include +#include #include namespace fuzzer { @@ -144,4 +144,5 @@ std::string DirName(const std::string &FileName) { } } // namespace fuzzer + #endif // LIBFUZZER_WINDOWS diff --git a/lib/Fuzzer/FuzzerInternal.h b/lib/Fuzzer/FuzzerInternal.h index e3a1801b467..f1e7415bb63 100644 --- a/lib/Fuzzer/FuzzerInternal.h +++ b/lib/Fuzzer/FuzzerInternal.h @@ -12,19 +12,18 @@ #ifndef LLVM_FUZZER_INTERNAL_H #define LLVM_FUZZER_INTERNAL_H -#include -#include -#include -#include -#include -#include - #include "FuzzerDefs.h" #include "FuzzerExtFunctions.h" #include "FuzzerInterface.h" #include "FuzzerOptions.h" #include "FuzzerSHA1.h" #include "FuzzerValueBitMap.h" +#include +#include +#include +#include +#include +#include namespace fuzzer { diff --git a/lib/Fuzzer/FuzzerLoop.cpp b/lib/Fuzzer/FuzzerLoop.cpp index f96fc7416ff..93db6179e3d 100644 --- a/lib/Fuzzer/FuzzerLoop.cpp +++ b/lib/Fuzzer/FuzzerLoop.cpp @@ -15,7 +15,6 @@ #include "FuzzerMutate.h" #include "FuzzerRandom.h" #include "FuzzerTracePC.h" - #include #include #include diff --git a/lib/Fuzzer/FuzzerSHA1.h b/lib/Fuzzer/FuzzerSHA1.h index b3e6111b474..3b5e6e807f4 100644 --- a/lib/Fuzzer/FuzzerSHA1.h +++ b/lib/Fuzzer/FuzzerSHA1.h @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// // SHA1 utils. //===----------------------------------------------------------------------===// + #ifndef LLVM_FUZZER_SHA1_H #define LLVM_FUZZER_SHA1_H @@ -28,4 +29,5 @@ std::string Sha1ToString(const uint8_t Sha1[kSHA1NumBytes]); std::string Hash(const Unit &U); } // namespace fuzzer + #endif // LLVM_FUZZER_SHA1_H diff --git a/lib/Fuzzer/FuzzerTracePC.h b/lib/Fuzzer/FuzzerTracePC.h index acff27fd9db..df037390c2a 100644 --- a/lib/Fuzzer/FuzzerTracePC.h +++ b/lib/Fuzzer/FuzzerTracePC.h @@ -12,10 +12,9 @@ #ifndef LLVM_FUZZER_TRACE_PC #define LLVM_FUZZER_TRACE_PC -#include - #include "FuzzerDefs.h" #include "FuzzerValueBitMap.h" +#include namespace fuzzer { diff --git a/lib/Fuzzer/FuzzerUtil.h b/lib/Fuzzer/FuzzerUtil.h index 78b7c2489b0..08058c56e4c 100644 --- a/lib/Fuzzer/FuzzerUtil.h +++ b/lib/Fuzzer/FuzzerUtil.h @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// // Util functions. //===----------------------------------------------------------------------===// + #ifndef LLVM_FUZZER_UTIL_H #define LLVM_FUZZER_UTIL_H @@ -67,4 +68,5 @@ inline std::string CloneArgsWithoutX(const std::vector &Args, } } // namespace fuzzer + #endif // LLVM_FUZZER_UTIL_H diff --git a/lib/Fuzzer/FuzzerUtilDarwin.cpp b/lib/Fuzzer/FuzzerUtilDarwin.cpp index 62f0f2271fe..9674368c355 100644 --- a/lib/Fuzzer/FuzzerUtilDarwin.cpp +++ b/lib/Fuzzer/FuzzerUtilDarwin.cpp @@ -10,6 +10,7 @@ //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" #if LIBFUZZER_APPLE + #include "FuzzerIO.h" #include #include @@ -145,5 +146,7 @@ int ExecuteCommand(const std::string &Command) { } return ProcessStatus; } -} + +} // namespace fuzzer + #endif // LIBFUZZER_APPLE diff --git a/lib/Fuzzer/FuzzerUtilLinux.cpp b/lib/Fuzzer/FuzzerUtilLinux.cpp index 060cec04542..dfe7e6f4e18 100644 --- a/lib/Fuzzer/FuzzerUtilLinux.cpp +++ b/lib/Fuzzer/FuzzerUtilLinux.cpp @@ -10,10 +10,15 @@ //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" #if LIBFUZZER_LINUX + #include + namespace fuzzer { + int ExecuteCommand(const std::string &Command) { return system(Command.c_str()); } -} + +} // namespace fuzzer + #endif // LIBFUZZER_LINUX diff --git a/lib/Fuzzer/FuzzerUtilPosix.cpp b/lib/Fuzzer/FuzzerUtilPosix.cpp index fc058cd7260..8b484b8effa 100644 --- a/lib/Fuzzer/FuzzerUtilPosix.cpp +++ b/lib/Fuzzer/FuzzerUtilPosix.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // Misc utils implementation using Posix API. //===----------------------------------------------------------------------===// - #include "FuzzerDefs.h" #if LIBFUZZER_POSIX #include "FuzzerIO.h" @@ -113,5 +112,6 @@ const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt, return memmem(Data, DataLen, Patt, PattLen); } -} // namespace fuzzer +} // namespace fuzzer + #endif // LIBFUZZER_POSIX diff --git a/lib/Fuzzer/FuzzerUtilWindows.cpp b/lib/Fuzzer/FuzzerUtilWindows.cpp index 91509cce8b5..fea09a698b5 100644 --- a/lib/Fuzzer/FuzzerUtilWindows.cpp +++ b/lib/Fuzzer/FuzzerUtilWindows.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // Misc utils implementation for Windows. //===----------------------------------------------------------------------===// - #include "FuzzerDefs.h" #if LIBFUZZER_WINDOWS #include "FuzzerIO.h" @@ -179,4 +178,5 @@ const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt, } } // namespace fuzzer + #endif // LIBFUZZER_WINDOWS