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

Make overflow checks optional at compile time #410

Merged
merged 13 commits into from
Nov 29, 2023

Conversation

danakj
Copy link
Collaborator

@danakj danakj commented Nov 29, 2023

This allows overflow checks to be removed through a compile-time option, by defining SUS_CHECK_INTEGER_OVERFLOW to false.

This aligns with the "arithmetic safety" profile suggested by Dr Stroustrup in "Delivering Safe C++": https://www.youtube.com/watch?v=I8UvQKvOSSw

Closes #408

If SUS_CHECK_INTEGER_OVERFLOW is defined to false then overflow checks
will be removed in signed integers. Wrapping operations (as with
unsigned integers) will be performed instead of Undefined Behaviour.
If SUS_CHECK_INTEGER_OVERFLOW is defined to false then overflow checks
will be removed in unsigned integers. Wrapping operations will be
performed for shift operations instead of Undefined Behaviour.
Clang caches the result of `if constexpr ()` across tests.
This avoids ODR issues where different tests cause integer methods
to be instantiated differently.
Add a 16 sanitizer bot since the 17 sanitizer bot is also broken.

Upstream: llvm/llvm-project#73402
The implementation is in unsigned_integer_impl.h and library code
can't always include both due to cycles.
These already exist for the basic operators, but were missing for
methods like checked_add, saturating_div, etc.
This reverts commit 389f5ee.

The problem was ODR violations, not the use of if constexpr. =)
@danakj danakj merged commit 67410e2 into chromium:main Nov 29, 2023
6 of 9 checks passed
@danakj danakj deleted the overflow-checks branch November 29, 2023 18:52
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.

Compile-time option for overflow checks
1 participant