Index: docs/LibFuzzer.rst =================================================================== --- docs/LibFuzzer.rst +++ docs/LibFuzzer.rst @@ -639,13 +639,16 @@ LibFuzzer is built as a part of LLVM project by default on macos and Linux. Users of other operating systems can explicitly request compilation using ``-DLIBFUZZER_ENABLE=YES`` flag. -Tests are run using ``check-fuzzer`` target from the build directory -which was configured with ``-DLIBFUZZER_ENABLE_TESTS=ON`` flag. +Tests are run using ``check-fuzzer`` target from the build directory, +provided Clang is checked out in your source tree: .. code-block:: console ninja check-fuzzer +If you wish to use a different Clang, you can specify it using +``LIBFUZZER_TEST_COMPILER`` environment variable. + Fuzzing components of LLVM ========================== Index: lib/Fuzzer/CMakeLists.txt =================================================================== --- lib/Fuzzer/CMakeLists.txt +++ lib/Fuzzer/CMakeLists.txt @@ -22,7 +22,6 @@ # Compile libFuzzer if the compilation is specifically requested, OR # if the platform is known to be working. set(LIBFUZZER_ENABLE ${LIBFUZZER_ENABLED_CHECK} CACHE BOOL "Build libFuzzer and its tests") -set(LIBFUZZER_ENABLE_TESTS OFF CACHE BOOL "Build libFuzzer and its tests") if (LLVM_USE_SANITIZE_COVERAGE) set(CMAKE_CXX_FLAGS @@ -71,7 +70,7 @@ add_custom_command(TARGET check-fuzzer COMMAND cmake -E echo "check-fuzzer is disalbed on Windows") else() - if (LLVM_INCLUDE_TESTS AND LIBFUZZER_ENABLE_TESTS) + if (LLVM_INCLUDE_TESTS) add_subdirectory(test) endif() endif() Index: lib/Fuzzer/test/CMakeLists.txt =================================================================== --- lib/Fuzzer/test/CMakeLists.txt +++ lib/Fuzzer/test/CMakeLists.txt @@ -13,6 +13,9 @@ # Unit tests ############################################################################### +# Do not register fuzzer tests under check-all. +set(EXCLUDE_FROM_ALL On) + add_custom_target(FuzzerUnitTests) set_target_properties(FuzzerUnitTests PROPERTIES FOLDER "libFuzzer tests") @@ -44,8 +47,7 @@ # Use just-built Clang to compile/link tests on all platforms, except for # Windows where we need to use clang-cl instead. -set(LIBFUZZER_TEST_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) -set(LIBFUZZER_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++) +set(LIBFUZZER_TEST_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang CACHE PATH "Path to Clang compiler") # LIT-based libFuzzer tests. configure_lit_site_cfg( @@ -63,4 +65,4 @@ ${CMAKE_CURRENT_BINARY_DIR} DEPENDS LLVMFuzzer-Unittest) -add_dependencies(check-fuzzer LLVMFuzzer asan clang llvm-symbolizer FileCheck sancov not) +add_dependencies(check-fuzzer LLVMFuzzer llvm-symbolizer FileCheck sancov not) Index: lib/Fuzzer/test/lit.cfg =================================================================== --- lib/Fuzzer/test/lit.cfg +++ lib/Fuzzer/test/lit.cfg @@ -54,7 +54,8 @@ config.substitutions.append(('%build_dir', config.cmake_binary_dir)) def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True): - compiler_cmd = config.cpp_compiler if is_cpp else config.c_compiler + compiler_cmd = config.c_compiler + driver_mode_cmd = '--driver-mode=g++' if is_cpp else '' std_cmd = '-std=c++11' if is_cpp else '' sanitizers = ['address'] if fuzzer_enabled: @@ -63,8 +64,9 @@ isysroot_cmd = ('-isysroot %s' % config.osx_sysroot ) if 'darwin' in config.target_triple else '' include_cmd = '-I%s/../.' % config.test_source_root - return '%s %s -gline-tables-only %s %s %s' % ( - compiler_cmd, std_cmd, isysroot_cmd, sanitizers_cmd, include_cmd) + return '%s %s %s -gline-tables-only %s %s %s' % ( + compiler_cmd, driver_mode_cmd, std_cmd, + isysroot_cmd, sanitizers_cmd, include_cmd) config.substitutions.append(('%cpp_compiler', generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True) Index: lib/Fuzzer/test/lit.site.cfg.in =================================================================== --- lib/Fuzzer/test/lit.site.cfg.in +++ lib/Fuzzer/test/lit.site.cfg.in @@ -1,7 +1,6 @@ config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@" config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" config.has_lsan = True if @HAS_LSAN@ == 1 else False -config.cpp_compiler = "@LIBFUZZER_TEST_CXX_COMPILER@" config.c_compiler = "@LIBFUZZER_TEST_COMPILER@" config.osx_sysroot = "@CMAKE_OSX_SYSROOT@" config.cmake_binary_dir = "@CMAKE_BINARY_DIR@"