Skip to content

Miscompilation with switch in anonymous struct literal #7097

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

Closed
ikskuh opened this issue Nov 13, 2020 · 3 comments
Closed

Miscompilation with switch in anonymous struct literal #7097

ikskuh opened this issue Nov 13, 2020 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code. stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@ikskuh
Copy link
Contributor

ikskuh commented Nov 13, 2020

The following function will always print reading from and will ignore the runtime parameter:

fn logErrorBad(err: Error, address: u24, access: BusAccess) Error {
    std.debug.print("{} when {} {X:0>6}\n", .{
        @errorName(err),
        @as([]const u8, switch (access) {
            .read => "reading from",
            .write => "writing to",
        }),
        address,
    });
    return err;
}

Fully runnble example can be found here:
https://gist.github.com/MasterQ32/da5b1f2dbe4ebc89ebbf602d8b118fca

Moving out the switch+@as will fix the problem. This is probably a known issue already

@alexnask alexnask added bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code. stage1 The process of building from source via WebAssembly and the C backend. labels Nov 13, 2020
@alexnask alexnask added this to the 0.8.0 milestone Nov 13, 2020
@travv0
Copy link
Contributor

travv0 commented Nov 13, 2020

Related to #3882?

@ghost
Copy link

ghost commented Nov 13, 2020

I think this is a more likely duplicate: #6444

@Mouvedia
Copy link

dupe of #5230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code. stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

6 participants