2024-10-15 13:46:23 -05:00
|
|
|
//! This test case is a `#![no_core]`-version of the MVCE presented in #129301.
|
|
|
|
//!
|
2024-10-15 14:04:06 -05:00
|
|
|
//! The function [`delay()`] is removed, as it is not necessary to trigger the
|
|
|
|
//! wrong behavior and would require some additional lang items.
|
|
|
|
#![feature(no_core, lang_items, intrinsics, rustc_attrs)]
|
2024-10-14 16:06:32 -05:00
|
|
|
#![no_core]
|
2024-10-15 13:46:23 -05:00
|
|
|
#![no_main]
|
|
|
|
#![allow(internal_features)]
|
2024-10-14 16:06:32 -05:00
|
|
|
|
|
|
|
use minicore::ptr;
|
|
|
|
|
|
|
|
#[no_mangle]
|
2024-10-15 13:46:23 -05:00
|
|
|
pub fn main() -> ! {
|
2024-10-14 16:06:32 -05:00
|
|
|
let port_b = 0x25 as *mut u8; // the I/O-address of PORTB
|
2024-10-15 13:46:23 -05:00
|
|
|
|
|
|
|
// a simple loop with some trivial instructions within. This loop label has
|
|
|
|
// to be placed correctly before the `ptr::write_volatile()` (some LLVM ver-
|
|
|
|
// sions did place it after the first loop instruction, causing unsoundness)
|
2024-10-14 16:06:32 -05:00
|
|
|
loop {
|
|
|
|
unsafe { ptr::write_volatile(port_b, 1) };
|
|
|
|
unsafe { ptr::write_volatile(port_b, 2) };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: replace with proper minicore once available (#130693)
|
|
|
|
mod minicore {
|
|
|
|
#[lang = "sized"]
|
|
|
|
pub trait Sized {}
|
|
|
|
|
|
|
|
#[lang = "copy"]
|
|
|
|
pub trait Copy {}
|
|
|
|
impl Copy for u32 {}
|
|
|
|
impl Copy for &u32 {}
|
|
|
|
impl<T: ?Sized> Copy for *mut T {}
|
|
|
|
|
|
|
|
pub mod ptr {
|
|
|
|
#[inline]
|
|
|
|
#[rustc_diagnostic_item = "ptr_write_volatile"]
|
|
|
|
pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
|
|
|
|
extern "rust-intrinsic" {
|
|
|
|
#[rustc_nounwind]
|
|
|
|
pub fn volatile_store<T>(dst: *mut T, val: T);
|
|
|
|
}
|
|
|
|
unsafe { volatile_store(dst, src) };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|