glsl: raise warning when using uninitialized variables
authorAlejandro Piñeiro <apinheiro@igalia.com>
Tue, 23 Feb 2016 10:48:52 +0000 (11:48 +0100)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Tue, 29 Mar 2016 05:28:57 +0000 (07:28 +0200)
v2:
 * Take into account out varyings too (Timothy Arceri)
 * Fix style (Timothy Arceri)
 * Use a new ast_expression variable, instead of an
   ast_expression::hir new parameter (Timothy Arceri)

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94129

Reviewed-by: Timothy Arceri <timothy.arceri@collabora.com>
src/compiler/glsl/ast_to_hir.cpp

index e162203c1c8179d26c22a639615fd17a71149da9..29a4642af2cfd0cbe0c73ad4590648d5d5e8ef4e 100644 (file)
@@ -1901,6 +1901,13 @@ ast_expression::do_hir(exec_list *instructions,
       if (var != NULL) {
          var->data.used = true;
          result = new(ctx) ir_dereference_variable(var);
+
+         if ((var->data.mode == ir_var_auto || var->data.mode == ir_var_shader_out)
+             && !this->is_lhs
+             && result->variable_referenced()->data.assigned != true) {
+            _mesa_glsl_warning(&loc, state, "`%s' used uninitialized",
+                               this->primary_expression.identifier);
+         }
       } else {
          _mesa_glsl_error(& loc, state, "`%s' undeclared",
                           this->primary_expression.identifier);