Fix alignment issues with vectors, unions, and raw_unions

This commit is contained in:
Ginger Bill
2016-11-16 12:36:02 +00:00
parent 0cab083b8f
commit e2d98324ba
6 changed files with 133 additions and 50 deletions
+3 -3
View File
@@ -520,6 +520,9 @@ void init_universal_scope(void) {
entity->Builtin.id = id;
add_global_entity(entity);
}
t_u8_ptr = make_type_pointer(a, t_u8);
t_int_ptr = make_type_pointer(a, t_int);
}
@@ -920,9 +923,6 @@ Map<Entity *> generate_minimum_dependency_map(CheckerInfo *info, Entity *start)
void init_preload_types(Checker *c) {
PROF_PROC();
if (t_u8_ptr == NULL) {
t_u8_ptr = make_type_pointer(c->allocator, t_u8);
}
if (t_type_info == NULL) {
Entity *e = current_scope_lookup_entity(c->global_scope, make_string("Type_Info"));
+7 -3
View File
@@ -820,10 +820,13 @@ Type *check_get_params(Checker *c, Scope *scope, AstNodeArray params, b32 *is_va
}
}
if (is_variadic && params.count > 0) {
variable_count = variable_index;
if (is_variadic) {
GB_ASSERT(params.count > 0);
// NOTE(bill): Change last variadic parameter to be a slice
// Custom Calling convention for variadic parameters
Entity *end = variables[params.count-1];
Entity *end = variables[variable_count-1];
end->type = make_type_slice(c->allocator, end->type);
}
@@ -3458,6 +3461,7 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode
defer (gb_string_free(proc_str));
error(ast_node_token(call), err_fmt, proc_str, param_count);
operand->mode = Addressing_Invalid;
return;
}
GB_ASSERT(proc_type->Proc.params != NULL);
@@ -3467,7 +3471,6 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode
Type *arg_type = sig_params[operand_index]->type;
Operand o = operands[operand_index];
if (variadic) {
o = operands[operand_index];
}
check_assignment(c, &o, arg_type, make_string("argument"), true);
@@ -3476,6 +3479,7 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode
if (variadic) {
b32 variadic_expand = false;
Type *slice = sig_params[param_count]->type;
GB_ASSERT(is_type_slice(slice));
Type *elem = base_type(slice)->Slice.elem;
Type *t = elem;
for (; operand_index < operands.count; operand_index++) {
+17 -16
View File
@@ -364,7 +364,8 @@ gb_global Type *t_byte = &basic_type_aliases[0];
gb_global Type *t_rune = &basic_type_aliases[1];
gb_global Type *t_u8_ptr = NULL;
gb_global Type *t_u8_ptr = NULL;
gb_global Type *t_int_ptr = NULL;
gb_global Type *t_type_info = NULL;
gb_global Type *t_type_info_ptr = NULL;
@@ -908,25 +909,26 @@ Selection lookup_field(gbAllocator a, Type *type_, String field_name, b32 is_typ
sel.entity = make_entity_constant(a, NULL, make_token_ident(count_str), t_int, make_exact_value_integer(type->Vector.count));
return sel;
}
if (type->Vector.count <= 4 && !is_type_boolean(type->Vector.elem)) {
// HACK(bill): Memory leak
switch (type->Vector.count) {
#define _VECTOR_FIELD(_name, length) \
case (length): \
#define _VECTOR_FIELD_CASE(_length, _name) \
case (_length): \
if (field_name == _name) { \
selection_add_index(&sel, (length)-1); \
sel.entity = make_entity_field(a, NULL, make_token_ident(make_string(_name)), type->Vector.elem, false, (length)-1); \
selection_add_index(&sel, (_length)-1); \
sel.entity = make_entity_vector_elem(a, NULL, make_token_ident(make_string(_name)), type->Vector.elem, (_length)-1); \
return sel; \
} \
/*fallthrough*/
_VECTOR_FIELD("w", 4);
_VECTOR_FIELD("z", 3);
_VECTOR_FIELD("y", 2);
_VECTOR_FIELD("x", 1);
case 0: break;
_VECTOR_FIELD_CASE(4, "w");
_VECTOR_FIELD_CASE(3, "z");
_VECTOR_FIELD_CASE(2, "y");
_VECTOR_FIELD_CASE(1, "x");
default: break;
#undef _VECTOR_FIELD
#undef _VECTOR_FIELD_CASE
}
}
@@ -1057,10 +1059,9 @@ i64 type_align_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
return type_align_of(s, allocator, t->Array.elem);
case Type_Vector: {
i64 size = type_size_of(s, allocator, t->Vector.elem);
size *= t->Vector.count;
size = prev_pow2(size);
// TODO(bill): Type_Vector type_align_of
return gb_clamp(size, 1, s.max_align);
i64 count = gb_max(prev_pow2(size), 1);
i64 total = size * count;
return gb_clamp(total, 1, s.max_align);
} break;
case Type_Tuple: {
@@ -1097,7 +1098,7 @@ i64 type_align_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
}
break;
case TypeRecord_Union: {
i64 max = s.word_size;
i64 max = 1;
for (isize i = 1; i < t->Record.field_count; i++) {
// NOTE(bill): field zero is null
i64 align = type_align_of(s, allocator, t->Record.fields[i]->type);