Skip to content
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

SIGSEGV in rust nightly 2021-01-07 (rustc 1.51.0-nightly) #83633

Closed
vlisivka opened this issue Mar 29, 2021 · 0 comments · Fixed by #96845
Closed

SIGSEGV in rust nightly 2021-01-07 (rustc 1.51.0-nightly) #83633

vlisivka opened this issue Mar 29, 2021 · 0 comments · Fixed by #96845
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-AVR Target: AVR processors (ATtiny, ATmega, etc.) requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@vlisivka
Copy link

vlisivka commented Mar 29, 2021

Code for AVR target. Code compiled on Fedora 33. Code reduced by comby-reducer.

rapt-reduced.tar.gz

Program requires nightly 2021-01-07. I cannot use newer version of rustc to check, because of unrelated bug in llvm for AVR target(LLVM ERROR: Not supported instr: <MCInst 296 <MCOperand Reg:1> <MCOperand Imm:15> <MCOperand Reg:39>).

Code

#![no_std]
#![no_main]
use arduino_uno::prelude::*;
use arduino_uno::Serial;
use atmega328p_hal::port::mode;
use atmega328p_hal::port::Pin;
use avr_hal_generic::usart::{Usart, UsartOps};
use avr_std_stub as _;
mod line_buffer;
use line_buffer::LineBuffer;
mod atoi;
use atoi::atoi_u8;
const MAX_BUF_LEN: usize = 128;
static mut LINE_BUFFER: [u8; MAX_BUF_LEN] = [0; MAX_BUF_LEN];
enum PinState {
    InputFloating(Pin<mode::Input<mode::Floating>>),
    InputAnalog(Pin<mode::Input<mode::PullUp>>),
    Output(Pin<mode::Output>),
    TriState(Pin<mode::TriState>),
}
fn error<USART, PD0, PD1, CLOCK>(serial: &mut Usart<USART, PD0, PD1, CLOCK>, message: &str) where    USART: UsartOps<PD0, PD1>, {}
#[arduino_uno::entry]
fn main() -> ! {
    let peripherals = arduino_uno::Peripherals::take().unwrap();
    let mut pins = arduino_uno::Pins::new(peripherals.PORTB, peripherals.PORTC, peripherals.PORTD);
    let serial_rx = pins.d0;
    let serial_tx = pins.d1.into_output(&mut pins.ddr);
    let mut serial = Serial::new(peripherals.USART0, serial_rx, serial_tx, 115200.into_baudrate());
    let mut line_buffer = unsafe { LineBuffer::new(&mut LINE_BUFFER) };
    let mut pin_state = [
        PinState::TriState(pins.d3.into_tri_state(&pins.ddr).downgrade()),
        PinState::TriState(pins.d4.into_tri_state(&pins.ddr).downgrade()),
        PinState::TriState(pins.d5.into_tri_state(&pins.ddr).downgrade()),
        PinState::TriState(pins.d6.into_tri_state(&pins.ddr).downgrade()),
        PinState::TriState(pins.d7.into_tri_state(&pins.ddr).downgrade()),
        PinState::TriState(pins.d8.into_tri_state(&pins.ddr).downgrade()),
        PinState::TriState(pins.d9.into_tri_state(&pins.ddr).downgrade()),
        PinState::TriState(pins.d10.into_tri_state(&pins.ddr).downgrade()),
        PinState::TriState(pins.d11.into_tri_state(&pins.ddr).downgrade()),
        PinState::TriState(pins.d12.into_tri_state(&pins.ddr).downgrade()),
        PinState::TriState(pins.d13.into_tri_state(&pins.ddr).downgrade()),
    ];
    loop {
        ufmt::uwrite!(&mut serial, "\x1B[1mrapt>\x1B[0m ").void_unwrap();
        if line_buffer.read_line(&mut serial) > 0 {
            for command in line_buffer.words() {
                match command {
                    [b'r', tail @ ..] => {
                        match atoi_u8(tail) {
                            Some(pin_number) if (pin_number as usize) < pin_state.len() => {
                                match &pin_state[pin_number as usize] {
                                    PinState::InputFloating(pin) => {
                                        ufmt::uwrite!(serial, "p{}={}\r\n", pin_number, pin.is_high().unwrap()).void_unwrap();
                                    }
                                    PinState::InputAnalog(pin) => {
                                        ufmt::uwrite!(serial, "p{}={}\r\n", pin_number, pin.is_high().unwrap() ).void_unwrap();
                                    }
                                    PinState::TriState(pin) => {
                                        ufmt::uwrite!(serial, "p{}={}\r\n", pin_number, pin.is_high().unwrap()).void_unwrap();
                                    }
                                    _ => {}
                                }
                            }
                            _ => {}
                        }
                    }
                    [b'w', tail @ .., val] => {
                        match atoi_u8(tail) {
                            Some(pin_number) if (pin_number as usize) < pin_state.len() => {
                                match &mut pin_state[pin_number as usize] {
                                    PinState::Output(ref mut pin) => {
                                        let v = match val {
                                            b'l' | b'L' => false,
                                            b'h' | b'H' =>true,
                                            _ => {
                                                continue;
                                            }
                                        };
                                        ufmt::uwrite!(serial, "p{}={}\r\n", pin_number, v).void_unwrap();
                                    }
                                    PinState::TriState(ref mut pin) => {
                                        let v = match val {
                                            b'l' | b'L' => {
                                                pin.set_low().expect("");
                                                false
                                            }
                                            b'h' | b'H' => {
                                                pin.set_high().expect("");
                                                true
                                            }
                                            _ => {
                                                continue;
                                            }
                                        };
                                        ufmt::uwrite!(serial, "p{}={}\r\n", pin_number, v).void_unwrap();
                                    }
                                    _ => {}
                                }
                            }
                            _ => {}
                        }
                    }
                    _ => error(&mut serial, ""),
                }
            }
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (c2de47a9a 2021-01-06)
binary: rustc
commit-hash: c2de47a9aa4c9812884f341f1852e9c9610f5f7a
commit-date: 2021-01-06
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly

Error output

  process didn't exit successfully: `rustc --crate-name rapt --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=s -C panic=abort -C lto -C codegen-units=1 -C debuginfo=2 -C metadata=874b614425088d6c -C extra-filename=-874b614425088d6c --out-dir /home/vlisivka/workspace/rapt/target/avr-atmega328p/release/deps --target /home/vlisivka/workspace/rapt/avr-atmega328p.json -L dependency=/home/vlisivka/workspace/rapt/target/avr-atmega328p/release/deps -L dependency=/home/vlisivka/workspace/rapt/target/release/deps --extern arduino_uno=/home/vlisivka/workspace/rapt/target/avr-atmega328p/release/deps/libarduino_uno-2a2559e92b4f8b94.rlib --extern atmega328p_hal=/home/vlisivka/workspace/rapt/target/avr-atmega328p/release/deps/libatmega328p_hal-9252c4cc0359dc4c.rlib --extern avr_hal_generic=/home/vlisivka/workspace/rapt/target/avr-atmega328p/release/deps/libavr_hal_generic-8b1481097f48b6ab.rlib --extern avr_std_stub=/home/vlisivka/workspace/rapt/target/avr-atmega328p/release/deps/libavr_std_stub-9b4b6bb91705909d.rlib --extern 'noprelude:compiler_builtins=/home/vlisivka/workspace/rapt/target/avr-atmega328p/release/deps/libcompiler_builtins-6ac0a51c4b9ecfe7.rlib' --extern 'noprelude:core=/home/vlisivka/workspace/rapt/target/avr-atmega328p/release/deps/libcore-627006de141c21fe.rlib' --extern nb=/home/vlisivka/workspace/rapt/target/avr-atmega328p/release/deps/libnb-949e9a646194f61f.rlib --extern ufmt=/home/vlisivka/workspace/rapt/target/avr-atmega328p/release/deps/libufmt-e2008be75bc74481.rlib -Z unstable-options` (signal: 11, SIGSEGV: invalid memory reference)

Backtrace

<backtrace>

@vlisivka vlisivka added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 29, 2021
@JohnTitor JohnTitor added O-AVR Target: AVR processors (ATtiny, ATmega, etc.) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. labels Mar 29, 2021
@jonas-schievink jonas-schievink added the requires-nightly This issue requires a nightly compiler in some way. label Mar 29, 2021
@bors bors closed this as completed in 0e345b7 May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-AVR Target: AVR processors (ATtiny, ATmega, etc.) requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants