From 5bca92b23cdc298ebc9728a12e3dd0969f97fafb Mon Sep 17 00:00:00 2001 From: slavek-kucera <53339291+slavek-kucera@users.noreply.github.com> Date: Thu, 23 Feb 2023 10:07:36 +0100 Subject: [PATCH] ci: Always build fuzzer source code --- parser_library/CMakeLists.txt | 6 ++---- parser_library/fuzzer/CMakeLists.txt | 16 +++++++++------- parser_library/fuzzer/fuzzer.cpp | 22 +++++++++++++++------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/parser_library/CMakeLists.txt b/parser_library/CMakeLists.txt index bc220b03b..91166ec48 100644 --- a/parser_library/CMakeLists.txt +++ b/parser_library/CMakeLists.txt @@ -27,7 +27,7 @@ add_subdirectory(src) add_subdirectory(include) if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(parser_library PUBLIC PARSER_LIBRARY_STATIC_DEFINE=1) + target_compile_definitions(parser_library PUBLIC PARSER_LIBRARY_STATIC_DEFINE=1) endif() generate_export_header(parser_library @@ -52,6 +52,4 @@ if(BUILD_TESTING) add_subdirectory(test) endif() -if(BUILD_FUZZER) - add_subdirectory(fuzzer) -endif() +add_subdirectory(fuzzer) diff --git a/parser_library/fuzzer/CMakeLists.txt b/parser_library/fuzzer/CMakeLists.txt index 5e477d62e..26d3f0f92 100644 --- a/parser_library/fuzzer/CMakeLists.txt +++ b/parser_library/fuzzer/CMakeLists.txt @@ -13,17 +13,20 @@ Project(fuzzer) -add_executable(library_fuzzer) +if(BUILD_FUZZER) + add_executable(library_fuzzer) + set_target_properties(library_fuzzer PROPERTIES LINK_FLAGS "-fsanitize=fuzzer") +else() + add_library(library_fuzzer) +endif() target_sources(library_fuzzer PRIVATE - fuzzer.cpp + fuzzer.cpp ) -set_target_properties(library_fuzzer PROPERTIES LINK_FLAGS "-fsanitize=fuzzer") - configure_file( - fuzzer.dict - ${CMAKE_BINARY_DIR}/bin/fuzzer.dict + fuzzer.dict + ${CMAKE_BINARY_DIR}/bin/fuzzer.dict COPYONLY) target_link_libraries(library_fuzzer parser_library) @@ -31,4 +34,3 @@ target_link_libraries(library_fuzzer Threads::Threads) target_link_libraries(library_fuzzer ${ANTLR4_RUNTIME}) target_link_libraries(library_fuzzer std::filesystem) target_link_libraries(library_fuzzer nlohmann_json::nlohmann_json) - diff --git a/parser_library/fuzzer/fuzzer.cpp b/parser_library/fuzzer/fuzzer.cpp index fe6681bd4..7e0dc1eac 100644 --- a/parser_library/fuzzer/fuzzer.cpp +++ b/parser_library/fuzzer/fuzzer.cpp @@ -36,6 +36,8 @@ using namespace hlasm_plugin::parser_library::workspaces; class fuzzer_lib_provider : public parse_lib_provider { + using resource_location = hlasm_plugin::utils::resource::resource_location; + std::optional read_library_name(std::string_view library) const { if (library.size() < 2 || library.size() > 8 || library[0] != '@' @@ -62,26 +64,32 @@ class fuzzer_lib_provider : public parse_lib_provider return; } - auto a = std::make_unique(files[lib.value()], - analyzer_options { hlasm_plugin::utils::resource::resource_location(library), this, std::move(ctx), data }); + auto a = std::make_unique( + files[lib.value()], analyzer_options { resource_location(library), this, std::move(ctx), data }); a->analyze(); a->collect_diags(); callback(true); } - bool has_library(std::string_view library) const override { return read_library_name(library).has_value(); } + bool has_library(std::string_view library, resource_location* url) const override + { + auto lib = read_library_name(library); + if (!lib.has_value()) + return false; + if (url) + *url = resource_location(library); + return true; + } void get_library(std::string_view library, - std::function>)> callback) - const override + std::function>)> callback) const override { assert(callback); auto lib = read_library_name(library); if (!lib.has_value()) return callback(std::nullopt); - return callback(std::pair( - files[lib.value()], hlasm_plugin::utils::resource::resource_location(library))); + return callback(std::pair(files[lib.value()], resource_location(library))); } std::vector files;