aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-03-18 11:19:24 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-03-19 09:53:55 -0400
commite947f0c7409c719377ca08fb09ec72a558a60d99 (patch)
tree36d3fc5ed977837dcd57feaef56b7f57b03b8ec4
parent72a261b4d35b4f720e189150eb5e73e0fa52ae35 (diff)
downloadzig-e947f0c7409c719377ca08fb09ec72a558a60d99.tar.gz
zig-e947f0c7409c719377ca08fb09ec72a558a60d99.zip
0-bit array type does not resolve child type
-rw-r--r--src/analyze.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 1f511fa834..77d3f33331 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -780,6 +780,8 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa
}
ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ZigValue *sentinel) {
+ Error err;
+
TypeId type_id = {};
type_id.id = ZigTypeIdArray;
type_id.data.array.codegen = g;
@@ -791,8 +793,9 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, Zi
return existing_entry->value;
}
- Error err;
- if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {
+ size_t full_array_size = array_size + ((sentinel != nullptr) ? 1 : 0);
+
+ if (full_array_size != 0 && (err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {
codegen_report_errors_and_exit(g);
}
@@ -806,9 +809,8 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, Zi
}
buf_appendf(&entry->name, "]%s", buf_ptr(&child_type->name));
- size_t full_array_size = array_size + ((sentinel != nullptr) ? 1 : 0);
entry->size_in_bits = child_type->size_in_bits * full_array_size;
- entry->abi_align = child_type->abi_align;
+ entry->abi_align = (full_array_size == 0) ? 0 : child_type->abi_align;
entry->abi_size = child_type->abi_size * full_array_size;
entry->data.array.child_type = child_type;