Skip to content

Array comparisons don't work on AVR - memcmp should return a c_int #144076

@supersurviveur

Description

@supersurviveur

Comparing two arrays when targeting AVR doesn't work as expected :

[0u8; 5] == [0u8; 5]

returns false.

It seems to be the same issue as #78022, memcmp returns an i32 in compiler_builtins while it's an i16 for instance on AVR.

#[mem_builtin]
pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
impls::compare_bytes(s1, s2, n)
}

Meta

rustc --version --verbose:

rustc 1.90.0-nightly (855e0fe46 2025-07-11)
binary: rustc
commit-hash: 855e0fe46e68d94e9f6147531b75ac2d488c548e
commit-date: 2025-07-11
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Metadata

Metadata

Labels

A-ABIArea: Concerning the application binary interface (ABI)C-bugCategory: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-AVRTarget: AVR processors (ATtiny, ATmega, etc.)P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions