Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

gccrs#4587: Enforce intrinsic signatures during the type checking

Link: Rust-GCC/gccrs#4587

Objective

This PR enforces signature validation for intrinsic functions during the type-checking phase rather than failing later during code generation.

Changes Made

Added a validation hook that intercepts extern "rust-intrinsic" function declarations. It strictly checks the argument types and argument counts against the expected compiler definitions.

Why is this needed for alloc?

While not strictly required only for alloc, this patch is crucial for development stability. Implementing the alloc crate requires adding numerous new intrinsics; failing early at the type-check phase prevents cryptic backend crashes (ICEs) when an intrinsic signature is mismatched.

Test Case

#![allow(unused)]
fn main() {
extern "rust-intrinsic" {
    // this will cause an error -> unrecognized intrinsic function: 'foo'
    fn foo();

    fn size_of<T, U>() -> usize;

    fn offset<T>(dst: usize, offset: isize) -> *const T;
}
}

The compiler now correctly emits user-friendly errors during the frontend type-checking pass instead of letting invalid signatures reach the backend.