[PATCH] Add clang-fuzzer target

Aaron Ballman aaron at aaronballman.com
Mon Apr 6 09:07:28 PDT 2015


This appears to have broken the build for Windows.

http://bb.pgr.jp/builders/msbuild-llvmclang-x64-msc18-DA/builds/116/steps/build_clang_all/logs/stdio

I am seeing this breakage locally as well. It seems that the
LLVMFuzzer library is not being built (possibly because of
LLVM_USE_SANITIZE_COVERAGE not being true?), and so clang-fuzzer gets
link failures.

~Aaron

On Thu, Jan 29, 2015 at 10:33 PM, Kostya Serebryany <kcc at google.com> wrote:
> Hi chandlerc,
>
> Add clang-fuzzer target.
> This is a very naive and slow clang fuzzer, but it has found
> one new bug (PR22396) and hit a known bug (PR21954) in just a few minutes,
> so I think it deserves to be committed.
> I would appreciate further contribution to fuzzer/ClangFuzzer.cpp
> to make if faster and more meaningful.
>
> http://reviews.llvm.org/D7289
>
> Files:
>   CMakeLists.txt
>   fuzzer/
>   fuzzer/CMakeLists.txt
>   fuzzer/ClangFuzzer.cpp
>
> Index: CMakeLists.txt
> ===================================================================
> --- CMakeLists.txt
> +++ CMakeLists.txt
> @@ -532,3 +532,7 @@
>      ${CLANG_BINARY_DIR}/share/clang/cmake/ClangConfig.cmake
>      COPYONLY)
>  endif ()
> +
> +if( LLVM_USE_SANITIZE_COVERAGE )
> +  add_subdirectory(fuzzer)
> +endif()
> Index: fuzzer/CMakeLists.txt
> ===================================================================
> --- /dev/null
> +++ fuzzer/CMakeLists.txt
> @@ -0,0 +1,17 @@
> +set(LLVM_LINK_COMPONENTS support)
> +
> +add_clang_executable(clang-fuzzer
> +  ClangFuzzer.cpp
> +  )
> +
> +target_link_libraries(clang-fuzzer
> +  clangAST
> +  clangASTMatchers
> +  clangBasic
> +  clangFrontend
> +  clangLex
> +  clangRewrite
> +  clangTooling
> +  clangToolingCore
> +  LLVMFuzzer
> +  )
> Index: fuzzer/ClangFuzzer.cpp
> ===================================================================
> --- /dev/null
> +++ fuzzer/ClangFuzzer.cpp
> @@ -0,0 +1,34 @@
> +//===-- ClangFuzzer.cpp - Fuzz Clang --------------------------------------===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +///
> +/// \file
> +/// \brief This file implements a function that runs Clang on a single
> +///  input. This function is then linked into the Fuzzer library.
> +///  See llvm/lib/Fuzzer/README.txt for more instructions.
> +///
> +//===----------------------------------------------------------------------===//
> +
> +#include <stdio.h>
> +#include <stddef.h>
> +#include <stdint.h>
> +
> +#include "clang/Tooling/Tooling.h"
> +#include <string>
> +
> +// FIXME: The current implementation is very naive an inefficient:
> +// - buildASTFromCode does a lot of driver work which slows down things.
> +// - Errors are reported to stderr slowing things even further.
> +//
> +// What we really need here is a function that takes the array of bytes
> +// and invokes preprocessor and/or parser on it, sending messages to dev/null.
> +
> +extern "C" void TestOneInput(uint8_t *data, size_t size) {
> +  std::string S((char*)data, size);
> +  clang::tooling::buildASTFromCode(S);
> +}
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list