-
Notifications
You must be signed in to change notification settings - Fork 1.6k
<optional>: Add Address Sanitizer annotations
#6010
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
ozguronsoy
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
ozguronsoy:optional-asan
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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3be5fb2
add asan annotation to optional
ozguronsoy 37bcf48
fix poison tests
ozguronsoy c9f424c
use __asan_address_is_poisoned in tests
ozguronsoy b4fd22b
fix unused var error in tests
ozguronsoy 93879fe
add _is_constant_evaluated and should_annotate checks before annotations
ozguronsoy 1be4772
add constexpr test
ozguronsoy 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
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_17_matrix.lst |
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,72 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <cassert> | ||
| #include <optional> | ||
|
|
||
| #ifdef __SANITIZE_ADDRESS__ | ||
| extern "C" int __cdecl __asan_address_is_poisoned(void const volatile* addr); | ||
| #define ASAN_VERIFY_POISONED(addr) assert(__asan_address_is_poisoned((addr)) != 0) | ||
| #define ASAN_VERIFY_UNPOISONED(addr) assert(__asan_address_is_poisoned((addr)) == 0) | ||
| #else | ||
| #define ASAN_VERIFY_POISONED(addr) ((void) (addr)) | ||
| #define ASAN_VERIFY_UNPOISONED(addr) ((void) (addr)) | ||
| #endif | ||
|
|
||
| struct Payload { | ||
| long long x; | ||
| long long y; | ||
| long long z; | ||
| long long w; | ||
| }; | ||
|
|
||
| void test_poison_on_empty_access() { | ||
| [[maybe_unused]] std::optional<Payload> opt; | ||
| ASAN_VERIFY_POISONED(reinterpret_cast<Payload*>(&opt)); | ||
| } | ||
|
|
||
| void test_emplace_unpoisoning() { | ||
| std::optional<Payload> opt; | ||
| opt.emplace(); | ||
| ASAN_VERIFY_UNPOISONED(reinterpret_cast<Payload*>(&opt)); | ||
| } | ||
|
|
||
| void test_assignment_unpoisoning() { | ||
| std::optional<Payload> opt = std::nullopt; | ||
| opt = Payload{}; | ||
| ASAN_VERIFY_UNPOISONED(reinterpret_cast<Payload*>(&opt)); | ||
| } | ||
|
|
||
| void test_repoison_after_reset() { | ||
| std::optional<Payload> opt = Payload{}; | ||
| ASAN_VERIFY_UNPOISONED(reinterpret_cast<Payload*>(&opt)); | ||
| opt.reset(); | ||
| ASAN_VERIFY_POISONED(reinterpret_cast<Payload*>(&opt)); | ||
| } | ||
|
|
||
| constexpr bool test_constexpr() { | ||
| #if _HAS_CXX20 | ||
| bool res = true; | ||
| std::optional<Payload> opt = std::nullopt; | ||
| opt = Payload{}; | ||
| opt.reset(); | ||
| opt = Payload{86, 0, 0, 0}; | ||
| res = opt->x == 86; | ||
| opt.emplace(42, 0, 0, 0); | ||
| res = res && (opt->x == 42); | ||
| return res; | ||
| #else | ||
| std::optional<Payload> opt{Payload{86, 0, 0, 0}}; | ||
| return opt->x == 86; | ||
| #endif | ||
| } | ||
|
|
||
| int main() { | ||
| test_poison_on_empty_access(); | ||
| test_emplace_unpoisoning(); | ||
| test_assignment_unpoisoning(); | ||
| test_repoison_after_reset(); | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| static_assert(test_constexpr(), "constexpr test failed"); | ||
|
|
||
| return 0; | ||
| } | ||
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.
This variable isn't used. Is it really necessary?
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.
Added a check for this variable inside the
if(!_STD _Is_constant_evaluated())block.