Skip to content

Commit

Permalink
Miscellaneous bugfixes (#23)
Browse files Browse the repository at this point in the history
Summary:
This pull request includes several miscellaneous bugfixes, which (I think) should not introduce any breaking changes:

* Fix a gcc `-Wreturn-type` warning in `PowersetAbstractDomain` and `SmallSortedSetAbstractDomain` that causes build failures in downstream projects compiled with `-Werror -Wall`.
* Don't add test targets if the CMake variable `BUILD_TESTING` is falsey.
* Fix the exported CMake `sparta` target using the wrong directory as the include directory when installed

Pull Request resolved: #23

Reviewed By: arnaudvenet

Differential Revision: D52111351

Pulled By: arthaud

fbshipit-source-id: 97d9a89537ce77f575f0e073b43f5d81eeba6a08
  • Loading branch information
Technius authored and facebook-github-bot committed Dec 15, 2023
1 parent 345a3c5 commit f2f42d0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
20 changes: 5 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
cmake_minimum_required(VERSION 3.0.2)
project("sparta")

include(CTest)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
include(Commons)

Expand All @@ -25,7 +26,7 @@ add_library(sparta INTERFACE)

target_include_directories(sparta INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_link_libraries(sparta INTERFACE ${Boost_LIBRARIES})
Expand Down Expand Up @@ -53,17 +54,6 @@ export(TARGETS sparta FILE sparta_target.cmake)
###################################################
# test
###################################################
file(GLOB test "test/*.cpp")

include(CTest)
# ${test} contains all paths to the test cpps
foreach(testfile ${test})
# ${testfile} is in the format of test/SomeTest.cpp
string(REPLACE ".cpp" "_test" no_ext_name ${testfile})
# ${no_ext_name} is in the format of test/SomeTest_test
get_filename_component(test_bin ${no_ext_name} NAME)
# ${test_bin} is in the format of SomeTest_test
add_executable(${test_bin} ${testfile})
target_link_libraries(${test_bin} PRIVATE sparta gmock_main)
add_test(NAME ${testfile} COMMAND ${test_bin})
endforeach()
if (BUILD_TESTING)
add_subdirectory(test)
endif()
5 changes: 5 additions & 0 deletions include/sparta/PowersetAbstractDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <type_traits>

#include <sparta/AbstractDomain.h>
#include <sparta/Exceptions.h>

namespace sparta {
namespace pad_impl {
Expand Down Expand Up @@ -235,6 +236,10 @@ class PowersetAbstractDomain
return this->get_value()->contains(e);
}
}
SPARTA_RUNTIME_CHECK(
false, internal_error() << error_msg("unknown AbstractValueKind"));
// Return false to suppress -Wreturn-type warning reported by gcc
return false;
}

friend std::ostream& operator<<(std::ostream& o, const Derived& s) {
Expand Down
4 changes: 4 additions & 0 deletions include/sparta/SmallSortedSetAbstractDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ class SmallSortedSetAbstractDomain final
return this->get_value()->contains(e);
}
}
SPARTA_RUNTIME_CHECK(
false, internal_error() << error_msg("unknown AbstractValueKind"));
// Return false to suppress -Wreturn-type warning reported by gcc
return false;
}

friend std::ostream& operator<<(std::ostream& out,
Expand Down
17 changes: 17 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

file(GLOB test "*.cpp")

foreach(testfile ${test})
# ${testfile} is in the format of SomeTest.cpp
string(REPLACE ".cpp" "_test" no_ext_name ${testfile})
# ${no_ext_name} is in the format of SomeTest_test
get_filename_component(test_bin ${no_ext_name} NAME)
# ${test_bin} is in the format of SomeTest_test
add_executable(${test_bin} ${testfile})
target_link_libraries(${test_bin} PRIVATE sparta gmock_main)
add_test(NAME ${testfile} COMMAND ${test_bin})
endforeach()

0 comments on commit f2f42d0

Please sign in to comment.