[Mesa-dev] [PATCH mesa] util: enforce unreachable() semantic

Emil Velikov emil.l.velikov at gmail.com
Mon Jul 10 16:02:48 UTC 2017


On 10 July 2017 at 16:08, Eric Engestrom <eric.engestrom at imgtec.com> wrote:
> No implementation of unreachable() should allow code execution to
> keep going past it.
>
> We can discuss whether we should have a dead loop, abort(), or do
> something else, but the current "meh, let's just keep going" is
> just wrong.
>
> Cc: mesa-stable at lists.freedesktop.org
> Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
> ---
>  src/util/macros.h | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/util/macros.h b/src/util/macros.h
> index a10f1de814..16682bf6e8 100644
> --- a/src/util/macros.h
> +++ b/src/util/macros.h
> @@ -84,7 +84,11 @@ do {                        \
>     __assume(0);             \
>  } while (0)
>  #else
> -#define unreachable(str) assert(!str)
> +#define unreachable(str)    \
> +do {                        \
> +   assert(!str);            \
> +   while(1);                \
> +} while (0)
>  #endif
Strictly speaking the current solution follows what the builtin does -
pretty much anything is possible.
In release builds the assert gets purged and we end up at the mercy of
the compiler.

Simple test showed varying behaviour - wrong case statement picked
(-O0), straight crash (-O1), semi-dead loop followed by a crash (-O2,
-O3).

I think we'd want to stick with the current solution, but either way
is fine with me.
-Emil


More information about the mesa-dev mailing list