diff options
author | Marek Olšák <[email protected]> | 2020-06-24 02:39:38 -0400 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2020-07-07 22:02:06 -0400 |
commit | 8d62969cfe81db92cc6073003f231dcca845bf9d (patch) | |
tree | e45260d324443945c71a37451a6bd330dcb79ce3 | |
parent | 8773d58b056e2299c5c1d93543a4cc8512fcccf3 (diff) |
glsl: validate more stuff
Reviewed-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5746>
-rw-r--r-- | src/compiler/glsl/ir_validate.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
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); @@ -137,6 +161,28 @@ ir_validate::visit_enter(class ir_dereference_array *ir) } 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) { if (ir->condition && ir->condition->type != glsl_type::bool_type) { @@ -235,6 +281,17 @@ ir_validate::visit_enter(ir_function_signature *ir) } 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) { for (unsigned i = ir->num_operands; i < 4; i++) { @@ -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; |