Skip to content

Crash when assigning value to slice, possibly related to allocators, possibly related to u128s. #588

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
John-Minor opened this issue Mar 14, 2020 · 3 comments
Labels
cannot-replicate Unable to Replicate

Comments

@John-Minor
Copy link

Context

Code:

package test

import "core:fmt"
import "core:mem"

Stack :: struct(T :typeid)
{
    head :int,
    elements :[]T,
}

make_stack :: inline proc($T :typeid, len :int, allocator := context.allocator) -> (stack :Stack(T))
{
    using stack;
    head = 0;
    elements = make([]T, len, allocator);
    return;
}

make_temp_stack :: inline proc($T :typeid, len :int, allocator := context.temp_allocator) -> Stack(T)
{
    return make_stack(T, len, allocator);
}

push_unsafe :: inline proc(using stack :^Stack($T), element :T)
{
    #no_bounds_check elements[head] = element;
    head += 1;
}

main :: proc() {
    using fmt;

    arena_slice := make([]byte, mem.megabytes(30));
    defer delete(arena_slice);
    
    arena :mem.Arena;
    mem.init_arena(&arena, arena_slice);
    arena_allocator := mem.arena_allocator(&arena);

    context.temp_allocator = arena_allocator;

    st := make_temp_stack(u128,32);
    push_unsafe(&st, 1);

    println("done");
}

Alternatively, this version of main has also been reported to have the issue:

main :: proc() {
    using fmt;
    st := make_temp_stack(u128,32);
    push_unsafe(&st, 1);

    println("done");
}

Different optimization levels also affect the behavior. I can get similar code to sometimes work with optimization levels 0, 2, and 3, but not 1, and this code apparently only works with 0.

OS: Windows 10
Odin version: 0bac2445bb4e0e2b8e3b229f79a4bae9dedfdf7

Expected Behavior

The u128 should correctly be put into the specified index of the elements slice in the stack struct.

Current Behavior

When push_unsafe is used with a u128 it crashes.

Failure Information (for bugs)

This bug is difficult to explain because it seems to behave wildly differently depending on what else is happening in the code. This project is where it was discovered: https://github.com/John-Minor/Named-Regions-DFA-Regex

Because of various noodling I have been doing with that project I have encountered many behaviors that seem related to this that I do not know how to enumerate at this point in time. At one point I was not able to get the stack functions to work unless they were inlined, but it might be working now? I am unsure.

Steps to Reproduce

  1. Run the code excerpts listed in the Context section of this bug report.

Failure Logs

The program will crash without any output.

@gingerBill
Copy link
Member

I am unable to replicate this in the latest commit.

@Tetralux
Copy link
Contributor

Me neither.

@Tetralux
Copy link
Contributor

However, while this example is apparently fixed, the original issue apparently still persists, and it's not clear what is causing it.

@ThisDevDane ThisDevDane added the cannot-replicate Unable to Replicate label Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cannot-replicate Unable to Replicate
Projects
None yet
Development

No branches or pull requests

4 participants