[Mesa-dev] [RFC 3/3] glsl: raise warning when using uninitialized variables

Timothy Arceri t_arceri at yahoo.com.au
Wed Feb 24 23:27:56 UTC 2016


On Wed, 2016-02-24 at 20:04 +0100, Alejandro Piñeiro wrote:
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94129
> ---
>  src/compiler/glsl/ast_to_hir.cpp | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/compiler/glsl/ast_to_hir.cpp
> b/src/compiler/glsl/ast_to_hir.cpp
> index ee5485c..296c845 100644
> --- a/src/compiler/glsl/ast_to_hir.cpp
> +++ b/src/compiler/glsl/ast_to_hir.cpp
> @@ -1885,6 +1885,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

I think we would also maybe want to warn for output varyings???

var->data.mode == ir_var_shader_out

> +             && !assignment_recipient
> +             && result->variable_referenced()->data.assigned !=
> true) {
> +            _mesa_glsl_warning(& loc, state, "`%s' used 
                                ---^
We don't really use this style anymore   

> uninitialized",
> +                               this->primary_expression.identifier);
> +         }

I think what you have will work but I don't really like passing
around assignment_recipient. Maybe it would be better just to add a new
bool lhs_var; to the ast_expression class that defaults to false and
use that instead.


>        } else {
>           _mesa_glsl_error(& loc, state, "`%s' undeclared",
>                            this->primary_expression.identifier);


More information about the mesa-dev mailing list