-
Notifications
You must be signed in to change notification settings - Fork 1.6k
<limits>: fix traps for integers
#5816
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
Open
AlexGuteniev
wants to merge
20
commits into
microsoft:main
Choose a base branch
from
AlexGuteniev:tricks-and-traps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−6
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2b4fb31
Integer coverage
AlexGuteniev 9833a4a
Product code fix
AlexGuteniev b17606a
Skip numeric.limits.members/traps.pass.cpp for Clang.
AlexGuteniev 97e6faa
Skippy skip
AlexGuteniev 586b09f
Merge remote-tracking branch 'upstream/main' into tricks-and-traps
AlexGuteniev e627022
it is always the trap
AlexGuteniev ad6a32f
but Clang
AlexGuteniev 816d158
concise override
AlexGuteniev 6996605
Spell that more naturally
AlexGuteniev 3347a99
Now we know
AlexGuteniev a49bce3
comprehensive compile-time coverage
AlexGuteniev e1a996e
nicer test format
AlexGuteniev 257f831
No longer SKIPPED actually
AlexGuteniev 4ede9b1
No more death, no more execution!
AlexGuteniev 72bd6f4
spelling
AlexGuteniev 614a323
spelling
AlexGuteniev c9c5ab7
ARM64EC fix
AlexGuteniev 1c3179e
back 2 skipped
AlexGuteniev 6e2f0e9
Merge branch 'main' into tricks-and-traps
AlexGuteniev b0fa9a6
mention LWG-554
AlexGuteniev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\usual_matrix.lst |
40 changes: 40 additions & 0 deletions
40
tests/std/tests/GH_005816_numeric_limits_traps/test.compile.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <limits> | ||
|
|
||
| #if defined(_M_IX86) || defined(_M_X64) && !defined(_M_ARM64EC) | ||
| // The #ED hardware exception always happens for zero division and for division overflow INT_MIN/-1 | ||
| // It is translated to the corresponding SEH exceptions | ||
| constexpr bool _Integer_zero_division_traps = true; | ||
| #elif defined(_M_ARM64) || defined(_M_ARM64EC) || defined(_M_HYBRID_X86_ARM64) | ||
| // The hardware does not trap. | ||
| #ifdef __clang__ | ||
| // Clang compiles code as is, so there's no trap | ||
| constexpr bool _Integer_zero_division_traps = false; | ||
| #else // ^^^ defined(__clang__) / !defined(__clang__) vvv | ||
| // MSVC inserts check for zero to trap zero division. | ||
| // It does not insert checks for INT_MIN/-1 division overflow though. | ||
| constexpr bool _Integer_zero_division_traps = true; | ||
| #endif // ^^^ !defined(__clang__) ^^^ | ||
| #else // ^^^ defined(_M_ARM64) || defined(_M_ARM64EC) || defined(_M_HYBRID_X86_ARM64) ^^^ | ||
| #error Unsupported hardware | ||
| #endif | ||
|
|
||
| template <class T> | ||
| constexpr bool traps_ = std::numeric_limits<T>::traps; | ||
|
|
||
| static_assert(traps_<int> == _Integer_zero_division_traps, | ||
| "integer trap behavior should match the expectation from the current platform and complier"); | ||
|
|
||
| static_assert(traps_<char> == traps_<int> && traps_<signed char> == traps_<int> && traps_<unsigned char> == traps_<int> | ||
| && traps_<short> == traps_<int> && traps_<unsigned short> == traps_<int> | ||
| && traps_<unsigned int> == traps_<int> // | ||
| && traps_<long> == traps_<int> && traps_<unsigned long> == traps_<int> | ||
| && traps_<long long> == traps_<int> && traps_<unsigned long long> == traps_<int>, | ||
| "all integers should trap or not trap equally"); | ||
|
|
||
| static_assert(!traps_<bool>, "bool does not trap for a moot reason; see LWG-554 resolution"); | ||
|
|
||
| static_assert(!traps_<float> && !traps_<double> && !traps_<long double>, | ||
| "floats don't trap because even if '/fp:except' is passed, it should be enabled at runtime"); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frederick-vs-ja suggests these should not trap either, according to LWG-554 resolution interpretation.
I'm not sure.