aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl/ir_validate.cpp
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2010-09-27 15:48:15 -0700
committerEric Anholt <[email protected]>2010-09-27 15:52:56 -0700
commit5e8ed7a79b381d559b059987bd99c68d40f641ca (patch)
tree2ad0e9cad409b0e3164653f765a321d72260d992 /src/glsl/ir_validate.cpp
parent668cdbe12958247f4a563c362dbf3247de7ccc3f (diff)
glsl: Add validation that a swizzle only references valid channels.
Caught the bug in the previous commit.
Diffstat (limited to 'src/glsl/ir_validate.cpp')
-rw-r--r--src/glsl/ir_validate.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp
index e35514aa6f9..70fb939b10a 100644
--- a/src/glsl/ir_validate.cpp
+++ b/src/glsl/ir_validate.cpp
@@ -67,6 +67,7 @@ public:
virtual ir_visitor_status visit_enter(ir_function_signature *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(ir_assignment *ir);
@@ -365,6 +366,23 @@ ir_validate::visit_leave(ir_expression *ir)
}
ir_visitor_status
+ir_validate::visit_leave(ir_swizzle *ir)
+{
+ int chans[4] = {ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w};
+
+ for (unsigned int i = 0; i < ir->type->vector_elements; i++) {
+ if (chans[i] >= ir->val->type->vector_elements) {
+ printf("ir_swizzle @ %p specifies a channel not present "
+ "in the value.\n", (void *) ir);
+ ir->print();
+ abort();
+ }
+ }
+
+ return visit_continue;
+}
+
+ir_visitor_status
ir_validate::visit(ir_variable *ir)
{
/* An ir_variable is the one thing that can (and will) appear multiple times