ir_validate: Validate loop control fields in ir_loop
authorIan Romanick <ian.d.romanick@intel.com>
Thu, 26 Aug 2010 22:22:06 +0000 (15:22 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 3 Sep 2010 18:55:21 +0000 (11:55 -0700)
src/glsl/ir_validate.cpp

index 9ea11dd400ec8961e758e4086e4dec4b519bcc49..8e8259036447d52a4ce756f1b1541a74cf8f24ac 100644 (file)
@@ -61,6 +61,7 @@ public:
    virtual ir_visitor_status visit(ir_dereference_variable *ir);
    virtual ir_visitor_status visit(ir_if *ir);
 
+   virtual ir_visitor_status visit_leave(ir_loop *ir);
    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);
@@ -113,6 +114,40 @@ ir_validate::visit(ir_if *ir)
 }
 
 
+ir_visitor_status
+ir_validate::visit_leave(ir_loop *ir)
+{
+   if (ir->counter != NULL) {
+      if ((ir->from == NULL) || (ir->from == NULL) || (ir->increment == NULL)) {
+        printf("ir_loop has invalid loop controls:\n"
+               "    counter:   %p\n"
+               "    from:      %p\n"
+               "    to:        %p\n"
+               "    increment: %p\n",
+               ir->counter, ir->from, ir->to, ir->increment);
+        abort();
+      }
+
+      if ((ir->cmp < ir_binop_less) || (ir->cmp > ir_binop_nequal)) {
+        printf("ir_loop has invalid comparitor %d\n", ir->cmp);
+        abort();
+      }
+   } else {
+      if ((ir->from != NULL) || (ir->from != NULL) || (ir->increment != NULL)) {
+        printf("ir_loop has invalid loop controls:\n"
+               "    counter:   %p\n"
+               "    from:      %p\n"
+               "    to:        %p\n"
+               "    increment: %p\n",
+               ir->counter, ir->from, ir->to, ir->increment);
+        abort();
+      }
+   }
+
+   return visit_continue;
+}
+
+
 ir_visitor_status
 ir_validate::visit_enter(ir_function *ir)
 {