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

Segfault using anonymous tuple struct #20759

Open
FnControlOption opened this issue Jul 23, 2024 · 4 comments
Open

Segfault using anonymous tuple struct #20759

FnControlOption opened this issue Jul 23, 2024 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@FnControlOption
Copy link
Contributor

Zig Version

0.14.0-dev.367+a57479afc

Steps to Reproduce and Observed Behavior

In the following code, replacing any usage of IntRange with struct { i32, i32 } will result in a segmentation fault:

const std = @import("std");
const debug = std.debug;
const math = std.math;
const sort = std.sort;

const IntRange = struct { i32, i32 };

pub fn main() void {
    const items = [_]IntRange{ // segfaults with struct { i32, i32 }
        .{ 1, 25 },
        .{ 26, 50 },
        .{ 51, 75 },
        .{ 76, 100 },
    };
    const key: i32 = 42;
    const index = sort.binarySearch(IntRange, key, &items, {}, compareFn); // segfaults with struct { i32, i32 }
    debug.print("{?}\n", .{index});
}

fn compareFn(_: void, key: i32, mid_item: struct { i32, i32 }) math.Order {
    const lo, const hi = mid_item;
    return if (key < lo) .lt else if (key > hi) .gt else .eq;
}

Expected Behavior

No segfault

@FnControlOption FnControlOption added the bug Observed behavior contradicts documented or intended behavior label Jul 23, 2024
@xdBronch
Copy link
Contributor

looks like a duplicate of #19497

@FnControlOption
Copy link
Contributor Author

FnControlOption commented Jul 23, 2024

None of the examples in that issue are giving me a segfault 🤔

#20415 and #20746 look similar to my issue, though

@xdBronch
Copy link
Contributor

interesting, testing myself and yeah youre right. seems @Vexu mightve been wrong about the others being duplicates?

@Vexu
Copy link
Member

Vexu commented Jul 24, 2024

Only the third example in #19497 crashes now but it is different from this. The other two are the same as this one.

@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Jul 24, 2024
@Vexu Vexu added this to the 0.14.0 milestone Jul 24, 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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

3 participants