Skip to content

segfault when slicing with pointer start index #3529

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

Closed
emekoi opened this issue Oct 25, 2019 · 4 comments
Closed

segfault when slicing with pointer start index #3529

emekoi opened this issue Oct 25, 2019 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@emekoi
Copy link
Contributor

emekoi commented Oct 25, 2019

test case:

test "foo" {
    _ = blk: {
        var array = [_]u8{};
        var idx: *usize = undefined;
        break :blk array[idx.*..];
    };
}
@LemonBoy
Copy link
Contributor

The result location madness strikes again. In ir_render_slice we have that tmp_struct_ptr is nullptr because the result is actually discarded and the result slot is typed as *void.

One should add something like this to

    if (!type_has_bits(instruction->result_loc->value.type)) {
        return nullptr;
    }

just before the line:

LLVMValueRef tmp_struct_ptr = ir_llvm_value(g, instruction->result_loc);

@tuket
Copy link

tuket commented Nov 3, 2019

What should be the expected output for this?

@emekoi
Copy link
Contributor Author

emekoi commented Nov 3, 2019

this is a reduced test from somewhere else in my code. what it boils down to is that i was trying to index an array with a variable from a capture block in a loop.

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Nov 26, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Nov 26, 2019
@andrewrk andrewrk added the stage1 The process of building from source via WebAssembly and the C backend. label Feb 21, 2020
@andrewrk
Copy link
Member

This now gives:

./test2.zig:5:25: error: expected type 'void', found '[]u8'
        break :blk array[idx.*..];
                        ^

expected output is to compile successfully.

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 21, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 29, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Dec 29, 2022
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

4 participants