aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-03-09 20:58:25 +0100
committerAndrew Kelley <andrew@ziglang.org>2020-03-09 22:08:56 -0400
commit1f44b29724b52433d84b43345a52da59f9220e62 (patch)
treea02ff60c378f78fee29d6559d44954b13ce0417a /src/codegen.cpp
parent638d5c3aca7ce1e4fd10060079caa0acb66144c0 (diff)
downloadzig-1f44b29724b52433d84b43345a52da59f9220e62.tar.gz
zig-1f44b29724b52433d84b43345a52da59f9220e62.zip
ir: Fix codegen of ?*T types where T is zero-sized
* Fix codegen for optional types that decay to a pointer, the type behaves as a boolean * Fix comptime evaluation of zero-sized arrays, always initialize the internal array elements Closes #4673
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index a67b8dc00b..22cb975205 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -6902,8 +6902,18 @@ check: switch (const_val->special) {
case ZigTypeIdOptional:
{
ZigType *child_type = type_entry->data.maybe.child_type;
+
if (get_src_ptr_type(type_entry) != nullptr) {
- return gen_const_val_ptr(g, const_val, name);
+ bool has_bits;
+ if ((err = type_has_bits2(g, child_type, &has_bits)))
+ codegen_report_errors_and_exit(g);
+
+ if (has_bits)
+ return gen_const_val_ptr(g, const_val, name);
+
+ // No bits, treat this value as a boolean
+ const unsigned bool_val = optional_value_is_null(const_val) ? 0 : 1;
+ return LLVMConstInt(LLVMInt1Type(), bool_val, false);
} else if (child_type->id == ZigTypeIdErrorSet) {
return gen_const_val_err_set(g, const_val, name);
} else if (!type_has_bits(g, child_type)) {