Skip to content
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

debug-assert ptr sanity in ptr::write #69509

Merged
merged 4 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,7 @@ pub unsafe fn read_unaligned<T>(src: *const T) -> T {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn write<T>(dst: *mut T, src: T) {
// FIXME: the debug assertion here causes codegen test failures on some architectures.
// See <https://github.com/rust-lang/rust/pull/69208#issuecomment-591326757>.
// debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
intrinsics::move_val_init(&mut *dst, src)
}

Expand Down
7 changes: 1 addition & 6 deletions src/test/codegen/repeat-trusted-len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@

use std::iter;

// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
#[no_mangle]
pub fn helper(_: usize) {
}

// CHECK-LABEL: @repeat_take_collect
#[no_mangle]
pub fn repeat_take_collect() -> Vec<u8> {
// CHECK: call void @llvm.memset.p0i8.[[USIZE]](i8* {{(nonnull )?}}align 1{{.*}} %{{[0-9]+}}, i8 42, [[USIZE]] 100000, i1 false)
// CHECK: call void @llvm.memset.p0i8.i{{[0-9]+}}(i8* {{(nonnull )?}}align 1{{.*}} %{{[0-9]+}}, i8 42, i{{[0-9]+}} 100000, i1 false)
iter::repeat(42).take(100000).collect()
}
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-40883.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ fn verify_stack_usage(before_ptr: *mut Vec<Big>) {
let stack_usage = isize::abs(
(&mut stack_var as *mut _ as isize) -
(before_ptr as isize)) as usize;
// give space for 2 copies of `Big` + 128 "misc" bytes.
if stack_usage > mem::size_of::<Big>() * 2 + 128 {
// give space for 2 copies of `Big` + 256 "misc" bytes.
if stack_usage > mem::size_of::<Big>() * 2 + 256 {
Copy link
Member

@eddyb eddyb Mar 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this constant be binary searched so it's less than double the previous value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought powers of two were nice, but sure. ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

208 is the smallest value that works for me.
But I am a bit worried it might be larger for other platforms / architectures.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support a target with larger sizes/alignments than x64 I don't think.

Copy link
Member

@eddyb eddyb Mar 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nevermind, they could less efficient in their stack usage even if the types aren't larger.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's what I meant.

panic!("used {} bytes of stack, but `struct Big` is only {} bytes",
stack_usage, mem::size_of::<Big>());
}
Expand Down