From bf794c05b1b1e5ab5ff2fbec427672ebe629af23 Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Tue, 15 Oct 2024 20:46:23 +0200 Subject: [PATCH] Convert to a `rmake`-test Since the `tests/assembly` use `emit=asm`, the issue is not observable as reported in the linked issue. Therefore the existing test case is converted and a simple `rmake`-test is added. The test only checks, if the correct `rjmp`-offset is used. --- .../avr-rjmp-offset}/avr-rjmp-offsets.rs | 34 ++++++------------- tests/run-make/avr-rjmp-offset/rmake.rs | 27 +++++++++++++++ 2 files changed, 38 insertions(+), 23 deletions(-) rename tests/{assembly => run-make/avr-rjmp-offset}/avr-rjmp-offsets.rs (64%) create mode 100644 tests/run-make/avr-rjmp-offset/rmake.rs diff --git a/tests/assembly/avr-rjmp-offsets.rs b/tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs similarity index 64% rename from tests/assembly/avr-rjmp-offsets.rs rename to tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs index 0acf54fada46a..a73fdd5e2d82d 100644 --- a/tests/assembly/avr-rjmp-offsets.rs +++ b/tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs @@ -1,17 +1,10 @@ -//@ compile-flags: -Copt-level=s --target=avr-unknown-gnu-atmega328 -C panic=abort -//@ needs-llvm-components: avr -//@ assembly-output: emit-asm - -#![feature( - no_core, - lang_items, - intrinsics, - rustc_attrs, - arbitrary_self_types, - asm_experimental_arch -)] -#![crate_type = "rlib"] +//! This test case is a `#![no_core]`-version of the MVCE presented in #129301. +//! +//! The function [`delay()`] is minimized and does not actually contain a loop +//! in order to remove the need for additional lang items. +#![feature(no_core, lang_items, intrinsics, rustc_attrs, asm_experimental_arch)] #![no_core] +#![no_main] #[rustc_builtin_macro] macro_rules! asm { @@ -20,18 +13,13 @@ macro_rules! asm { use minicore::ptr; -// CHECK-LABEL: pin_toggling -// CHECK: ldi [[REG_1:r[0-9]+]], 1 -// CHECK: ldi [[REG_2:r[0-9]+]], 2 -// CHECK: .LBB0_1: -// CHECK-NEXT: out 5, [[REG_1]] -// CHECK-NEXT: call delay -// CHECK-NEXT: out 5, [[REG_2]] -// CHECK-NEXT: call delay -// CHECK-NEXT: rjmp .LBB0_1 #[no_mangle] -pub fn pin_toggling() { +pub fn main() -> ! { let port_b = 0x25 as *mut u8; // the I/O-address of PORTB + + // 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) loop { unsafe { ptr::write_volatile(port_b, 1) }; delay(500_0000); diff --git a/tests/run-make/avr-rjmp-offset/rmake.rs b/tests/run-make/avr-rjmp-offset/rmake.rs new file mode 100644 index 0000000000000..bc59efed918db --- /dev/null +++ b/tests/run-make/avr-rjmp-offset/rmake.rs @@ -0,0 +1,27 @@ +//! Regression test for #129301/llvm-project#106722 within `rustc`. +//! +//! Some LLVM-versions had wrong offsets in the local labels, causing the first +//! loop instruction to be missed. This test therefore contains a simple loop +//! with trivial instructions in it, to see, where the label is placed. +//! +//! This must be a `rmake`-test and cannot be a `tests/assembly`-test, since the +//! wrong output is only produced with direct assembly generation, but not when +//! "emit-asm" is used, as described in the issue description of #129301: +//! https://github.com/rust-lang/rust/issues/129301#issue-2475070770 +use run_make_support::{llvm_objdump, rustc}; + +fn main() { + rustc() + .input("avr-rjmp-offsets.rs") + .opt_level("s") + .panic("abort") + .target("avr-unknown-gnu-atmega328") + .output("compiled") + .run(); + + llvm_objdump() + .disassemble() + .input("compiled") + .run() + .assert_stdout_contains_regex(r"rjmp.*\.-14"); +}