-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[WIP] Implement unchecked_disjoint_bitor
#124601
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
Changes from 8 commits
0879bbf
5380e09
9ae9862
fbcb3dc
676d94b
49a5f89
e1e4c17
e62d5ce
018a3a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1478,6 +1478,8 @@ pub enum BinOp { | |||||
BitAnd, | ||||||
/// The `|` operator (bitwise or) | ||||||
BitOr, | ||||||
/// Like `BitOr` and `BitXor`, but UB if results don't match. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's express the requirement directly, in a way that matches the name, rather than indirectly. |
||||||
BitOrDisjoint, | ||||||
/// The `<<` operator (shift left) | ||||||
/// | ||||||
/// The offset is truncated to the size of the first operand and made unsigned before shifting. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,6 +320,7 @@ pub enum BinOp { | |
BitXor, | ||
BitAnd, | ||
BitOr, | ||
BitOrDisjoint, | ||
Shl, | ||
ShlUnchecked, | ||
Shr, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2311,6 +2311,16 @@ extern "rust-intrinsic" { | |||||||||||||||||||||||||||||||||
#[rustc_nounwind] | ||||||||||||||||||||||||||||||||||
pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
/// Performs an unchecked disjoint bitor operation. Equivalent to normal | ||||||||||||||||||||||||||||||||||
/// bitor and bitxor operations, triggering undefined behavior if their | ||||||||||||||||||||||||||||||||||
/// results differ. | ||||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||
/// The stable counterpart of this intrinsic is `unchecked_disjoint_bitor` | ||||||||||||||||||||||||||||||||||
/// on the various integer types, such as [`u16::unchecked_disjoint_bitor`] | ||||||||||||||||||||||||||||||||||
/// and [`i64::unchecked_disjoint_bitor`]. | ||||||||||||||||||||||||||||||||||
#[rustc_nounwind] | ||||||||||||||||||||||||||||||||||
pub fn disjoint_bitor<T: Copy>(x: T, y: T) -> T; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, as a good way to split up the PR, this PR should just add this as an intrinsic with fallback. You can see rust/library/core/src/intrinsics.rs Lines 968 to 973 in 5065123
Then a follow-up PR can change just the llvm backend to do something different, without needing to update cg_gcc nor cg_clif nor smir nor ... This this would be something like
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
/// Performs rotate left. | ||||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||
/// Note that, unlike most intrinsics, this is safe to call; | ||||||||||||||||||||||||||||||||||
|
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.
You need to
throw_ub!
. To that end, you first need to add a new error variant toUndefinedBehaviorInfo
, and then use that here.Make sure to also add a Miri testcase that checks that we detect the UB here.