util/ra: Sanity check that we're adding a valid reg to a class.
authorEric Anholt <eric@anholt.net>
Thu, 9 Apr 2020 22:10:08 +0000 (15:10 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Apr 2020 19:46:08 +0000 (19:46 +0000)
BITSET_SET might not segfault on you right away if you're just slightly
off, and an assert is nicer anyway.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4537>

src/util/register_allocate.c

index a65b5ea154f70b96cf960821b8e0a6d0b2dab31c..68d4a13ca1e9e55e34c15156adc75c6ceca04802 100644 (file)
@@ -371,6 +371,8 @@ ra_class_add_reg(struct ra_regs *regs, unsigned int c, unsigned int r)
 {
    struct ra_class *class = regs->classes[c];
 
+   assert(r < regs->count);
+
    BITSET_SET(class->regs, r);
    class->p++;
 }