Skip to content

Commit

Permalink
Fix 452 (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnimuc authored Nov 3, 2023
1 parent d1564dc commit 29ab8fe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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];
};

0 comments on commit 29ab8fe

Please sign in to comment.