Skip to content

Shadowing and --move-declarations wrong scope #458

@therontarigo

Description

@therontarigo

Input:

uniform int A;
uniform int B;
out vec4 O;

void main() {
  O = vec4(0);
  float f = 1;
  if (B < 2) f = A;
  {
    float n = A + 1;
    if (B < 1) O.y=1;
    float f = f * n + n * n;
    O.x=f;
  }
}

With no options, correct output:

uniform int v,Q;
out vec4 i;
void main()
{
  i=vec4(0);
  float m=1;
  if(Q<2)
    m=v;
  {
    float f=v+1;
    if(Q<1)
      i.y=1;
    f=m*f+f*f;
    i.x=f;
  }
}

With --move-declarations:

uniform int v,Q;
out vec4 i;
void main()
{
  i=vec4(0);
  float m=1;
  if(Q<2)
    m=v;
  {
    float x=v+1,f;
    if(Q<1)
      i.y=1;
    f=f*x+x*x;  // here
    i.x=f;
  }
}

Now f=f*x+x*x is referencing the uninitialized variable f instead of resolving correctly to m.

Some cases of scope shadowing with visibility to context scope in the initializer expression were already resolved in #153.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions