-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
tests/assembly-llvm/some-non-zero-from-atomic-optimization.rs: New test #149658
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
Enselic
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
Enselic:non-zero-opt
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.
+54
−0
Open
Changes from all commits
Commits
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
54 changes: 54 additions & 0 deletions
54
tests/assembly-llvm/some-non-zero-from-atomic-optimization.rs
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,54 @@ | ||
| //! Regression test for <https://github.com/rust-lang/rust/issues/60044>. | ||
| //@ assembly-output: emit-asm | ||
| //@ only-x86_64 | ||
|
|
||
| // We want to check that the None case is optimized away | ||
| //@ compile-flags: -O | ||
|
|
||
| // Simplify the generated assembly | ||
| //@ compile-flags: -Cforce-unwind-tables=no | ||
|
|
||
| #![crate_type = "lib"] | ||
|
|
||
| use std::num::NonZeroUsize; | ||
| use std::sync::atomic::AtomicUsize; | ||
| use std::sync::atomic::Ordering::Relaxed; | ||
|
|
||
| pub static X: AtomicUsize = AtomicUsize::new(1); | ||
|
|
||
| /// This function function shall look like this: | ||
| /// ``` | ||
| /// some_non_zero_from_atomic_get: | ||
| /// movq _RNvCs7C4TuIcXqwO_25some_non_zero_from_atomic1X@GOTPCREL(%rip), %rax | ||
| /// movq (%rax), %rax | ||
| /// retq | ||
| /// ``` | ||
| // CHECK-LABEL: some_non_zero_from_atomic_get: | ||
| // CHECK-NEXT: movq {{[_a-zA-Z0-9]+}}@GOTPCREL(%rip), %rax | ||
| // CHECK-NEXT: movq (%rax), %rax | ||
| // CHECK-NEXT: retq | ||
| #[no_mangle] | ||
| pub unsafe fn some_non_zero_from_atomic_get() -> Option<NonZeroUsize> { | ||
| let x = X.load(Relaxed); | ||
| Some(NonZeroUsize::new_unchecked(x)) | ||
| } | ||
|
|
||
| /// This function shall be identical to the above, which mean that for LLVM 21 | ||
| /// we should see | ||
| /// ``` | ||
| /// some_non_zero_from_atomic_get2 = some_non_zero_from_atomic_get | ||
| /// ``` | ||
| /// and for LLVM 20 we should see | ||
| /// ``` | ||
| /// .set some_non_zero_from_atomic_get2, some_non_zero_from_atomic_get | ||
| /// ``` | ||
| /// so use a regex to match either one. | ||
| // CHECK-DAG: {{\.set some_non_zero_from_atomic_get2, some_non_zero_from_atomic_get|some_non_zero_from_atomic_get2 = some_non_zero_from_atomic_get}} | ||
| #[no_mangle] | ||
| pub unsafe fn some_non_zero_from_atomic_get2() -> usize { | ||
| match some_non_zero_from_atomic_get() { | ||
| Some(x) => x.get(), | ||
| None => unreachable!(), // shall be optimized out | ||
| } | ||
| } | ||
Oops, something went wrong.
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 is incompatible with platforms that need LVI mitigations. At the moment I think that's only the
x86_64-fortanix-unknown-sgxtarget. Could you add//@ ignore-sgxon top to ignore this platform?