Skip to content

Array comparisons don't work on AVRΒ #78022

Closed
@piegamesde

Description

For some reason, comparing to identical arrays does not yield true in all cases.

I tried this code:

#![no_std]
#![no_main]

extern crate panic_halt;
use arduino_uno::prelude::*;

#[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 mut serial = arduino_uno::Serial::new(
		peripherals.USART0,
		pins.d0,
		pins.d1.into_output(&mut pins.ddr),
		57600,
	);

	let a = [ true, true, true, true, true ];
	let b = a;
	ufmt::uwriteln!(&mut serial, "{}\r", a == b).void_unwrap(); // prints false

	let a = [ true, true, true, true ];
	let b = a;
	ufmt::uwriteln!(&mut serial, "{}\r", a == b).void_unwrap(); // prints true
	
	let a = [ 0, 1 ];
	let b = a;
	ufmt::uwriteln!(&mut serial, "{}\r", a == b).void_unwrap(); // prints false

	let a = [ 0 ];
	let b = a;
	ufmt::uwriteln!(&mut serial, "{}\r", a == b).void_unwrap(); // prints true

	loop {}
}

I expected to see this happen: all lines print true

Instead, this happened: some print false. See the code.

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (dd7fc54eb 2020-10-15)
binary: rustc
commit-hash: dd7fc54ebdca419ad9d3ab1e9f5ed14e770768ea
commit-date: 2020-10-15
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0

I am cross compiling for the avr-unknown-unknown target. I did not try any other targets except the host (x86_64-unknown-linux-gnu), on which it does work.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-AVRTarget: AVR processors (ATtiny, ATmega, etc.)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions