Skip to content

Commit 55b0f15

Browse files
committed
Mark functions as NORETURN
Surprisingly this leads to some code size savings on itsybitsym4, even though LTO optimization should have let the compiler deduce (almost) all of this. When a compiler knows a call can never return, it is possibly able to avoid emitting code, such as saving caller-saved registers to the stack, or doing _ANYTHING_ affter the function returns, explaining why code size savings is possible with this attribute. With the exception of raise_deinited_error, these were found by checking the functions found by `-Wmissing-noreturn` and making a case by case decision. However, this dignostic can't be enabled unconditionally as it has false positives, functions we do NOT want to mark as noreturn. Testing performed: built itsybitsy m4, flash size savings 128 bytes. didn't test on hardware as none came on this trip with me.
1 parent 8f7496c commit 55b0f15

File tree

7 files changed

+7
-7
lines changed

7 files changed

+7
-7
lines changed

ports/atmel-samd/common-hal/alarm/touch/TouchAlarm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
#include "shared-bindings/alarm/touch/TouchAlarm.h"
88
#include "shared-bindings/microcontroller/__init__.h"
99

10-
void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *self, const mcu_pin_obj_t *pin) {
10+
NORETURN void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *self, const mcu_pin_obj_t *pin) {
1111
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_TouchAlarm);
1212
}

ports/atmel-samd/supervisor/port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ void port_idle_until_interrupt(void) {
686686
/**
687687
* \brief Default interrupt handler for unused IRQs.
688688
*/
689-
__attribute__((used)) void HardFault_Handler(void) {
689+
__attribute__((used)) NORETURN void HardFault_Handler(void) {
690690
#ifdef ENABLE_MICRO_TRACE_BUFFER
691691
// Turn off the micro trace buffer so we don't fill it up in the infinite
692692
// loop below.

shared-bindings/alarm/time/TimeAlarm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "shared-bindings/time/__init__.h"
1515

1616
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
17-
mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
17+
NORETURN mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
1818
mp_raise_RuntimeError(MP_ERROR_TEXT("RTC is not supported on this board"));
1919
}
2020
#endif

shared-bindings/microcontroller/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern void common_hal_mcu_disable_interrupts(void);
2020
extern void common_hal_mcu_enable_interrupts(void);
2121

2222
extern void common_hal_mcu_on_next_reset(mcu_runmode_t runmode);
23-
extern void common_hal_mcu_reset(void);
23+
NORETURN extern void common_hal_mcu_reset(void);
2424

2525
extern const mp_obj_dict_t mcu_pin_globals;
2626

shared-bindings/storage/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void common_hal_storage_umount_path(const char *path);
1616
void common_hal_storage_umount_object(mp_obj_t vfs_obj);
1717
void common_hal_storage_remount(const char *path, bool readonly, bool disable_concurrent_write_protection);
1818
mp_obj_t common_hal_storage_getmount(const char *path);
19-
void common_hal_storage_erase_filesystem(bool extended);
19+
NORETURN void common_hal_storage_erase_filesystem(bool extended);
2020

2121
bool common_hal_storage_disable_usb_drive(void);
2222
bool common_hal_storage_enable_usb_drive(void);

shared-bindings/time/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(time_not_implemented_obj, time_not_implemented);
172172
#endif
173173

174174
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
175-
mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
175+
NORETURN mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
176176
mp_raise_RuntimeError(MP_ERROR_TEXT("RTC is not supported on this board"));
177177
}
178178

shared-bindings/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
#include "py/mpprint.h"
1010
#include "py/runtime.h"
1111

12-
void raise_deinited_error(void);
12+
NORETURN void raise_deinited_error(void);
1313
void properties_print_helper(const mp_print_t *print, mp_obj_t self_in, const mp_arg_t *properties, size_t n_properties);
1414
void properties_construct_helper(mp_obj_t self_in, const mp_arg_t *args, const mp_arg_val_t *vals, size_t n_properties);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy