Skip to content

Commit 63046d8

Browse files
dpgeorgetannewt
authored andcommitted
py: Introduce MP_UNREACHABLE macro to annotate unreachable code.
And use it to replace the same pattern at the end of nlrthumb.c:nlr_jump.
1 parent 887f64e commit 63046d8

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

py/mpconfig.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,15 @@ typedef double mp_float_t;
14401440
#define MP_UNLIKELY(x) __builtin_expect((x), 0)
14411441
#endif
14421442

1443+
// To annotate that code is unreachable
1444+
#ifndef MP_UNREACHABLE
1445+
#if defined(__GNUC__)
1446+
#define MP_UNREACHABLE __builtin_unreachable();
1447+
#else
1448+
#define MP_UNREACHABLE for (;;);
1449+
#endif
1450+
#endif
1451+
14431452
#ifndef MP_HTOBE16
14441453
#if MP_ENDIANNESS_LITTLE
14451454
# define MP_HTOBE16(x) ((uint16_t)( (((x) & 0xff) << 8) | (((x) >> 8) & 0xff) ))

py/nlrthumb.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ NORETURN void nlr_jump(void *val) {
127127
: // clobbered registers
128128
);
129129

130-
#if defined(__GNUC__)
131-
__builtin_unreachable();
132-
#else
133-
for (;;); // needed to silence compiler warning
134-
#endif
130+
MP_UNREACHABLE
135131
}
136132

137133
#endif // MICROPY_NLR_THUMB

0 commit comments

Comments
 (0)