aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-08-09 20:31:11 +0100
committergingerBill <bill@gingerbill.org>2019-08-09 20:31:11 +0100
commit65d41d4248b61e6ef79ed02c2ce4f3be305149a5 (patch)
treeff48b29752f44d61a59486139e2ece9289e3bdac /src
parentb04231dd95b6a80789b5e8762a51db4506948da1 (diff)
Fix bit_field comparison against nil #414
Diffstat (limited to 'src')
-rw-r--r--src/checker.cpp1
-rw-r--r--src/ir.cpp9
2 files changed, 10 insertions, 0 deletions
diff --git a/src/checker.cpp b/src/checker.cpp
index ba13b2237..45b661a58 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -1615,6 +1615,7 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
str_lit("udivti3"),
str_lit("memory_compare"),
+ str_lit("memory_compare_zero"),
};
for (isize i = 0; i < gb_count_of(required_runtime_entities); i++) {
add_dependency_to_set(c, scope_lookup(c->info.runtime_package->scope, required_runtime_entities[i]));
diff --git a/src/ir.cpp b/src/ir.cpp
index 0a5dc7528..ee67c0ea8 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -4017,6 +4017,15 @@ irValue *ir_emit_comp_against_nil(irProcedure *proc, TokenKind op_kind, irValue
} else if (is_type_typeid(t)) {
irValue *invalid_typeid = ir_value_constant(t_typeid, exact_value_i64(0));
return ir_emit_comp(proc, op_kind, x, invalid_typeid);
+ } else if (is_type_bit_field(t)) {
+ auto args = array_make<irValue *>(heap_allocator(), 2);
+ irValue *lhs = ir_address_from_load_or_generate_local(proc, x);
+ args[0] = ir_emit_conv(proc, lhs, t_rawptr);
+ args[1] = ir_const_int(type_size_of(t));
+ irValue *val = ir_emit_runtime_call(proc, "memory_compare_zero", args);
+ irValue *res = ir_emit_comp(proc, op_kind, val, v_zero);
+ return ir_emit_conv(proc, res, t_bool);
+
}
return nullptr;
}