aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-12-20 18:19:01 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-12-20 18:28:59 -0500
commit8d73703d524e06e17320e025ff970c86ebc01d22 (patch)
tree1c9eae2163aa25df4380c6b6690933f5cec62ca1 /src/codegen.cpp
parent8918cb06fca10309dc67ac881894528eac33a8fc (diff)
downloadzig-8d73703d524e06e17320e025ff970c86ebc01d22.tar.gz
zig-8d73703d524e06e17320e025ff970c86ebc01d22.zip
fix safety for sentinel-slicing floats
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 01a15b5f2c..1455b4b743 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -1425,7 +1425,12 @@ static void add_sentinel_check(CodeGen *g, LLVMValueRef sentinel_elem_ptr, ZigVa
LLVMValueRef expected_sentinel = gen_const_val(g, sentinel, "");
LLVMValueRef actual_sentinel = gen_load_untyped(g, sentinel_elem_ptr, 0, false, "");
- LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, actual_sentinel, expected_sentinel, "");
+ LLVMValueRef ok_bit;
+ if (sentinel->type->id == ZigTypeIdFloat) {
+ ok_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, actual_sentinel, expected_sentinel, "");
+ } else {
+ ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, actual_sentinel, expected_sentinel, "");
+ }
LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "SentinelFail");
LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "SentinelOk");