Skip to content

Regression: Inappropriate attribute removal causes incorrect code generation #1284

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

Closed
ppannuto opened this issue Jan 22, 2017 · 0 comments
Closed
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@ppannuto
Copy link

v0.6.3 does not touch this code, v0.7.1 removes only the first instance of #[no_mangle]

The following is a reduced test case that silently (no compile error) broke the kernel. Original file here.

Input

#![crate_name = "sam4l"]
#![crate_type = "rlib"]
#![feature(asm,core_intrinsics,concat_idents,const_fn)]
#![no_std]

#[link_section=".vectors"]
#[no_mangle] // Ensures that the symbol is kept until the final binary
#[cfg_attr(rustfmt, rustfmt_skip)]
pub static BASE_VECTORS: [unsafe extern fn(); 16] = [
    _estack, reset_handler,
    /* NMI */           unhandled_interrupt,
    /* Hard Fault */    hard_fault_handler,
];

#[link_section=".vectors"]
#[no_mangle] // Ensures that the symbol is kept until the final binary
pub static IRQS: [unsafe extern "C" fn(); 80] = [generic_isr; 80];

#[no_mangle]
#[cfg_attr(rustfmt, rustfmt_skip)]
pub static INTERRUPT_TABLE: [Option<unsafe extern fn()>; 80] = [
    /* HFLASHC */       Option::Some(flashcalw::flash_handler),
    /* PDCA0 */         Option::Some(dma::pdca0_handler),
    /* PDCA1 */         Option::Some(dma::pdca1_handler),
];

Output

#![crate_name = "sam4l"]
#![crate_type = "rlib"]
#![feature(asm,core_intrinsics,concat_idents,const_fn)]
#![no_std]

#[link_section=".vectors"]
 // Ensures that the symbol is kept until the final binary
#[cfg_attr(rustfmt, rustfmt_skip)]
pub static BASE_VECTORS: [unsafe extern fn(); 16] = [
    _estack, reset_handler,
    /* NMI */           unhandled_interrupt,
    /* Hard Fault */    hard_fault_handler,
];

#[link_section=".vectors"]
#[no_mangle] // Ensures that the symbol is kept until the final binary
pub static IRQS: [unsafe extern "C" fn(); 80] = [generic_isr; 80];

#[no_mangle]
#[cfg_attr(rustfmt, rustfmt_skip)]
pub static INTERRUPT_TABLE: [Option<unsafe extern fn()>; 80] = [
    /* HFLASHC */       Option::Some(flashcalw::flash_handler),
    /* PDCA0 */         Option::Some(dma::pdca0_handler),
    /* PDCA1 */         Option::Some(dma::pdca1_handler),
];

While the exact line #[no_mangle] // Ensures that the symbol is kept until the final binary appears twice, in the first case it is followed by #[cfg_attr(rustfmt, rustfmt_skip)]. Removing that cfg causes rustfmt to leave the no_mangle alone. Interestingly, the third case also has the skip cfg, but no comment after the no_mangle and is unaffected. Deleting the comment after the first no_mangle also fixes this issue.

@nrc nrc added the bug Panic, non-idempotency, invalid code, etc. label Jan 23, 2017
@nrc nrc closed this as completed in 2261947 Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

2 participants