Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator variables shouldn't "leak" out of for-loops #4028

Closed
Jasper-Bekkers opened this issue Oct 21, 2021 · 2 comments
Closed

Iterator variables shouldn't "leak" out of for-loops #4028

Jasper-Bekkers opened this issue Oct 21, 2021 · 2 comments

Comments

@Jasper-Bekkers
Copy link

http://shader-playground.timjones.io/9ec140c1a4f17799769abb8a333f4986

void stuff(out float3 b) {
    for(int i = 0; i < 10; i++) {
    }
    
    b = i;
}

I think these are legacy HLSL rules, but in any modern programming language with reasonable scoping rules this shouldn't compile. I think we shouldn't expect DXC to accept this code.

@jaebaek
Copy link
Collaborator

jaebaek commented Oct 21, 2021

@pow2clk Oops .. this is an interesting bug. I am curious the for-loop is the only case or it can happen in other cases as well.

@pow2clk
Copy link
Member

pow2clk commented Oct 21, 2021

Hi @Jasper-Bekkers,

We have to blame the gravity of legacy for this one. This is how HLSL has behaved since its inception. We considered this change for HLSL 2021, but decided it was a more impactful change than we were willing to make at this time. We will likely consider it again for the next HLSL version.

It is a known issue. In fact, a much older bug #584 is already tracking this. As such, I'm closing this as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants