From 29ab8feb08d2561a35d34978fcea5f5837bd8859 Mon Sep 17 00:00:00 2001 From: Yupei Qi Date: Fri, 3 Nov 2023 13:03:31 +0900 Subject: [PATCH] Fix 452 (#453) --- src/generator/codegen.jl | 2 +- test/generators.jl | 5 +++++ test/include/struct-mutual-ref.h | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/include/struct-mutual-ref.h diff --git a/src/generator/codegen.jl b/src/generator/codegen.jl index 90895477..872d7226 100644 --- a/src/generator/codegen.jl +++ b/src/generator/codegen.jl @@ -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)" diff --git a/test/generators.jl b/test/generators.jl index f34cbe84..092620a3 100644 --- a/test/generators.jl +++ b/test/generators.jl @@ -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 diff --git a/test/include/struct-mutual-ref.h b/test/include/struct-mutual-ref.h new file mode 100644 index 00000000..293d6388 --- /dev/null +++ b/test/include/struct-mutual-ref.h @@ -0,0 +1,26 @@ +#include +#include + +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]; +}; \ No newline at end of file