Skip to content

the language should honor alignment decaying in type coercion #7495

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

Open
andrewrk opened this issue Dec 19, 2020 · 2 comments
Open

the language should honor alignment decaying in type coercion #7495

andrewrk opened this issue Dec 19, 2020 · 2 comments
Labels
accepted This proposal is planned. breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Dec 19, 2020

export fn entry() void {
    var buf: [10]u8 align(4096) = undefined;
    const x: []u8 = &buf;
    @compileLog(@TypeOf(x));
}

This outputs:

[nix-shell:~/Downloads/zig/build]$ ./zig build-obj foo.zig 
| []align(4096) u8
./foo.zig:4:5: error: found compile log statement
    @compileLog(@TypeOf(x));
    ^

I believe this strange behavior is the cause of the bug that is surfacing in #7482 (comment)

The language should not ignore the programmer's type that they specify.

Related: #1106

Labeling as a bug because if this proposal is accepted I believe it will fix a bug, if this proposal is rejected then this issue will be the bug report for that behavior. The bug is that generic functions which accept slices/pointers get incorrectly generated with respect to alignment. See that linked issue comment above for more details.

@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Dec 19, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Dec 19, 2020
@andrewrk andrewrk added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code. labels Dec 19, 2020
@LemonBoy
Copy link
Contributor

The same thing happens with @ptrCast, ir_analyze_ptr_cast has a keep_bigger_alignment parameter that may hint this is a wanted behaviour?

@andrewrk
Copy link
Member Author

I did it intentionally but I think that may have been a bad idea. I'm pretty sure we should change the language spec to accept this proposal but I just want to put a bit of thought into @ptrCast because it would be nice to keep extra alignment when doing pointer casting.

@andrewrk andrewrk removed bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code. labels Dec 20, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk added the accepted This proposal is planned. label Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jun 19, 2023
@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

2 participants