Skip to content

Commit

Permalink
Convert to a rmake-test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jfrimmel committed Oct 16, 2024
1 parent db6c736 commit ab00841
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
//@ 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]
#![allow(internal_features)]

#[rustc_builtin_macro]
macro_rules! asm {
Expand All @@ -20,18 +14,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);
Expand Down
28 changes: 28 additions & 0 deletions tests/run-make/avr-rjmp-offset/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@ needs-llvm-components: avr
//! 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");
}

0 comments on commit ab00841

Please sign in to comment.