Skip to content

Regression test for AVR rjmp offset #131755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
jfrimmel committed Oct 16, 2024
commit ab008414d4b4919c1344ef0d542fc9b0d354a505
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");
}