[Mesa-dev] [PATCH] util/tgsi: add static assertion to catch opcode overflowing bitfield

Roland Scheidegger sroland at vmware.com
Tue Nov 7 16:16:25 UTC 2017


Am 07.11.2017 um 17:09 schrieb Brian Paul:
> I've noticed at least two places where we store the TGSI opcode in
> an unsigned:8 bitfield.  We're at 249 opcodes now.  If we hit 256 we'll
> need to grow those bitfields.  Add a static assertion to detect that.
> ---
>  src/gallium/auxiliary/tgsi/tgsi_info.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_info.c b/src/gallium/auxiliary/tgsi/tgsi_info.c
> index 4e39950..ff4b150 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_info.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_info.c
> @@ -55,6 +55,11 @@ tgsi_get_opcode_info( uint opcode )
>  {
>     static boolean firsttime = 1;
>  
> +   /* If this assertion fails, increase tgsi_opcode_info::opcode
> +    * and glsl_to_tgsi_instruction::op field sizes (and other locations?)
> +    */
> +   STATIC_ASSERT(TGSI_OPCODE_LAST <= 255);
I think technically this could be 256 as we're never assigning this
"last" opcode?
Either way though,
Reviewed-by: Roland Scheidegger <sroland at vmware.com>

(And yes we have been very close to the limit for a while now - I think
so far the solution has been to remove deprecated opcodes instead of
increasing the limit, but that might no longer suffice in the future. It
should not be all that difficult to increase the limit in any case.)


> +
>     if (firsttime) {
>        unsigned i;
>        firsttime = 0;
> 



More information about the mesa-dev mailing list