8000 py/nlrthumb: Fix use of naked funcs, must only contain basic asm code. · neverhover/micropython@97cc485 · GitHub
[go: up one dir, main page]

Skip to content

Commit 97cc485

Browse files
committed
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.
1 parent 7a9a73e commit 97cc485

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

py/nlrthumb.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ __attribute__((naked)) unsigned int nlr_push(nlr_buf_t *nlr) {
7676
#endif
7777
);
7878

79-
return 0; // needed to silence compiler warning
79+
#if defined(__GNUC__)
80+
// Older versions of gcc give an error when naked functions don't return a value
81+
__builtin_unreachable();
82+
#endif
8083
}
8184

8285
__attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr) {
@@ -92,7 +95,7 @@ void nlr_pop(void) {
9295
*top = (*top)->prev;
9396
}
9497

95-
NORETURN __attribute__((naked)) void nlr_jump(void *val) {
98+
NORETURN void nlr_jump(void *val) {
9699
nlr_buf_t **top_ptr = &MP_STATE_THREAD(nlr_top);
97100
nlr_buf_t *top = *top_ptr;
98101
if (top == NULL) {
@@ -138,7 +141,11 @@ NORETURN __attribute__((naked)) void nlr_jump(void *val) {
138141
: // clobbered registers
139142
);
140143

144+
#if defined(__GNUC__)
145+
__builtin_unreachable();
146+
#else
141147
for (;;); // needed to silence compiler warning
148+
#endif
142149
}
143150

144151
#endif // (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))

0 commit comments

Comments
 (0)
0