Re: [Mesa-dev] [PATCH 2/2] glsl: raise warning when using uninitialized variables

2016-02-28 Thread Alejandro Piñeiro


On 26/02/16 22:18, Ian Romanick wrote:
> On 02/26/2016 07:09 AM, Alejandro Piñeiro wrote:
>> 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
>> ---
>>  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 49e4858..ac451df 100644
>> --- a/src/compiler/glsl/ast_to_hir.cpp
>> +++ b/src/compiler/glsl/ast_to_hir.cpp
>> @@ -1899,6 +1899,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(, state, "`%s' used uninitialized",
>> +   this->primary_expression.identifier);
> It seems like this might miss cases like
>
> void main()
> {
> int i;
> int a[2];
>
> a[i] = 0;
> }

Just tested and I got the "warning: `i' used uninitialized" message, so
this case is covered.

BR
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/2] glsl: raise warning when using uninitialized variables

2016-02-26 Thread Ian Romanick
On 02/26/2016 07:09 AM, Alejandro Piñeiro wrote:
> 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
> ---
>  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 49e4858..ac451df 100644
> --- a/src/compiler/glsl/ast_to_hir.cpp
> +++ b/src/compiler/glsl/ast_to_hir.cpp
> @@ -1899,6 +1899,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(, state, "`%s' used uninitialized",
> +   this->primary_expression.identifier);

It seems like this might miss cases like

void main()
{
int i;
int a[2];

a[i] = 0;
}

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

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/2] glsl: raise warning when using uninitialized variables

2016-02-26 Thread Alejandro Piñeiro
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
---
 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 49e4858..ac451df 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -1899,6 +1899,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(, state, "`%s' used uninitialized",
+   this->primary_expression.identifier);
+ }
   } else {
  _mesa_glsl_error(& loc, state, "`%s' undeclared",
   this->primary_expression.identifier);
-- 
2.5.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev