Skip to content

Commit 703972d

Browse files
committed
Rewrite the test function to remove dependencies on libraries such as 'core' and 'compiler_builtins'.
1 parent 75df501 commit 703972d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/assembly-llvm/stack-protector/stack-protector-safe-stack.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,23 @@
1414
//@ compile-flags: -C opt-level=2 -Z merge-functions=disabled
1515

1616
#![no_std]
17-
#![crate_type = "lib"]
18-
#![allow(internal_features)]
17+
#![feature(link_llvm_intrinsics)]
1918
#![feature(unsized_fn_params)]
19+
#![crate_type = "lib"]
20+
21+
extern "C" {
22+
#[link_name = "llvm.memcpy.p0.p0.i64"]
23+
fn memcpy_intrinsic(dst: *mut u8, src: *const u8, size: u64, align: u32, is_volatile: bool);
24+
}
2025

21-
// Check the coexistence of stack-protector and safe-stack.
2226
// CHECK-LABEL: test1{{:|\[}}
2327
#[no_mangle]
2428
pub unsafe fn test1(src: *const u8, len: usize) -> u8 {
25-
let mut buf = [0u8; 64];
26-
core::ptr::copy_nonoverlapping(src, buf.as_mut_ptr(), len.min(buf.len()));
29+
let mut buf: [u8; 64] = [0; 64];
30+
31+
let copy_len = if len < 64 { len } else { 64 };
32+
memcpy_intrinsic(buf.as_mut_ptr(), src, copy_len as u64, 1, false);
33+
2734
buf[0]
2835

2936
// none-NOT: __stack_chk_fail

0 commit comments

Comments
 (0)