[PATCH vkd3d] vkd3d: Add a function to mark unreachable code.

Zebediah Figura zfigura at codeweavers.com
Fri Apr 8 12:00:27 CDT 2022


On 4/8/22 08:04, Giovanni Mascellani wrote:
> diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
> index eabe189f..1ebd97c1 100644
> --- a/libs/vkd3d-shader/hlsl.c
> +++ b/libs/vkd3d-shader/hlsl.c
> @@ -1188,7 +1188,7 @@ static void dump_ir_constant(struct vkd3d_string_buffer *buffer, const struct hl
>                   break;
>   
>               default:
> -                assert(0);
> +                vkd3d_unreachable("Unknown type");
>           }
>       }
>       if (type->dimx != 1)

I don't think there's value in specifying a message for cases like this, 
and I'd rather not have to do so in new code. This applies to pretty 
much anywhere we have an assert() in a switch default case.

(Ideally we should avoid the 'default' keyword where possible, although 
in some cases this is difficult.)

> @@ -1542,12 +1534,10 @@ static void write_sm4_cast(struct hlsl_ctx *ctx,
>               break;
>   
>           case HLSL_TYPE_BOOL:
> -            /* Casts to bool should have already been lowered. */
> -            assert(0);
> -            break;
> +            vkd3d_unreachable("Casts to bool should have already been lowered");

This one I think should remain an assert. I can more easily see this 
getting triggered due to some forgotten implicit agreement. Hence we 
probably shouldn't tell the compiler this code path is unreachable.

Using an assert(!"string") or assert(0 && "string") construction (or 
defining our own macro) seems reasonable to me, though.



More information about the wine-devel mailing list