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

C backend does not generate function pointer conversion #22427

Open
ruihe774 opened this issue Jan 5, 2025 · 0 comments
Open

C backend does not generate function pointer conversion #22427

ruihe774 opened this issue Jan 5, 2025 · 0 comments
Labels
backend-c The C backend (CBE) outputs C source code. bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code.
Milestone

Comments

@ruihe774
Copy link
Contributor

ruihe774 commented Jan 5, 2025

Zig Version

0.14.0-dev.2587+f57a7458b

Steps to Reproduce and Observed Behavior

A minimal example:

fn awd() void {}

pub fn main() void {
    @as(*const fn (u32) void, @ptrCast(&awd))(1);
}

Quoted from the generated non-compilable C code:

static void test_awd__224(void) {
 return;
}

static void test_main__225(void) {
 /* file:2:59 */
 test_awd__224(UINT32_C(1));
 return;
}

See also #22368 (comment)

Expected Behavior

The generated C code includes the function pointer conversion and can be compiled by C compiler.

@ruihe774 ruihe774 added the bug Observed behavior contradicts documented or intended behavior label Jan 5, 2025
@alexrp alexrp added backend-c The C backend (CBE) outputs C source code. miscompilation The compiler reports success but produces semantically incorrect code. labels Jan 5, 2025
@alexrp alexrp added this to the 0.15.0 milestone Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-c The C backend (CBE) outputs C source code. bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code.
Projects
None yet
Development

No branches or pull requests

2 participants