aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-02-28 12:01:26 +0000
committergingerBill <bill@gingerbill.org>2018-02-28 12:01:26 +0000
commit40542e6e2606f9370ce19755ee704ffb24c8921e (patch)
treee6a36a4203b4d293953fb35d699a1480859877b8 /src/ir.cpp
parent9da05dd4cbab364d1fc8260abdc0c980497389b8 (diff)
Fix comparison against `nil` for `cstring`
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 6ab3c9ef7..c4fbf23a6 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -2421,7 +2421,10 @@ irValue *ir_emit_union_tag_value(irProcedure *proc, irValue *u) {
irValue *ir_emit_comp_against_nil(irProcedure *proc, TokenKind op_kind, irValue *x) {
Type *t = ir_type(x);
- if (is_type_any(t)) {
+ if (is_type_cstring(t)) {
+ irValue *ptr = ir_emit_conv(proc, x, t_u8_ptr);
+ return ir_emit_comp(proc, op_kind, ptr, v_raw_nil);
+ } else if (is_type_any(t)) {
irValue *data = ir_emit_struct_ev(proc, x, 0);
irValue *ti = ir_emit_struct_ev(proc, x, 1);
if (op_kind == Token_CmpEq) {
@@ -3130,7 +3133,10 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
return ir_emit(proc, ir_instr_conv(proc, irConv_zext, b, t_llvm_bool, t));
}
- if (src == t_cstring && is_type_u8_ptr(dst)) {
+ if (is_type_cstring(src) && is_type_u8_ptr(dst)) {
+ return ir_emit_bitcast(proc, value, dst);
+ }
+ if (is_type_u8_ptr(src) && is_type_cstring(dst)) {
return ir_emit_bitcast(proc, value, dst);
}