From 8d62969cfe81db92cc6073003f231dcca845bf9d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Wed, 24 Jun 2020 02:39:38 -0400 Subject: [PATCH] glsl: validate more stuff Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/glsl/ir_validate.cpp | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/compiler/glsl/ir_validate.cpp b/src/compiler/glsl/ir_validate.cpp index 64e46991753..4f96ef0031b 100644 --- a/src/compiler/glsl/ir_validate.cpp +++ b/src/compiler/glsl/ir_validate.cpp @@ -69,11 +69,13 @@ public: virtual ir_visitor_status visit_enter(ir_function *ir); virtual ir_visitor_status visit_leave(ir_function *ir); virtual ir_visitor_status visit_enter(ir_function_signature *ir); + virtual ir_visitor_status visit_enter(ir_return *ir); virtual ir_visitor_status visit_leave(ir_expression *ir); virtual ir_visitor_status visit_leave(ir_swizzle *ir); virtual ir_visitor_status visit_enter(class ir_dereference_array *); + virtual ir_visitor_status visit_enter(class ir_dereference_record *); virtual ir_visitor_status visit_enter(ir_assignment *ir); virtual ir_visitor_status visit_enter(ir_call *ir); @@ -96,6 +98,13 @@ ir_validate::visit(ir_dereference_variable *ir) abort(); } + if (ir->var->type != ir->type) { + printf("ir_dereference_variable type is not equal to variable type: "); + ir->print(); + printf("\n"); + abort(); + } + if (_mesa_set_search(ir_set, ir->var) == NULL) { printf("ir_dereference_variable @ %p specifies undeclared variable " "`%s' @ %p\n", @@ -121,6 +130,21 @@ ir_validate::visit_enter(class ir_dereference_array *ir) abort(); } + if (ir->array->type->is_array()) { + if (ir->array->type->fields.array != ir->type) { + printf("ir_dereference_array type is not equal to the array " + "element type: "); + ir->print(); + printf("\n"); + abort(); + } + } else if (ir->array->type->base_type != ir->type->base_type) { + printf("ir_dereference_array base types are not equal: "); + ir->print(); + printf("\n"); + abort(); + } + if (!ir->array_index->type->is_scalar()) { printf("ir_dereference_array @ %p does not have scalar index: %s\n", (void *) ir, ir->array_index->type->name); @@ -136,6 +160,28 @@ ir_validate::visit_enter(class ir_dereference_array *ir) return visit_continue; } +ir_visitor_status +ir_validate::visit_enter(class ir_dereference_record *ir) +{ + if (!ir->record->type->is_struct() && !ir->record->type->is_interface()) { + printf("ir_dereference_record @ %p does not specify a record\n", + (void *) ir); + ir->print(); + printf("\n"); + abort(); + } + + if (ir->record->type->fields.structure[ir->field_idx].type != ir->type) { + printf("ir_dereference_record type is not equal to the record " + "field type: "); + ir->print(); + printf("\n"); + abort(); + } + + return visit_continue; +} + ir_visitor_status ir_validate::visit_enter(ir_discard *ir) { @@ -234,6 +280,17 @@ ir_validate::visit_enter(ir_function_signature *ir) return visit_continue; } +ir_visitor_status +ir_validate::visit_enter(ir_return *ir) +{ + if (!this->current_function) { + printf("Return statement outside of a function\n"); + abort(); + } + + return visit_continue; +} + ir_visitor_status ir_validate::visit_leave(ir_expression *ir) { @@ -1032,6 +1089,15 @@ ir_validate::visit_enter(ir_assignment *ir) } } + if (lhs->type->base_type != ir->rhs->type->base_type) { + printf("Assignment LHS and RHS base types are different:\n"); + lhs->print(); + printf("\n"); + ir->rhs->print(); + printf("\n"); + abort(); + } + this->validate_ir(ir, this->data_enter); return visit_continue; -- 2.30.2