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

Fix 452 #453

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/generator/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ function emit!(dag::ExprDAG, node::ExprNode{StructMutualRef}, options::Dict; arg
# if `leaf_ty.sym` can not be found in `tags` and `ids` then it's in `ids_extra`
field_idx == typemax(Int) && @assert haskey(dag.ids_extra, leaf_ty.sym)

if node_idx < field_idx
if node_idx < field_idx && field_idx != typemax(Int)
# this assumes that circular references were removed at pointers
@assert is_jl_pointer(jlty) "Expected this field to be a pointer: $(struct_sym).$(field_sym)"

Expand Down
5 changes: 5 additions & 0 deletions test/generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,8 @@ end
ctx = create_context([joinpath(@__DIR__, "include/enum.h")], get_default_args(), options)
@test_logs (:info, "Done!") match_mode = :any build!(ctx)
end

@testset "Issue 452 - StructMutualRef" begin
ctx = create_context([joinpath(@__DIR__, "include/struct-mutual-ref.h")], get_default_args())
@test_logs (:info, "Done!") match_mode = :any build!(ctx)
end
26 changes: 26 additions & 0 deletions test/include/struct-mutual-ref.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdlib.h>
#include <stdbool.h>

struct mutualref {
int type;

struct buffer *buffer;

int n_dims;
int64_t ne[10];
size_t nb[10];

int32_t op_params[10 / sizeof(int32_t)];

bool is_param;

struct mutualref *grad;
struct mutualref *src[10];

struct mutualref *view_src;
size_t view_offs;

void *data;

char padding[12];
};