nir: Assert the nir_src union is used safely

It is undefined behaviour in C to read a different member of a union than was
written. Nothing in-tree should be using this behaviour with the nir_src union:
nir_if should never be read as nir_instr and vice versa. Assert this.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24671>
This commit is contained in:
Alyssa Rosenzweig 2023-08-14 10:41:23 -04:00
parent c39896b17b
commit 316af8c965

View file

@ -1018,12 +1018,14 @@ nir_src_is_if(const nir_src *src)
static inline nir_instr *
nir_src_parent_instr(const nir_src *src)
{
assert(!nir_src_is_if(src));
return src->renamed_parent_instr;
}
static inline struct nir_if *
nir_src_parent_if(const nir_src *src)
{
assert(nir_src_is_if(src));
return src->parent_if;
}