More efficient int[] a = {}; Disallow zero length arrays. Bump to 0.2.19 (#489)

More efficient int[] a = {}; Disallow zero length arrays. Bump to 0.2.19. Improve error on mistyped types.
This commit is contained in:
Christoffer Lerno
2022-07-20 22:25:03 +02:00
committed by GitHub
parent 8afbccd3fe
commit 002ee006c1
14 changed files with 59 additions and 94 deletions

View File

@@ -1060,11 +1060,19 @@ static inline void llvm_emit_initialize_reference(GenContext *c, BEValue *value,
*/
static void llvm_emit_arr_to_subarray_cast(GenContext *c, BEValue *value, Type *to_type)
{
llvm_value_rvalue(c, value);
ByteSize size = value->type->pointer->array.len;
LLVMValueRef pointer;
Type *array_type = value->type->pointer->array.base;
LLVMTypeRef subarray_type = llvm_get_type(c, to_type);
LLVMValueRef pointer = llvm_emit_bitcast(c, value->value, type_get_ptr(array_type));
if (size)
{
llvm_value_rvalue(c, value);
LLVMTypeRef subarray_type = llvm_get_type(c, to_type);
pointer = llvm_emit_bitcast(c, value->value, type_get_ptr(array_type));
}
else
{
pointer = llvm_get_zero(c, type_get_ptr(array_type));
}
LLVMValueRef len = llvm_const_int(c, type_usize, size);
llvm_set_aggregate_two(c, value, to_type, pointer, len);
}