Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use boost::multiprecision on platforms where int128_t i… #3430

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ option(WITH_QCHART "When building GUI(need BUILD_GUI=ON), use Qt5 Chart
option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF)
option(USE_Z3 "Usage of z3 library" OFF)
option(USE_BUNDLED_TINYXML2 "Usage of bundled tinyxml2 library" ON)
option(USE_BOOST_MULTIPREC "Usage of boost::multiprecision instead of int128_t" OFF)

if (CMAKE_VERSION VERSION_EQUAL "3.16" OR CMAKE_VERSION VERSION_GREATER "3.16")
set(CMAKE_DISABLE_PRECOMPILE_HEADERS Off CACHE BOOL "Disable precompiled headers")
Expand Down
6 changes: 6 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ add_library(lib_objs OBJECT ${srcs_lib} ${hdrs})
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(lib_objs PRIVATE precompiled.h)
endif()

if (USE_BOOST_MULTIPREC)
find_package(Boost REQUIRED COMPONENTS system)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why system? The component is just multiprecision.

target_include_directories(lib_objs PUBLIC SYSTEM ${Boost_INCLUDE_DIRS})
target_compile_definitions(lib_objs PUBLIC USE_BOOST_MULTIPREC)
endif()
2 changes: 1 addition & 1 deletion lib/exprengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ ExprEngine::ConditionalValue::Vector ExprEngine::ArrayValue::read(ExprEngine::Va
if (i->minValue >= 0 && i->minValue == i->maxValue) {
int c = 0;
if (i->minValue < stringLiteral->size())
c = stringLiteral->string[i->minValue];
c = stringLiteral->string[static_cast<size_t>(i->minValue)];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is 128-bit now it will probably cause problems when it doesn't fit into size_t.

ret.push_back(std::pair<ValuePtr,ValuePtr>(indexAndValue.index, std::make_shared<ExprEngine::IntRange>(std::to_string(c), c, c)));
continue;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/exprengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ class Variable;
#if defined(__GNUC__) && defined (__SIZEOF_INT128__)
typedef __int128_t int128_t;
#else
#if defined(USE_BOOST_MULTIPREC)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the first case. If we configure to use it we should use it across all platforms

#include <boost/multiprecision/cpp_int.hpp>
using int128_t = boost::multiprecision::int128_t;
#else
typedef long long int128_t;
#ifdef _MSC_VER
#pragma message(__FILE__ "(" _CRT_STRINGIZE(__LINE__) ")" ": warning: TODO No 128-bit integer type is available => Limited analysis of large integers...")
#else
#warning TODO No 128-bit integer type is available => Limited analysis of large integers
#endif
#endif
#endif

namespace ExprEngine {
std::string str(int128_t);
Expand Down