From fdbef97e22effa32acdfff616a0a92bdf02bf723 Mon Sep 17 00:00:00 2001 From: Bryan Tan Date: Sun, 10 Dec 2023 17:57:24 -0800 Subject: [PATCH 1/3] Fix GCC -Wreturn-type warnings Always return false in PowersetAbstractDomain::contains() and SmallSortedSetAbstractDomain::contains() to avoid a gcc warning. On debug builds, this will instead trigger an assertion failure. --- include/sparta/PowersetAbstractDomain.h | 4 ++++ include/sparta/SmallSortedSetAbstractDomain.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/include/sparta/PowersetAbstractDomain.h b/include/sparta/PowersetAbstractDomain.h index 88e1ca5..a21b5a1 100644 --- a/include/sparta/PowersetAbstractDomain.h +++ b/include/sparta/PowersetAbstractDomain.h @@ -14,6 +14,7 @@ #include #include +#include namespace sparta { namespace pad_impl { @@ -235,6 +236,9 @@ class PowersetAbstractDomain return this->get_value()->contains(e); } } + SPARTA_ASSERT(false && "unknown AbstractValueKind"); + // Return false to suppress -Wreturn-type warning reported by gcc + return false; } friend std::ostream& operator<<(std::ostream& o, const Derived& s) { diff --git a/include/sparta/SmallSortedSetAbstractDomain.h b/include/sparta/SmallSortedSetAbstractDomain.h index 514f094..9a3229b 100644 --- a/include/sparta/SmallSortedSetAbstractDomain.h +++ b/include/sparta/SmallSortedSetAbstractDomain.h @@ -167,6 +167,9 @@ class SmallSortedSetAbstractDomain final return this->get_value()->contains(e); } } + SPARTA_ASSERT(false && "unknown AbstractValueKind"); + // Return false to suppress -Wreturn-type warning reported by gcc + return false; } friend std::ostream& operator<<(std::ostream& out, From e5d1dbc7c54f6b7c5ebc2d3c8eada8b1e93773cf Mon Sep 17 00:00:00 2001 From: Bryan Tan Date: Sun, 10 Dec 2023 17:57:24 -0800 Subject: [PATCH 2/3] Only add test targets if testing is enabled This commit ensures that test targets are only added if BUILD_TESTING is enabled when generating the CMake configuration. There should be no change in behavior, as BUILD_TESTING defaults to ON. --- CMakeLists.txt | 18 ++++-------------- test/CMakeLists.txt | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f3d3d4..d8b04ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..b36f911 --- /dev/null +++ b/test/CMakeLists.txt @@ -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() From 4b617ae7558c18ad47f7fcdee0160840879b3d2a Mon Sep 17 00:00:00 2001 From: Bryan Tan Date: Sun, 10 Dec 2023 17:57:24 -0800 Subject: [PATCH 3/3] Fix install interface to use CMAKE_INSTALL_INCLUDEDIR Currently, the sparta target will use `$CMAKE_INSTALL_PREFIX/include` as the include directory when installed. If the user sets a custom CMAKE_INSTALL_INCLUDEDIR, however, then this will not be the correct location. This commit changes the include directory of the sparta target to be consistent with the actual installed location. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d8b04ab..f549e39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ add_library(sparta INTERFACE) target_include_directories(sparta INTERFACE $ - $ + $ ) target_link_libraries(sparta INTERFACE ${Boost_LIBRARIES})