Skip to content

Commit e9581f2

Browse files
authored
Merge pull request #303 from maleadt/tb/poison
Add support for poison values.
2 parents 2e8d315 + 4b245f0 commit e9581f2

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/core/value.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ end
4040

4141
## general APIs
4242

43-
export llvmtype, llvmeltype, name, name!, replace_uses!, isconstant, isundef, context
43+
export llvmtype, llvmeltype, name, name!, replace_uses!, isconstant, isundef, ispoison, context
4444

4545
llvmtype(val::Value) = LLVMType(API.LLVMTypeOf(val))
4646
llvmeltype(val::Value) = eltype(llvmtype(val))
@@ -59,6 +59,8 @@ isconstant(val::Value) = convert(Core.Bool, API.LLVMIsConstant(val))
5959

6060
isundef(val::Value) = convert(Core.Bool, API.LLVMIsUndef(val))
6161

62+
ispoison(val::Value) = convert(Core.Bool, API.LLVMIsPoison(val))
63+
6264
context(val::Value) = Context(API.LLVMGetValueContext(val))
6365

6466

src/core/value/constant.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract type Instruction <: User end
2020

2121
## data
2222

23-
export ConstantData, PointerNull, UndefValue, ConstantInt, ConstantFP
23+
export ConstantData, PointerNull, UndefValue, PoisonValue, ConstantInt, ConstantFP
2424

2525
abstract type ConstantData <: Constant end
2626

@@ -40,6 +40,14 @@ register(UndefValue, API.LLVMUndefValueValueKind)
4040

4141
UndefValue(typ::LLVMType) = UndefValue(API.LLVMGetUndef(typ))
4242

43+
@static if version() >= v"12"
44+
@checked struct PoisonValue <: ConstantData # XXX: actually <: UndefValue
45+
ref::API.LLVMValueRef
46+
end
47+
register(PoisonValue, API.LLVMPoisonValueValueKind)
48+
49+
PoisonValue(typ::LLVMType) = PoisonValue(API.LLVMGetPoison(typ))
50+
end
4351

4452
@checked struct ConstantInt <: ConstantData
4553
ref::API.LLVMValueRef

test/core.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ Context() do ctx
322322
@test val isa LLVM.Constant
323323
end
324324

325+
if LLVM.version() >= v"12"
326+
let val = PoisonValue(typ)
327+
@test ispoison(val)
328+
@test val isa LLVM.Constant
329+
end
330+
end
331+
325332
end
326333
end
327334

0 commit comments

Comments
 (0)