glsl: Add validation that a swizzle only references valid channels.
authorEric Anholt <eric@anholt.net>
Mon, 27 Sep 2010 22:48:15 +0000 (15:48 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 27 Sep 2010 22:52:56 +0000 (15:52 -0700)
Caught the bug in the previous commit.

src/glsl/ir_validate.cpp

index e35514aa6f956a06af7e1244385cd6b9dec4b62e..70fb939b10aca382e185b75b5fa2e13aecefefa1 100644 (file)
@@ -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);
 
@@ -364,6 +365,23 @@ ir_validate::visit_leave(ir_expression *ir)
    return visit_continue;
 }
 
+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)
 {