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.
This commit is contained in:
Damien George 2017-12-28 15:59:09 +11:00
parent 7a9a73ee84
commit 97cc485538
1 changed files with 9 additions and 2 deletions

View File

@ -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__))