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

every f32 compared to 0 is true #77266

Closed
jsen- opened this issue Sep 27, 2020 · 1 comment
Closed

every f32 compared to 0 is true #77266

jsen- opened this issue Sep 27, 2020 · 1 comment
Labels
C-bug Category: This is a bug. O-AVR Target: AVR processors (ATtiny, ATmega, etc.)

Comments

@jsen-
Copy link
Contributor

jsen- commented Sep 27, 2020

I tried this code:

main.rs

#![no_std]
#![no_main]
#![feature(llvm_asm)]

pub fn black_box<T>(dummy: T) -> T {
    unsafe { llvm_asm!("" : : "r"(&dummy)) }
    dummy
}

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    use arduino_uno::prelude::*;
    let dp = arduino_uno::Peripherals::take().unwrap();
    let mut pins = arduino_uno::Pins::new(dp.PORTB, dp.PORTC, dp.PORTD);
    let mut led = pins.d13.into_output(&mut pins.ddr);
    loop {
        led.toggle().void_unwrap();
        arduino_uno::delay_ms(50);
    }
}

#[arduino_uno::entry]
fn main() -> ! {
    let x = 123.456;
    assert_eq!(x == 0f32, black_box(x) == 0f32);
    loop {}
}

Cargo.toml

[package]
name = "rust-arduino-blink"
version = "0.1.0"
edition = "2018"

[profile.release]
panic = "abort"
opt-level = "z"
lto = true
codegen-units = 1

[dependencies.arduino-uno]
git = "https://github.com/Rahix/avr-hal"
features = ["arduino-nano"]

RUSTFLAGS="-Clink-args=-lc" cargo build --release --target avr-unknown-gnu-atmega328 -Z build-std=core

I expected to see this happen: no blinking

Instead, this happened: blinking :)

Meta

rustc --version --verbose:

rustc 1.48.0-nightly (0da580074 2020-09-22)
binary: rustc
commit-hash: 0da58007451a154da2480160429e1604a1f5f0ec
commit-date: 2020-09-22
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0
Backtrace

``` N/A ```

@jsen- jsen- added the C-bug Category: This is a bug. label Sep 27, 2020
@jonas-schievink
Copy link
Contributor

Thanks for the report! This looks like a duplicate of #77131, however, so closing in favor of that.

Please leave a comment on that issue if you have more information to contribute.

@workingjubilee workingjubilee added the O-AVR Target: AVR processors (ATtiny, ATmega, etc.) label Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-AVR Target: AVR processors (ATtiny, ATmega, etc.)
Projects
None yet
Development

No branches or pull requests

3 participants