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

stage2 test-run-translated-c test "boolean values and expressions" produces old function pointer semantics #12194

Closed
andrewrk opened this issue Jul 22, 2022 · 4 comments · Fixed by #12234
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@andrewrk
Copy link
Member

[nix-shell:~/Downloads/zig/build-release]$ time stage2/bin/zig build test-run-translated-c
/home/andy/.cache/zig/o/f2302a0f9c1008101cfc5ce3b88e5ebc/source.zig:448:32: error: expected pointer, found 'fn(c_int, c_int) callconv(.C) void'
    var self: bool = @ptrToInt(foo) != 0;
                               ^~~
error: run-translated-c boolean values and expressions build-exe...
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. translate-c C to Zig source translation feature (@cImport) labels Jul 22, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Jul 22, 2022
@ehaas
Copy link
Sponsor Contributor

ehaas commented Jul 22, 2022

Do we need to change how we translate this, or is this a bug in stage2's ptrToInt?

@Vexu
Copy link
Member

Vexu commented Jul 22, 2022

I think this can be argued in either way, since translate-c is passing a function when a pointer is expected but other places in stage2 support implicit casts from functions to function pointers. I tried to fix this in translate-c earlier today and it turned out to be more complicated than I anticipated.

@andrewrk
Copy link
Member Author

Good point about implicit casts from functions to function pointers. I'm fine with solving this in Sema.

@andrewrk
Copy link
Member Author

andrewrk commented Jul 25, 2022

Hmm I actually changed my mind about this one. I know it's annoying but I think this needs to be a translate-c change. The problem is that @ptrToInt is one of the most unsafe operations we have, and so I think it makes sense for it to not do any implicit coercions on the operand. We don't want anyone accidentally passing a wrong identifier to @ptrToInt, but because it was a function (of which many identifiers are!), it passed the type-check.

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 frontend Tokenization, parsing, AstGen, Sema, and Liveness. translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants