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

never_inline call modifier ignored #20290

Open
vadim-za opened this issue Jun 14, 2024 · 0 comments
Open

never_inline call modifier ignored #20290

vadim-za opened this issue Jun 14, 2024 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@vadim-za
Copy link

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

Take the following code and compile in ReleaseFast.

const std = @import("std");

const A = struct { data: usize = 0 };
const B = struct { data: *usize };

fn getA(a: *A) usize {
    const maybe_data: ?*usize = &a.data;
    return if (maybe_data) |data| data.* else 0xFFFF;
}

fn getB(b: *B) usize {
    const maybe_data: ?*usize = b.data;
    return if (maybe_data) |data| data.* else 0xFFFF;
}

pub fn main() void {
    var a = A{};
    var b = B{ .data = &a.data };
    std.mem.doNotOptimizeAway(&a);
    std.mem.doNotOptimizeAway(&b);
    @breakpoint();
    std.mem.doNotOptimizeAway(@call(.never_inline, getA, .{&a}));
    std.mem.doNotOptimizeAway(@call(.never_inline, getB, .{&b}));
}

Inspect the generated machine code at the breakpoint (so far reproed on x64). The call to getB is not inlined, as expected, but the call to getA has been fully inlined.

Expected Behavior

Both calls are not inlined.

Notes:

@vadim-za vadim-za added the bug Observed behavior contradicts documented or intended behavior label Jun 14, 2024
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
Projects
None yet
Development

No branches or pull requests

1 participant