CMake: Add -fsanitize-undefined-trap-on-error to MaxSan configuration#146
Merged
ednolan merged 1 commit intobemanproject:mainfrom Mar 16, 2025
ednolan:enolan_ubsantrap1
Merged
CMake: Add -fsanitize-undefined-trap-on-error to MaxSan configuration#146ednolan merged 1 commit intobemanproject:mainfrom ednolan:enolan_ubsantrap1
ednolan merged 1 commit intobemanproject:mainfrom
ednolan:enolan_ubsantrap1
Conversation
Previously, the following implementation of identity would pass all
tests under MaxSan:
```
struct identity {
// Returns `t`.
template <class T>
constexpr T&& operator()(T&& t) const noexcept {
int x = std::numeric_limits<int>::max();
++x;
return std::forward<T>(t);
}
using is_transparent = __is_transparent;
};
```
This is because UndefinedBehaviorSanitizer would diagnose the integer
overflow by printing, but would not abort the program:
```
[ RUN ] IdentityTest.check_is_transparent
bemanproject/exemplar/include/beman/exemplar/identity.hpp:37:7: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
[ OK ] IdentityTest.check_is_transparent (0 ms)
```
After this change, the test correctly fails, with SIGILL:
```
The following tests FAILED:
1 - IdentityTest.call_identity_with_int (ILLEGAL)
```
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Previously, the following implementation of identity would pass all tests under MaxSan:
This is because UndefinedBehaviorSanitizer would diagnose the integer overflow by printing, but would not abort the program:
After this change, the test correctly fails, with SIGILL: