Skip to content

Commit 1cf0ce0

Browse files
dpgeorgetannewt
authored andcommitted
py/nlr: Use MP_UNREACHABLE at the end of arch-specific nlr_jump funcs.
Recent versions of gcc perform optimisations which can lead to the following code from the MP_NLR_JUMP_HEAD macro being omitted: top->ret_val = val; \ MP_NLR_RESTORE_PYSTACK(top); \ *_top_ptr = top->prev; \ This is noticeable (at least) in the unix coverage on x86-64 built with gcc 9.1.0. This is because the nlr_jump function is marked as no-return, so gcc deduces that the above code has no effect. Adding MP_UNREACHABLE tells the compiler that the asm code may branch elsewhere, and so it cannot optimise away the code.
1 parent 63046d8 commit 1cf0ce0

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

py/nlrx64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ NORETURN void nlr_jump(void *val) {
108108
: // clobbered registers
109109
);
110110

111-
for (;;); // needed to silence compiler warning
111+
MP_UNREACHABLE
112112
}
113113

114114
#endif // MICROPY_NLR_X64

py/nlrx86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ NORETURN void nlr_jump(void *val) {
100100
: // clobbered registers
101101
);
102102

103-
for (;;); // needed to silence compiler warning
103+
MP_UNREACHABLE
104104
}
105105

106106
#endif // MICROPY_NLR_X86

py/nlrxtensa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ NORETURN void nlr_jump(void *val) {
7777
: // clobbered registers
7878
);
7979

80-
for (;;); // needed to silence compiler warning
80+
MP_UNREACHABLE
8181
}
8282

8383
#endif // MICROPY_NLR_XTENSA

0 commit comments

Comments
 (0)