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 issue 307 #342

Merged
merged 3 commits into from
Sep 29, 2021
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
15 changes: 11 additions & 4 deletions src/generator/system_deps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ function collect_dependent_system_nodes!(dag::ExprDAG, node::ExprNode{TypedefToA
return system_nodes
end

function collect_dependent_system_nodes!(dag::ExprDAG, node::ExprNode{<:AbstractStructNodeType}, system_nodes)
cursor = node.cursor
for c in fields(getCursorType(cursor))
function collect_dependent_system_nodes!(dag::ExprDAG, node::ExprNode{<:Union{AbstractStructNodeType, <:AbstractUnionNodeType}}, system_nodes)
collect_dependent_system_nodes!(dag, getCursorType(node.cursor), system_nodes)
end

function collect_dependent_system_nodes!(dag::ExprDAG, type::CLType, system_nodes)
for c in fields(type)
ty = getCursorType(c)
jlty = tojulia(ty)
leaf_ty = get_jl_leaf_type(jlty)
Expand All @@ -130,14 +133,18 @@ function collect_dependent_system_nodes!(dag::ExprDAG, node::ExprNode{<:Abstract
(!hasref && haskey(dag.ids, leaf_ty.sym)) ||
haskey(dag.ids_extra, leaf_ty.sym) ||
occursin("anonymous", spelling(ty))
# pass
# nested tags may also be from system headers
collect_dependent_system_nodes!(dag, ty, system_nodes)
else
# add all sys nodes with the same id
for (i, n) in enumerate(dag.sys)
if n.id == leaf_ty.sym
system_nodes[n] = i
end
end
if Clang.is_elaborated(ty)
collect_dependent_system_nodes!(dag, ty, system_nodes)
end
end
end
return dag
Expand Down
22 changes: 22 additions & 0 deletions test/generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,25 @@ end
build!(ctx)
@test include("LibEscapeWithVar.jl") isa Any
end

@testset "Issue 307" begin
args = get_default_args()
dir = joinpath(@__DIR__, "sys")
push!(args, "-isystem$dir")
headers = joinpath(@__DIR__, "include", "struct-in-union.h")
ctx = create_context(headers, args)
@test build!(ctx, BUILDSTAGE_NO_PRINTING) isa Any

headers = joinpath(@__DIR__, "include", "nested-struct.h")
ctx = create_context(headers, args)
@test build!(ctx, BUILDSTAGE_NO_PRINTING) isa Any

headers = joinpath(@__DIR__, "include", "nested-declaration.h")
ctx = create_context(headers, args)
@test_broken try
build!(ctx, BUILDSTAGE_NO_PRINTING) isa Any
true
catch
false
end
end
6 changes: 6 additions & 0 deletions test/include/nested-declaration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "nested-declaration-sys.h"

struct test_s
{
Inner_t lock;
};
9 changes: 9 additions & 0 deletions test/include/nested-struct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "struct-in-union-sys.h"

typedef struct
{
struct
{
pthread_mutex_t lock;
} s;
} test_t;
3 changes: 3 additions & 0 deletions test/include/struct-in-union.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "struct-in-union-sys.h"

typedef pthread_mutex_t lock;
10 changes: 10 additions & 0 deletions test/sys/nested-declaration-sys.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
struct Outer
{
// Inner is visible in global scope
struct Inner
{
int i;
} inner;
};

typedef struct Inner Inner_t;
13 changes: 13 additions & 0 deletions test/sys/struct-in-union-sys.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
typedef struct __pthread_internal_list
{
struct __pthread_internal_list *__prev;
} __pthread_list_t;

typedef union
{
struct __pthread_mutex_s
{
__pthread_list_t __list;
} __data;
char __size[1];
} pthread_mutex_t;