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

[naga wgsl-in] Fix parsing break ifs #5001

Merged
merged 1 commit into from
Jan 8, 2024

Conversation

Patryk27
Copy link
Contributor

@Patryk27 Patryk27 commented Jan 5, 2024

Closes #4982.

Note that #4558 (comment) does not get solved by this commit - in particular, something like this:

fn foo() {
    var a = 0;

    loop {
        let cmp = a < 8;

        if cmp {
            a += 1;
        }

        continuing {
            break if cmp;
        }
    }
}

... still gets miscompiled (when going to glsl, hlsl and msl):

void foo(
) {
    int a_2 = 0;
    bool loop_init_4 = true;
    while(true) {
        if (!loop_init_4) {
            if (a_2 < 8) { // whoopsie - should read `cmp`, not redo the comparison here!
                break;
            }
        }
        loop_init_4 = false;
        int _e2 = a_2;
        bool cmp = _e2 < 8;
        if (cmp) {
            int _e6 = a_2;
            a_2 = _e6 + 1;
        }
    }
    return;
}

... 'cause there's some another bug somewhere, not related to the wgsl frontend, that I can't put my finger on right now (using var cmp instead of let cmp generates correct output, tho).

@Patryk27 Patryk27 requested a review from a team as a code owner January 5, 2024 18:11
Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

@teoxoy teoxoy merged commit e7c7017 into gfx-rs:trunk Jan 8, 2024
26 checks passed
@Patryk27 Patryk27 deleted the fix-4982/wgsl-break-if-parsing branch March 17, 2024 12:04
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

Successfully merging this pull request may close these issues.

naga: Miscompilation with "break if"
2 participants