-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Introduce unsafe offset_from on pointers #49297
Changes from all commits
68e0ea9
d6926ca
02b5851
4a097ea
6264952
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 |
---|---|---|
|
@@ -289,7 +289,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>, | |
"ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" | "ctpop" | "bswap" | | ||
"bitreverse" | "add_with_overflow" | "sub_with_overflow" | | ||
"mul_with_overflow" | "overflowing_add" | "overflowing_sub" | "overflowing_mul" | | ||
"unchecked_div" | "unchecked_rem" | "unchecked_shl" | "unchecked_shr" => { | ||
"unchecked_div" | "unchecked_rem" | "unchecked_shl" | "unchecked_shr" | "exact_div" => { | ||
let ty = arg_tys[0]; | ||
match int_type_width_signed(ty, cx) { | ||
Some((width, signed)) => | ||
|
@@ -343,6 +343,12 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>, | |
"overflowing_add" => bx.add(args[0].immediate(), args[1].immediate()), | ||
"overflowing_sub" => bx.sub(args[0].immediate(), args[1].immediate()), | ||
"overflowing_mul" => bx.mul(args[0].immediate(), args[1].immediate()), | ||
"exact_div" => | ||
if signed { | ||
bx.exactsdiv(args[0].immediate(), args[1].immediate()) | ||
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.
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. It turned out to already exist: https://github.com/rust-lang/rust/pull/49297/files#diff-89b470c8d50892235012a9fffdb50d7cR361 |
||
} else { | ||
bx.exactudiv(args[0].immediate(), args[1].immediate()) | ||
}, | ||
"unchecked_div" => | ||
if signed { | ||
bx.sdiv(args[0].immediate(), args[1].immediate()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-flags: -C no-prepopulate-passes | ||
|
||
#![crate_type = "lib"] | ||
#![feature(core_intrinsics)] | ||
|
||
use std::intrinsics::exact_div; | ||
|
||
// CHECK-LABEL: @exact_sdiv | ||
#[no_mangle] | ||
pub unsafe fn exact_sdiv(x: i32, y: i32) -> i32 { | ||
// CHECK: sdiv exact | ||
exact_div(x, y) | ||
} | ||
|
||
// CHECK-LABEL: @exact_udiv | ||
#[no_mangle] | ||
pub unsafe fn exact_udiv(x: u32, y: u32) -> u32 { | ||
// CHECK: udiv exact | ||
exact_div(x, y) | ||
} |
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 will panic at runtime. You do this a few other places as well. You should probably use
get_unchecked
? There's no actual mention of UB if you index out of bounds, so, I don't think it's an issue.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.
Huh?
a
is an array of length 5, soa[3]
is not out of bounds.(But if it was,
get_unchecked
would be UB because it usesoffset
, notwrapping_offset
.)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.
I, uh, may be too used to OCaml, sorry -.-
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.
Also,
offset
works with pointers which are one past the end.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.
Oh yeah ifEdit: Uh, yeah, see belowa
had length 2 then that would have been fine.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.
Actually, I'm just being stupid, array indexing is zero-based lol. Sorry, I should not comment when I'm tired :P