From 557a51ede11b39acd37dcadb5bd3e12c4e7e7b28 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 12 Feb 2019 11:07:15 +0100 Subject: forbid early returns in init --- tests/cfail/early-return-2.rs | 29 +++++++++++++++++++++++++++++ tests/cfail/early-return.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/cfail/early-return-2.rs create mode 100644 tests/cfail/early-return.rs (limited to 'tests') diff --git a/tests/cfail/early-return-2.rs b/tests/cfail/early-return-2.rs new file mode 100644 index 0000000..bf867e0 --- /dev/null +++ b/tests/cfail/early-return-2.rs @@ -0,0 +1,29 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + static mut UNINITIALIZED: bool = (); + + #[init] + fn init() { + if false { + return; //~ ERROR `init` is *not* allowed to early return + } + + UNINITIALIZED = true; + } + + #[interrupt(resources = [UNINITIALIZED])] + fn UART0() { + if resources.UNINITIALIZED { + // UB + } + } +}; diff --git a/tests/cfail/early-return.rs b/tests/cfail/early-return.rs new file mode 100644 index 0000000..fb695aa --- /dev/null +++ b/tests/cfail/early-return.rs @@ -0,0 +1,32 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + static mut UNINITIALIZED: bool = (); + + #[init] + fn init() { + let x = || { + // this is OK + return 0; + }; + + return; //~ ERROR `init` is *not* allowed to early return + + UNINITIALIZED = true; + } + + #[interrupt(resources = [UNINITIALIZED])] + fn UART0() { + if resources.UNINITIALIZED { + // UB + } + } +}; -- cgit v1.2.3 From 89c922079eaefc748febdb62aeccfff598a07c69 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 12 Feb 2019 15:08:46 +0100 Subject: update examples and tests --- tests/cfail/init-divergent.rs | 2 +- tests/cfail/init-input.rs | 2 +- tests/cfail/init-output.rs | 2 +- tests/cfail/late-not-send.rs | 6 ++++-- tests/cfail/late-uninit.rs | 2 ++ tests/cpass/late-not-send.rs | 6 ++++-- tests/cpass/late-resource.rs | 5 ++--- 7 files changed, 15 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/cfail/init-divergent.rs b/tests/cfail/init-divergent.rs index 400c805..54813d4 100644 --- a/tests/cfail/init-divergent.rs +++ b/tests/cfail/init-divergent.rs @@ -11,7 +11,7 @@ use rtfm::app; const APP: () = { #[init] fn init() -> ! { - //~^ ERROR `init` must have type signature `[unsafe] fn()` + //~^ ERROR `init` must have type signature `[unsafe] fn() [-> init::LateResources]` loop {} } }; diff --git a/tests/cfail/init-input.rs b/tests/cfail/init-input.rs index fa79099..3bf0cad 100644 --- a/tests/cfail/init-input.rs +++ b/tests/cfail/init-input.rs @@ -11,6 +11,6 @@ use rtfm::app; const APP: () = { #[init] fn init(undef: u32) { - //~^ ERROR `init` must have type signature `[unsafe] fn()` + //~^ ERROR `init` must have type signature `[unsafe] fn() [-> init::LateResources]` } }; diff --git a/tests/cfail/init-output.rs b/tests/cfail/init-output.rs index 1200aca..414a35a 100644 --- a/tests/cfail/init-output.rs +++ b/tests/cfail/init-output.rs @@ -11,7 +11,7 @@ use rtfm::app; const APP: () = { #[init] fn init() -> u32 { - //~^ ERROR `init` must have type signature `[unsafe] fn()` + //~^ ERROR `init` must have type signature `[unsafe] fn() [-> init::LateResources]` 0 } }; diff --git a/tests/cfail/late-not-send.rs b/tests/cfail/late-not-send.rs index b9180fe..eb3048d 100644 --- a/tests/cfail/late-not-send.rs +++ b/tests/cfail/late-not-send.rs @@ -22,8 +22,10 @@ const APP: () = { static mut X: NotSend = (); #[init] - fn init() { - X = NotSend { _0: PhantomData }; + fn init() -> init::LateResources { + init::LateResources { + X: NotSend { _0: PhantomData }, + } } #[interrupt(resources = [X])] diff --git a/tests/cfail/late-uninit.rs b/tests/cfail/late-uninit.rs index eeb9bd4..55122ed 100644 --- a/tests/cfail/late-uninit.rs +++ b/tests/cfail/late-uninit.rs @@ -1,3 +1,5 @@ +// TODO remove in v0.5.x + #![no_main] #![no_std] diff --git a/tests/cpass/late-not-send.rs b/tests/cpass/late-not-send.rs index 06d376b..5b278ab 100644 --- a/tests/cpass/late-not-send.rs +++ b/tests/cpass/late-not-send.rs @@ -19,10 +19,12 @@ const APP: () = { static mut Y: Option = None; #[init(resources = [Y])] - fn init() { + fn init() -> init::LateResources { *resources.Y = Some(NotSend { _0: PhantomData }); - X = NotSend { _0: PhantomData }; + init::LateResources { + X: NotSend { _0: PhantomData }, + } } #[idle(resources = [X, Y])] diff --git a/tests/cpass/late-resource.rs b/tests/cpass/late-resource.rs index 94ec8c9..0dec4cb 100644 --- a/tests/cpass/late-resource.rs +++ b/tests/cpass/late-resource.rs @@ -14,8 +14,7 @@ const APP: () = { static Y: u32 = (); #[init] - fn init() { - X = 0; - Y = 1; + fn init() -> init::LateResources { + init::LateResources { X: 0, Y: 1 } } }; -- cgit v1.2.3