Skip to content

Commit

Permalink
ci: Always build fuzzer source code
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Feb 23, 2023
1 parent ef158c1 commit 5bca92b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
6 changes: 2 additions & 4 deletions parser_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,6 +52,4 @@ if(BUILD_TESTING)
add_subdirectory(test)
endif()

if(BUILD_FUZZER)
add_subdirectory(fuzzer)
endif()
add_subdirectory(fuzzer)
16 changes: 9 additions & 7 deletions parser_library/fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@

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)
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)

22 changes: 15 additions & 7 deletions parser_library/fuzzer/fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t> read_library_name(std::string_view library) const
{
if (library.size() < 2 || library.size() > 8 || library[0] != '@'
Expand All @@ -62,26 +64,32 @@ class fuzzer_lib_provider : public parse_lib_provider
return;
}

auto a = std::make_unique<analyzer>(files[lib.value()],
analyzer_options { hlasm_plugin::utils::resource::resource_location(library), this, std::move(ctx), data });
auto a = std::make_unique<analyzer>(
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<void(std::optional<std::pair<std::string, utils::resource::resource_location>>)> callback)
const override
std::function<void(std::optional<std::pair<std::string, resource_location>>)> callback) const override
{
assert(callback);
auto lib = read_library_name(library);
if (!lib.has_value())
return callback(std::nullopt);

return callback(std::pair<std::string, hlasm_plugin::utils::resource::resource_location>(
files[lib.value()], hlasm_plugin::utils::resource::resource_location(library)));
return callback(std::pair<std::string, resource_location>(files[lib.value()], resource_location(library)));
}

std::vector<std::string> files;
Expand Down

0 comments on commit 5bca92b

Please sign in to comment.