Skip to content

Commit 8d097cc

Browse files
committed
pybricks/util_mp/pb_obj_helper: add LTO hack to pb_assert_type()
For unknown reasons, GCC 10 LTO is optimizing out pb_assert_type() (presumably because it thinks the function has no side effects as noinline has no effect). The GCC recommended workaround for such issues is to include and empty inline assembly statement to prevent the function from being optimized out. Fixes: pybricks/support#950
1 parent 61e5f24 commit 8d097cc

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
### Fixed
1212
- Fixed `Light` controlling wrong ports on Move hub ([support#913]).
13+
- Fixed type checking optimized out on Move hub ([support#950]).
1314

1415
[support#904]: https://github.com/pybricks/support/issues/904
1516
[support#913]: https://github.com/pybricks/support/issues/913
17+
[support#950]: https://github.com/pybricks/support/issues/950
1618

1719
## [3.2.2] - 2023-01-06
1820

pybricks/util_mp/pb_obj_helper.c

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ mp_obj_t pb_obj_get_base_class_obj(mp_obj_t obj, const mp_obj_type_t *type) {
123123
void pb_assert_type(mp_obj_t obj, const mp_obj_type_t *type) {
124124
if (!mp_obj_is_type(obj, type)) {
125125
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
126+
// HACK: for some reason, GCC 10 LTO optimizes out pb_assert_type()
127+
// in the terse case. By adding an empty inline assembly statement,
128+
// we prevent the incorrect optimization.
129+
__asm__ ("");
126130
mp_raise_TypeError(NULL);
127131
#else
128132
mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("can't convert %s to %s"),

0 commit comments

Comments
 (0)