eve icon indicating copy to clipboard operation
eve copied to clipboard

Add fall-through checks to if-constexpr chains

Open SadiinsoSnowfall opened this issue 1 month ago • 2 comments

A lof ot code in EVE is composed of if-constexpr chains which do not have a final else branch. Most of the time this is not a problem as the implicit else branch is never reached. However, when debugging EVE or adding new functionalities, such branches may be reached and in some cases introduce UB in the program without any compiler diagnostic.

I propose to add a new macro, EVE_UNREACHEABLE which raises an error using static_assert when reached, and use this macro in every as-of-now implicit else constexpr branch to ensure that no fall-through ever occur without the user noticing.

As an example, calling an eve function with a type no covered in its if-constexpr chain leads to the following code gen under GCC:

test():
     brk

Under clang, no assembly is generated as the compiler consider the caller function UB. With the macro, the following error is raised:

error: static assertion failed: [EVE] Fallthrough rejected
   43 |         else    EVE_UNREACHABLE();

This implies that most of the source files should be modified to accommodate this change, this PR only applies to the neon backend as a demonstration.

SadiinsoSnowfall avatar Jun 26 '24 15:06 SadiinsoSnowfall