New intrinsic "unreachable()" to indicate unreachable code points

This allows better compiler optimisation, while also including an
ASSERT() for debug builds.

Refs #7
This commit is contained in:
Keir Fraser
2024-11-03 10:26:15 +00:00
parent c839984a5f
commit 45821dee07
4 changed files with 7 additions and 7 deletions

View File

@@ -27,6 +27,8 @@ struct exception_frame {
#define likely(x) __builtin_expect(!!(x),1)
#define unlikely(x) __builtin_expect(!!(x),0)
#define unreachable() do { ASSERT(0); __builtin_unreachable(); } while (0)
#define illegal() asm volatile (".short 0xde00");
#define barrier() asm volatile ("" ::: "memory")

View File

@@ -26,8 +26,7 @@ GPIO gpio_from_id(uint8_t id)
case _I: return gpioi;
#endif
}
ASSERT(0);
return NULL;
unreachable();
}
uint8_t write_mapped_pin(

View File

@@ -410,9 +410,8 @@ static void handle_iepint(uint8_t epnr)
handle_tx_ep0();
}
if (iepint & OTG_DIEPINT_TXFE) {
ASSERT(0);
}
/* We don't set DIEPEMPMSK bits so TXFE notification is impossible. */
ASSERT(!(iepint & OTG_DIEPINT_TXFE));
}
static void dwc_otg_process(void)

View File

@@ -65,7 +65,7 @@ void hw_usb_init(void)
}
break;
default:
ASSERT(0);
unreachable();
}
peripheral_clock_delay();
@@ -109,7 +109,7 @@ void hw_usb_deinit(void)
rcc->ahb1enr &= ~RCC_AHB1ENR_OTGHSEN;
break;
default:
ASSERT(0);
unreachable();
}
}