spirv: Assert that OpTypeForwardPointer only points to structs

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4743>
This commit is contained in:
Jason Ekstrand
2021-09-27 16:43:23 -05:00
committed by Marge Bot
parent e87dbfd3e8
commit 219ac26ea3

View File

@@ -1587,6 +1587,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
if (opcode == SpvOpTypePointer)
deref_type = vtn_get_type(b, w[3]);
bool has_forward_pointer = false;
if (val->value_type == vtn_value_type_invalid) {
val->value_type = vtn_value_type_type;
val->type = rzalloc(b, struct vtn_type);
@@ -1617,6 +1618,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
"The storage classes of an OpTypePointer and any "
"OpTypeForwardPointers that provide forward "
"declarations of it must match.");
has_forward_pointer = true;
}
if (opcode == SpvOpTypePointer) {
@@ -1625,6 +1627,11 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
"forward declaration of a pointer, OpTypePointer can "
"only be used once for a given id.");
vtn_fail_if(has_forward_pointer &&
deref_type->base_type != vtn_base_type_struct,
"An OpTypePointer instruction must declare "
"Pointer Type to be a pointer to an OpTypeStruct.");
val->type->deref = deref_type;
/* Only certain storage classes use ArrayStride. */