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

Conversation

chrchr-github
Copy link
Collaborator

…s not available

if (USE_BOOST_MULTIPREC)
find_package(Boost REQUIRED COMPONENTS system)
include_directories(${Boost_INCLUDE_DIRS})
add_compile_definitions(USE_BOOST_MULTIPREC)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should use:

target_include_directories(lib_objs PUBLIC SYSTEM ${Boost_INCLUDE_DIRS})
target_compile_definitions(lib_objs PUBLIC USE_BOOST_MULTIPREC)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess this makes it specific to lib_objs?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's add_definitions(-DUSE_BOOST_MULTIPREC) - target_compile_definitions() is not available in CMake 2.8 (let's tackle a CMake update later - if I ever get healthy again).

Also those should be placed in findDependencies.cmake and compilerDefinitions.cmake.

Also those should be PRIVATE so they don't spill into everything.

@pfultz2
Copy link
Contributor

pfultz2 commented Aug 30, 2021

Dont we need to update MathLib::bigint to make this useful for ValueFlow as well? As this changes only affect the bug-hunting.

@pfultz2
Copy link
Contributor

pfultz2 commented Aug 30, 2021

I guess the MathLib::bigint change could be made in another PR.

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

@@ -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.

@danmar
Copy link
Owner

danmar commented Aug 30, 2021

I am skeptic about taking in a boost dependency even if it's optional. I assume this is a msvc problem primarily. Is there no cleaner way to get this in windows also?

@@ -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.

@firewave
Copy link
Collaborator

firewave commented Aug 30, 2021

I am skeptic about taking in a boost dependency even if it's optional. I assume this is a msvc problem primarily. Is there no cleaner way to get this in windows also?

Maybe using clang-cl... and probably using Cygwin/MinGW.

@danmar
Copy link
Owner

danmar commented Aug 30, 2021

Hi @firewave good to see you..

I think we should look into using clang-cl in the windows build. as far as I have seen it makes the cppcheck binary a lot faster. For information, there is a ticket here: https://trac.cppcheck.net/ticket/10441

And then for the bughunting I am not 100% sure it was a good idea to use 128 bit integer. The Z3 library does not support this at all so we get 64-bit integers anyway in all expressions. Maybe a redesign is better..

@firewave
Copy link
Collaborator

Hi @firewave good to see you..

Don't blink.

I think we should look into using clang-cl in the windows build. as far as I have seen it makes the cppcheck binary a lot faster.

Well - I think it's up to the actual user which toolchain is being used. And having something which is available on all platforms seems better. But I also feel uneasy about having a Boost dependency. I would prefer something much lighter.

And then for the bughunting I am not 100% sure it was a good idea to use 128 bit integer. The Z3 library does not support this at all so we get 64-bit integers anyway in all expressions. Maybe a redesign is better..

This was actually triggered by https://trac.cppcheck.net/ticket/9994 which has nothing to do with bug hunting.

@danmar
Copy link
Owner

danmar commented Aug 30, 2021

This was actually triggered by https://trac.cppcheck.net/ticket/9994 which has nothing to do with bug hunting.

aha ok..

Do we have to make bigint 128 bit.. I have the feeling that some class like:

class bigint {
    uint64_t rawvalue;
    uint8_t bits;
    bool sign;
};

and then some convenient interface might work also..? and maybe that could handle calculations more properly also.

@chrchr-github
Copy link
Collaborator Author

I guess I won't waste time on CMake details until there is a consensus that this could be approved in principle...

@danmar
Copy link
Owner

danmar commented Aug 30, 2021

thanks @chrchr-github that sounds reasonable.

@pfultz2
Copy link
Contributor

pfultz2 commented Aug 30, 2021

We could incorporate calccrypto/uint128_t into cppcheck. We would need to write some code to make this work for signed integers(although all the arithmetic operations should be the same only the conversions need updated) and we may need fill in some of the math functions.

However, using boost.multiprecision doesn't really need any extra code changes, so it seems simpler to integrate and then we can look into removing dependency in the future.

I have the feeling that some class like

I am not sure how easy that can be used in place of bigint. We would need to implement all of the operators for this, and bitwise operations may not work correctly since it no longer uses two's complement.

I think it would be best to use boost.multiprecision as an optional dependency now and then we can look at better options in the future.

Also, this is header only, so this does not require building boost nor will the final binaries have a dependency on boost.

@firewave
Copy link
Collaborator

Also, this is header only, so this does not require building boost nor will the final binaries have a dependency on boost.

Good point.

I guess I won't waste time on CMake details until there is a consensus that this could be approved in principle...

"waste" - it's "learning" ;)

@firewave
Copy link
Collaborator

firewave commented Sep 4, 2021

BTW Please mark this a draft for now until the changes are finished/it has been decided about. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants