diff options
| author | Damien George <damien.p.george@gmail.com> | 2017-12-28 15:59:09 +1100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2017-12-28 15:59:09 +1100 |
| commit | 97cc48553828ed091325d0d3922eb4cd6c377221 (patch) | |
| tree | 7b18bfc22a7cdcb5f4f9aa4de41a23c9e4feb757 | |
| parent | 7a9a73ee8466111f73a7de7d27568c1260d802ef (diff) | |
py/nlrthumb: Fix use of naked funcs, must only contain basic asm code.
A function with a naked attribute must only contain basic inline asm
statements and no C code.
For nlr_push this means removing the "return 0" statement. But for some
gcc versions this induces a compiler warning so the __builtin_unreachable()
line needs to be added.
For nlr_jump, this function contains a combination of C code and inline asm
so cannot be naked.
| -rw-r--r-- | py/nlrthumb.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/py/nlrthumb.c b/py/nlrthumb.c index eab5759f2..18d31eb70 100644 --- a/py/nlrthumb.c +++ b/py/nlrthumb.c @@ -76,7 +76,10 @@ __attribute__((naked)) unsigned int nlr_push(nlr_buf_t *nlr) { #endif ); - return 0; // needed to silence compiler warning + #if defined(__GNUC__) + // Older versions of gcc give an error when naked functions don't return a value + __builtin_unreachable(); + #endif } __attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr) { @@ -92,7 +95,7 @@ void nlr_pop(void) { *top = (*top)->prev; } -NORETURN __attribute__((naked)) void nlr_jump(void *val) { +NORETURN void nlr_jump(void *val) { nlr_buf_t **top_ptr = &MP_STATE_THREAD(nlr_top); nlr_buf_t *top = *top_ptr; if (top == NULL) { @@ -138,7 +141,11 @@ NORETURN __attribute__((naked)) void nlr_jump(void *val) { : // clobbered registers ); + #if defined(__GNUC__) + __builtin_unreachable(); + #else for (;;); // needed to silence compiler warning + #endif } #endif // (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__)) |
