[PATCH] D114611: [AVR] Expand STDWSPQRr & STDSPQRr, approach #2
Patryk Wychowaniec via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 17 11:52:26 PST 2021
Patryk27 added a comment.
So I think //something// this patch does is not right - I'm not sure how to prepare a minimized, llvm-only example, but if you try to run this code:
#![no_std]
#![no_main]
#![feature(bench_black_box)]
use atmega_hal::{pins, usart::Usart0, Peripherals};
use core::hint::black_box;
use panic_halt as _;
use ufmt::*;
use void::{ResultVoidExt, Void};
pub type Clock = atmega_hal::clock::MHz20;
#[atmega_hal::entry]
fn main() -> ! {
let dp = Peripherals::take().unwrap();
let pins = pins!(dp);
let mut serial =
Usart0::<Clock>::new(dp.USART0, pins.pd0, pins.pd1.into_output(), 115200.into());
fun(&mut serial, 23, 23);
fun(&mut serial, 24, 24);
fun(&mut serial, 25, 25); // commenting-out this line makes the code work
loop {}
}
#[inline(never)]
fn fun(serial: &mut dyn uWrite<Error = Void>, x: u32, y: u32) {
let _ = black_box(serial);
let _ = black_box(x / y);
}
[dependencies]
atmega-hal = { git = "https://github.com/Rahix/avr-hal", features = ["atmega328p", "rt"] }
embedded-hal = "0.2"
panic-halt = "0.2"
ufmt = "0.1"
void = { version = "1", default-features = false }
[profile.release]
panic = "abort"
codegen-units = 1
opt-level = 1
lto = false
... you'll see that the `25 / 25` division triggers what seems to be a CPU reset, and in reality is caused by a `ret` on a corrupted stack frame.
I've managed to nail the problem down to a miscompilation in `__udivmodsi4` (https://github.com/rust-lang/rust/issues/82242#issuecomment-996805546), as if the `ldd` instructions before `st` / `std` were removed (?), but I'm not sure how to investigate it further 😅
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114611/new/
https://reviews.llvm.org/D114611
More information about the llvm-commits
mailing list