File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ function operands(md::MDNode)
108
108
nops = API. LLVMExtraGetMDNodeNumOperands2 (md)
109
109
ops = Vector {API.LLVMMetadataRef} (undef, nops)
110
110
API. LLVMExtraGetMDNodeOperands2 (md, ops)
111
- return [Metadata (op) for op in ops]
111
+ return [op == C_NULL ? nothing : Metadata (op) for op in ops]
112
112
end
113
113
114
114
# TODO : setindex?
@@ -131,3 +131,10 @@ MDNode(mds::Vector{<:Metadata}; ctx::Context) =
131
131
MDTuple (API. LLVMMDNodeInContext2 (ctx, mds, length (mds)))
132
132
MDNode (vals:: Vector ; ctx:: Context ) =
133
133
MDNode (convert (Vector{Metadata}, vals); ctx)
134
+
135
+ # we support passing `nothing`, but convert it to a non-exported `MDNull` instance
136
+ # so that we can keep everything as a subtype of `Metadata`
137
+ struct MDNull <: Metadata end
138
+ Base. convert (:: Type{Metadata} , :: Nothing ) = MDNull ()
139
+ Base. unsafe_convert (:: Type{API.LLVMMetadataRef} , md:: MDNull ) =
140
+ convert (API. LLVMMetadataRef, C_NULL )
Original file line number Diff line number Diff line change @@ -851,6 +851,23 @@ Context() do ctx
851
851
@test ops[1 ] == str
852
852
end
853
853
854
+ # null metadata, represented as null pointers in the API, by `nothing` in Julia
855
+ Context () do ctx
856
+ ir = """
857
+ !0 = !{i32 42, null, !"string"}
858
+ !foo = !{!0}
859
+ """
860
+ mod = parse (LLVM. Module, ir; ctx)
861
+
862
+ foo_md = operands (metadata (mod)[" foo" ])[1 ]
863
+ @test operands (foo_md)[1 ] != = nothing
864
+ @test operands (foo_md)[2 ] === nothing
865
+ @test operands (foo_md)[3 ] != = nothing
866
+
867
+ bar_md = MDNode ([ConstantInt (Int32 (42 ); ctx), nothing , MDString (" string" ; ctx)]; ctx)
868
+ @test foo_md == bar_md
869
+ end
870
+
854
871
@testset " debuginfo" begin
855
872
856
873
Context () do ctx
You can’t perform that action at this time.
0 commit comments