Skip to content

Commit f0cca6e

Browse files
committed
avr: Provide abort()
1 parent 8ee1aa9 commit f0cca6e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

compiler-builtins/src/avr.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
intrinsics! {
2+
pub unsafe extern "C" fn abort() -> ! {
3+
// On AVRs, an architecture that doesn't support traps, unreachable code
4+
// paths get lowered into calls to `abort`:
5+
//
6+
// https://github.com/llvm/llvm-project/blob/cbe8f3ad7621e402b050e768f400ff0d19c3aedd/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp#L4462
7+
//
8+
// When control gets here, it means an undefined behavior has occurred, so
9+
// there's really not that much we can do to recover - we can't reliably
10+
// `panic!()`, because for all we know the environment is gone, so panicking
11+
// might end up with us getting back to this very function.
12+
//
13+
// So let's do the next best thing, loop.
14+
//
15+
// Alternatively we could (try to) restart the program, but since undefined
16+
// behavior is undefined, there's really no obligation for us to do anything
17+
// here - for all we care, we could just set the chip on fire; but that'd be
18+
// bad for the environment.
19+
20+
loop {}
21+
}
22+
}

compiler-builtins/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ pub mod aarch64_linux;
6363
))]
6464
pub mod arm_linux;
6565

66+
#[cfg(target_arch = "avr")]
67+
pub mod avr;
68+
6669
#[cfg(target_arch = "hexagon")]
6770
pub mod hexagon;
6871

0 commit comments

Comments
 (0)