Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Merge #242
Browse files Browse the repository at this point in the history
242: Backport lint fixes and test to 0.6.x r=adamgreig a=jonas-schievink

Closes #240

Co-authored-by: Emil Fresk <[email protected]>
Co-authored-by: Jonas Schievink <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2020
2 parents 5b4ece5 + 00d300b commit 17ea2ee
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 6 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [v0.6.12] - 2020-01-26

### Fixed

- Fixed lint warnings getting emitted on macro-generated code.

## [v0.6.11] - 2019-12-04

### Changed

- Macros now generate a second trampoline function instead of randomizing the
Expand Down Expand Up @@ -466,7 +474,9 @@ section size addr

Initial release

[Unreleased]: https://github.com/rust-embedded/cortex-m-rt/compare/v0.6.10...HEAD
[Unreleased]: https://github.com/rust-embedded/cortex-m-rt/compare/v0.6.12...HEAD
[v0.6.12]: https://github.com/rust-embedded/cortex-m-rt/compare/v0.6.11...v0.6.12
[v0.6.11]: https://github.com/rust-embedded/cortex-m-rt/compare/v0.6.10...v0.6.11
[v0.6.10]: https://github.com/rust-embedded/cortex-m-rt/compare/v0.6.9...v0.6.10
[v0.6.9]: https://github.com/rust-embedded/cortex-m-rt/compare/v0.6.8...v0.6.9
[v0.6.8]: https://github.com/rust-embedded/cortex-m-rt/compare/v0.6.7...v0.6.8
Expand Down
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ license = "MIT OR Apache-2.0"
name = "cortex-m-rt"
readme = "README.md"
repository = "https://github.com/rust-embedded/cortex-m-rt"
version = "0.6.11"
version = "0.6.12"
autoexamples = true

[dependencies]
r0 = "0.2.2"
cortex-m-rt-macros = { path = "macros", version = "0.1" }
cortex-m-rt-macros = { path = "macros", version = "=0.1.8" }

[dev-dependencies]
cortex-m = "0.6"
Expand All @@ -31,6 +31,10 @@ compiletest_rs = "0.4.0"
name = "device"
required-features = ["device"]

[[example]]
name = "warnings"
required-features = ["device"]

[[test]]
name = "compiletest"
required-features = ["device"]
Expand Down
50 changes: 50 additions & 0 deletions examples/warnings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Tests that a crate can still build with all warnings enabled.
//!
//! The code generated by the `cortex-m-rt` macros might need to manually
//! `#[allow]` some of them (even though Rust does that by default for a few
//! warnings too).

#![no_std]
#![no_main]
#![deny(warnings, missing_docs, rust_2018_idioms)]

extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m_rt::{entry, exception, interrupt, pre_init, ExceptionFrame};

#[allow(non_camel_case_types)]
enum interrupt {
INT,
}

extern "C" {
fn INT();
}

union Vector {
#[allow(dead_code)]
handler: unsafe extern "C" fn(),
}

#[link_section = ".vector_table.interrupts"]
#[no_mangle]
#[used]
static __INTERRUPTS: [Vector; 1] = [Vector { handler: INT }];

/// Dummy interrupt.
#[interrupt]
fn INT() {}

#[exception]
fn HardFault(_eh: &ExceptionFrame) -> ! {
loop {}
}

#[entry]
fn main() -> ! {
loop {}
}

#[pre_init]
unsafe fn pre_init() {}
2 changes: 1 addition & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["arm", "cortex-m", "runtime", "startup"]
license = "MIT OR Apache-2.0"
name = "cortex-m-rt-macros"
repository = "https://github.com/japaric/cortex-m-rt"
version = "0.1.7"
version = "0.1.8"
edition = "2018"

[lib]
Expand Down
6 changes: 6 additions & 0 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
.collect::<Vec<_>>();

quote!(
#[doc(hidden)]
#[export_name = "main"]
pub unsafe extern "C" fn #tramp_ident() {
#ident(
Expand Down Expand Up @@ -343,6 +344,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
let ident = &f.sig.ident;

quote!(
#[doc(hidden)]
#[export_name = #ident_s]
pub unsafe extern "C" fn #tramp_ident() {
extern crate core;
Expand Down Expand Up @@ -395,6 +397,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
let ident = &f.sig.ident;

quote!(
#[doc(hidden)]
#[export_name = "HardFault"]
#[link_section = ".HardFault.user"]
pub unsafe extern "C" fn #tramp_ident(frame: &::cortex_m_rt::ExceptionFrame) {
Expand Down Expand Up @@ -481,6 +484,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
.collect::<Vec<_>>();

quote!(
#[doc(hidden)]
#[export_name = #ident_s]
pub unsafe extern "C" fn #tramp_ident() {
#ident(
Expand Down Expand Up @@ -651,6 +655,7 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream {
.collect::<Vec<_>>();

quote!(
#[doc(hidden)]
#[export_name = #ident_s]
pub unsafe extern "C" fn #tramp_ident() {
#ident(
Expand Down Expand Up @@ -730,6 +735,7 @@ pub fn pre_init(args: TokenStream, input: TokenStream) -> TokenStream {

quote!(
#[export_name = "__pre_init"]
#[allow(missing_docs)] // we make a private fn public, which can trigger this lint
#(#attrs)*
pub unsafe fn #ident() #block
)
Expand Down
2 changes: 1 addition & 1 deletion tests/compile-fail/exception-soundness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ fn SysTick() {
#[exception]
fn SVCall() {
// If this was allowed it would lead to a data race as `SVCall` could preempt `SysTick`
SysTick(); //~ ERROR cannot find function `SysTick` in this scope
SysTick(); //~ ERROR cannot find function, tuple struct or tuple variant `SysTick` in this scope [E0425]
}
2 changes: 1 addition & 1 deletion tests/compile-fail/interrupt-soundness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ fn USART1() {

#[interrupt]
fn USART2() {
USART1(); //~ ERROR cannot find function `USART1` in this scope
USART1(); //~ ERROR cannot find function, tuple struct or tuple variant `USART1` in this scope [E0425]
}

0 comments on commit 17ea2ee

Please sign in to comment.