Skip to content

Commit 0053aa1

Browse files
authored
Merge pull request #190 from maleadt/tb/rm_init
Support for removing an initializer.
2 parents bf12473 + a2d1976 commit 0053aa1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/core/value/constant.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,14 @@ GlobalVariable(mod::Module, typ::LLVMType, name::String, addrspace::Integer) =
217217

218218
unsafe_delete!(::Module, gv::GlobalVariable) = API.LLVMDeleteGlobal(ref(gv))
219219

220-
initializer(gv::GlobalVariable) =
221-
Value(API.LLVMGetInitializer(ref(gv)))
220+
function initializer(gv::GlobalVariable)
221+
init = API.LLVMGetInitializer(ref(gv))
222+
init == C_NULL ? nothing : Value(init)
223+
end
222224
initializer!(gv::GlobalVariable, val::Constant) =
223225
API.LLVMSetInitializer(ref(gv), ref(val))
226+
initializer!(gv::GlobalVariable, ::Nothing) =
227+
API.LLVMSetInitializer(ref(gv), C_NULL)
224228

225229
isthreadlocal(gv::GlobalVariable) = convert(Core.Bool, API.LLVMIsThreadLocal(ref(gv)))
226230
threadlocal!(gv::GlobalVariable, bool) =

test/core.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,12 @@ LLVM.Module("SomeModule", ctx) do mod
421421

422422
show(devnull, gv)
423423

424-
@test_throws UndefRefError initializer(gv)
424+
@test initializer(gv) === nothing
425425
init = ConstantInt(Int32(0), ctx)
426426
initializer!(gv, init)
427427
@test initializer(gv) == init
428+
initializer!(gv, nothing)
429+
@test initializer(gv) === nothing
428430

429431
@test !isthreadlocal(gv)
430432
threadlocal!(gv, true)

0 commit comments

Comments
 (0)