From 219ac26ea3361d3ae185d9e98a753656fd33a534 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 27 Sep 2021 16:43:23 -0500 Subject: [PATCH] spirv: Assert that OpTypeForwardPointer only points to structs Reviewed-by: Caio Marcelo de Oliveira Filho Part-of: --- src/compiler/spirv/spirv_to_nir.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 26e7582bed5..5f9ac65fbad 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -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. */