Commit 11a6550324
Changed files (16)
src/all_types.hpp
@@ -277,7 +277,7 @@ struct TldVar {
VariableTableEntry *var;
AstNode *set_global_align_node;
- uint64_t alignment;
+ uint32_t alignment;
AstNode *set_global_section_node;
Buf *section_name;
AstNode *set_global_linkage_node;
@@ -888,7 +888,7 @@ struct TypeTableEntryPointer {
};
struct TypeTableEntryInt {
- size_t bit_count;
+ uint32_t bit_count;
bool is_signed;
};
@@ -1146,7 +1146,7 @@ struct FnTableEntry {
ZigList<VariableTableEntry *> variable_list;
AstNode *set_global_align_node;
- uint64_t alignment;
+ uint32_t alignment;
AstNode *set_global_section_node;
Buf *section_name;
AstNode *set_global_linkage_node;
@@ -1251,7 +1251,7 @@ struct TypeId {
} array;
struct {
bool is_signed;
- uint8_t bit_count;
+ uint32_t bit_count;
} integer;
} data;
};
src/analyze.cpp
@@ -163,7 +163,7 @@ static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *so
// TODO no reason to limit to 8/16/32/64
-static size_t bits_needed_for_unsigned(uint64_t x) {
+static uint8_t bits_needed_for_unsigned(uint64_t x) {
if (x <= UINT8_MAX) {
return 8;
} else if (x <= UINT16_MAX) {
@@ -578,13 +578,14 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t
buf_appendf(&entry->name, "[%" PRIu64 "]%s", array_size, buf_ptr(&child_type->name));
if (!entry->zero_bits) {
- entry->type_ref = child_type->type_ref ? LLVMArrayType(child_type->type_ref, array_size) : nullptr;
+ entry->type_ref = child_type->type_ref ? LLVMArrayType(child_type->type_ref,
+ (unsigned int)array_size) : nullptr;
uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref);
uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, entry->type_ref);
entry->di_type = ZigLLVMCreateDebugArrayType(g->dbuilder, debug_size_in_bits,
- debug_align_in_bits, child_type->di_type, array_size);
+ debug_align_in_bits, child_type->di_type, (int)array_size);
}
entry->data.array.child_type = child_type;
entry->data.array.len = array_size;
@@ -911,9 +912,9 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
fn_type->data.fn.gen_param_count = gen_param_index;
fn_type->data.fn.raw_type_ref = LLVMFunctionType(gen_return_type->type_ref,
- gen_param_types, gen_param_index, fn_type_id->is_var_args);
+ gen_param_types, (unsigned int)gen_param_index, fn_type_id->is_var_args);
fn_type->type_ref = LLVMPointerType(fn_type->data.fn.raw_type_ref, 0);
- fn_type->di_type = ZigLLVMCreateSubroutineType(g->dbuilder, param_di_types, gen_param_index + 1, 0);
+ fn_type->di_type = ZigLLVMCreateSubroutineType(g->dbuilder, param_di_types, (int)(gen_param_index + 1), 0);
}
g->fn_type_table.put(&fn_type->data.fn.fn_type_id, fn_type);
@@ -954,13 +955,13 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKi
break;
}
- unsigned line = decl_node ? decl_node->line : 0;
+ size_t line = decl_node ? decl_node->line : 0;
ImportTableEntry *import = get_scope_import(scope);
entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), name);
entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,
ZigLLVMTag_DW_structure_type(), name,
- ZigLLVMFileToScope(import->di_file), import->di_file, line + 1);
+ ZigLLVMFileToScope(import->di_file), import->di_file, (unsigned)(line + 1));
buf_init_from_str(&entry->name, name);
@@ -1264,7 +1265,7 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
union_inner_di_types[type_enum_field->gen_index] = ZigLLVMCreateDebugMemberType(g->dbuilder,
ZigLLVMTypeToScope(enum_type->di_type), buf_ptr(type_enum_field->name),
- import->di_file, field_node->line + 1,
+ import->di_file, (unsigned)(field_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
0,
@@ -1307,13 +1308,15 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
uint64_t tag_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, tag_type_entry->type_ref);
uint64_t tag_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, tag_type_entry->type_ref);
ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder,
- ZigLLVMTypeToScope(enum_type->di_type), "AnonEnum", import->di_file, decl_node->line + 1,
+ ZigLLVMTypeToScope(enum_type->di_type), "AnonEnum",
+ import->di_file, (unsigned)(decl_node->line + 1),
tag_debug_size_in_bits, tag_debug_align_in_bits, di_enumerators, field_count,
tag_type_entry->di_type, "");
// create debug type for union
ZigLLVMDIType *union_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,
- ZigLLVMTypeToScope(enum_type->di_type), "AnonUnion", import->di_file, decl_node->line + 1,
+ ZigLLVMTypeToScope(enum_type->di_type), "AnonUnion",
+ import->di_file, (unsigned)(decl_node->line + 1),
biggest_union_member_size_in_bits, biggest_align_in_bits, 0, union_inner_di_types,
gen_field_count, 0, "");
@@ -1321,7 +1324,7 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
uint64_t tag_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, enum_type->type_ref, 0);
ZigLLVMDIType *tag_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder,
ZigLLVMTypeToScope(enum_type->di_type), "tag_field",
- import->di_file, decl_node->line + 1,
+ import->di_file, (unsigned)(decl_node->line + 1),
tag_debug_size_in_bits,
tag_debug_align_in_bits,
tag_offset_in_bits,
@@ -1330,7 +1333,7 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
uint64_t union_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, enum_type->type_ref, 1);
ZigLLVMDIType *union_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder,
ZigLLVMTypeToScope(enum_type->di_type), "union_field",
- import->di_file, decl_node->line + 1,
+ import->di_file, (unsigned)(decl_node->line + 1),
biggest_union_member_size_in_bits,
biggest_align_in_bits,
union_offset_in_bits,
@@ -1348,7 +1351,7 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
ZigLLVMFileToScope(import->di_file),
buf_ptr(&enum_type->name),
- import->di_file, decl_node->line + 1,
+ import->di_file, (unsigned)(decl_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
0, nullptr, di_root_members, 2, 0, nullptr, "");
@@ -1364,7 +1367,7 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
uint64_t tag_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, tag_type_entry->type_ref);
ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder,
ZigLLVMFileToScope(import->di_file), buf_ptr(&enum_type->name),
- import->di_file, decl_node->line + 1,
+ import->di_file, (unsigned)(decl_node->line + 1),
tag_debug_size_in_bits,
tag_debug_align_in_bits,
di_enumerators, field_count,
@@ -1499,7 +1502,7 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
type_struct_field->unaligned_bit_count = field_size_in_bits;
size_t full_bit_count = next_packed_bits_offset - first_packed_bits_offset_misalign;
- LLVMTypeRef int_type_ref = LLVMIntType(full_bit_count);
+ LLVMTypeRef int_type_ref = LLVMIntType((unsigned)(full_bit_count));
if (8 * LLVMStoreSizeOfType(g->target_data_ref, int_type_ref) == full_bit_count) {
// next field recovers store alignment
element_types[gen_field_index] = int_type_ref;
@@ -1529,9 +1532,9 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
}
if (first_packed_bits_offset_misalign != SIZE_MAX) {
size_t full_bit_count = packed_bits_offset - first_packed_bits_offset_misalign;
- LLVMTypeRef int_type_ref = LLVMIntType(full_bit_count);
+ LLVMTypeRef int_type_ref = LLVMIntType((unsigned)full_bit_count);
size_t store_bit_count = 8 * LLVMStoreSizeOfType(g->target_data_ref, int_type_ref);
- element_types[gen_field_index] = LLVMIntType(store_bit_count);
+ element_types[gen_field_index] = LLVMIntType((unsigned)store_bit_count);
gen_field_index += 1;
}
@@ -1552,9 +1555,9 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
// the count may have been adjusting from packing bit fields
gen_field_count = gen_field_index;
- struct_type->data.structure.gen_field_count = gen_field_count;
+ struct_type->data.structure.gen_field_count = (uint32_t)gen_field_count;
- LLVMStructSetBody(struct_type->type_ref, element_types, gen_field_count, packed);
+ LLVMStructSetBody(struct_type->type_ref, element_types, (unsigned)gen_field_count, packed);
assert(LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref) > 0);
ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count);
@@ -1593,15 +1596,16 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
debug_size_in_bits = type_struct_field->packed_bits_size;
debug_align_in_bits = 1;
debug_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, struct_type->type_ref,
- gen_field_index) + type_struct_field->packed_bits_offset;
+ (unsigned)gen_field_index) + type_struct_field->packed_bits_offset;
} else {
debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_type->type_ref);
debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_type->type_ref);
- debug_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, struct_type->type_ref, gen_field_index);
+ debug_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, struct_type->type_ref,
+ (unsigned)gen_field_index);
}
di_element_types[debug_field_index] = ZigLLVMCreateDebugMemberType(g->dbuilder,
ZigLLVMTypeToScope(struct_type->di_type), buf_ptr(type_struct_field->name),
- import->di_file, field_node->line + 1,
+ import->di_file, (unsigned)(field_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
debug_offset_in_bits,
@@ -1616,10 +1620,10 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
ZigLLVMFileToScope(import->di_file),
buf_ptr(&struct_type->name),
- import->di_file, decl_node->line + 1,
+ import->di_file, (unsigned)(decl_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
- 0, nullptr, di_element_types, debug_field_count, 0, nullptr, "");
+ 0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");
ZigLLVMReplaceTemporary(g->dbuilder, struct_type->di_type, replacement_di_type);
struct_type->di_type = replacement_di_type;
@@ -1647,7 +1651,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
assert(enum_type->di_type);
assert(!enum_type->data.enumeration.fields);
- uint32_t field_count = decl_node->data.container_decl.fields.length;
+ uint32_t field_count = (uint32_t)decl_node->data.container_decl.fields.length;
enum_type->data.enumeration.src_field_count = field_count;
enum_type->data.enumeration.fields = allocate<TypeEnumField>(field_count);
@@ -1700,7 +1704,7 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
assert(!struct_type->data.structure.fields);
size_t field_count = decl_node->data.container_decl.fields.length;
- struct_type->data.structure.src_field_count = field_count;
+ struct_type->data.structure.src_field_count = (uint32_t)field_count;
struct_type->data.structure.fields = allocate<TypeStructField>(field_count);
Scope *scope = &struct_type->data.structure.decls_scope->base;
@@ -1729,7 +1733,7 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
}
struct_type->data.structure.zero_bits_loop_flag = false;
- struct_type->data.structure.gen_field_count = gen_field_index;
+ struct_type->data.structure.gen_field_count = (uint32_t)gen_field_index;
struct_type->zero_bits = (gen_field_index == 0);
struct_type->data.structure.zero_bits_known = true;
}
@@ -1985,7 +1989,7 @@ static void preview_error_value_decl(CodeGen *g, AstNode *node) {
} else {
size_t error_value_count = g->error_decls.length;
assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)g->err_tag_type->data.integral.bit_count));
- err->value = error_value_count;
+ err->value = (uint32_t)error_value_count;
g->error_decls.append(node);
g->error_table.put(&err->name, err);
}
@@ -2999,7 +3003,7 @@ bool is_node_void_expr(AstNode *node) {
return false;
}
-TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint8_t size_in_bits) {
+TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
size_t index;
if (size_in_bits == 8) {
index = 0;
@@ -3015,7 +3019,7 @@ TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint8_t size_in_bi
return &g->builtin_types.entry_int[is_signed ? 0 : 1][index];
}
-TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint8_t size_in_bits) {
+TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
TypeTableEntry **common_entry = get_int_type_ptr(g, is_signed, size_in_bits);
if (common_entry)
return *common_entry;
@@ -3104,11 +3108,11 @@ void find_libc_lib_path(CodeGen *g) {
}
static uint32_t hash_ptr(void *ptr) {
- return ((uintptr_t)ptr) % UINT32_MAX;
+ return (uint32_t)(((uintptr_t)ptr) % UINT32_MAX);
}
static uint32_t hash_size(size_t x) {
- return x % UINT32_MAX;
+ return (uint32_t)(x % UINT32_MAX);
}
uint32_t fn_table_entry_hash(FnTableEntry* value) {
@@ -3121,14 +3125,14 @@ bool fn_table_entry_eql(FnTableEntry *a, FnTableEntry *b) {
uint32_t fn_type_id_hash(FnTypeId *id) {
uint32_t result = 0;
- result += id->is_extern ? 3349388391 : 0;
- result += id->is_naked ? 608688877 : 0;
- result += id->is_cold ? 3605523458 : 0;
- result += id->is_var_args ? 1931444534 : 0;
+ result += id->is_extern ? (uint32_t)3349388391 : 0;
+ result += id->is_naked ? (uint32_t)608688877 : 0;
+ result += id->is_cold ? (uint32_t)3605523458 : 0;
+ result += id->is_var_args ? (uint32_t)1931444534 : 0;
result += hash_ptr(id->return_type);
for (size_t i = 0; i < id->param_count; i += 1) {
FnTypeParamInfo *info = &id->param_info[i];
- result += info->is_noalias ? 892356923 : 0;
+ result += info->is_noalias ? (uint32_t)892356923 : 0;
result += hash_ptr(info->type);
}
return result;
@@ -3161,55 +3165,55 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
assert(const_val->special == ConstValSpecialStatic);
switch (const_val->type->id) {
case TypeTableEntryIdBool:
- return const_val->data.x_bool ? 127863866 : 215080464;
+ return const_val->data.x_bool ? (uint32_t)127863866 : (uint32_t)215080464;
case TypeTableEntryIdMetaType:
return hash_ptr(const_val->data.x_type);
case TypeTableEntryIdVoid:
- return 4149439618;
+ return (uint32_t)4149439618;
case TypeTableEntryIdInt:
case TypeTableEntryIdNumLitInt:
case TypeTableEntryIdEnumTag:
- return ((uint32_t)(bignum_to_twos_complement(&const_val->data.x_bignum) % UINT32_MAX)) * 1331471175;
+ return ((uint32_t)(bignum_to_twos_complement(&const_val->data.x_bignum) % UINT32_MAX)) * (uint32_t)1331471175;
case TypeTableEntryIdFloat:
case TypeTableEntryIdNumLitFloat:
- return const_val->data.x_bignum.data.x_float * UINT32_MAX;
+ return (uint32_t)(const_val->data.x_bignum.data.x_float * (uint32_t)UINT32_MAX);
case TypeTableEntryIdArgTuple:
- return const_val->data.x_arg_tuple.start_index * 281907309 +
- const_val->data.x_arg_tuple.end_index * 2290442768;
+ return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 +
+ (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768;
case TypeTableEntryIdPointer:
{
uint32_t hash_val = 0;
switch (const_val->data.x_ptr.mut) {
case ConstPtrMutRuntimeVar:
- hash_val += 3500721036;
+ hash_val += (uint32_t)3500721036;
break;
case ConstPtrMutComptimeConst:
- hash_val += 4214318515;
+ hash_val += (uint32_t)4214318515;
break;
case ConstPtrMutComptimeVar:
- hash_val += 1103195694;
+ hash_val += (uint32_t)1103195694;
break;
}
switch (const_val->data.x_ptr.special) {
case ConstPtrSpecialInvalid:
zig_unreachable();
case ConstPtrSpecialRef:
- hash_val += 2478261866;
+ hash_val += (uint32_t)2478261866;
hash_val += hash_ptr(const_val->data.x_ptr.data.ref.pointee);
return hash_val;
case ConstPtrSpecialBaseArray:
- hash_val += 1764906839;
+ hash_val += (uint32_t)1764906839;
hash_val += hash_ptr(const_val->data.x_ptr.data.base_array.array_val);
hash_val += hash_size(const_val->data.x_ptr.data.base_array.elem_index);
hash_val += const_val->data.x_ptr.data.base_array.is_cstr ? 1297263887 : 200363492;
return hash_val;
case ConstPtrSpecialBaseStruct:
- hash_val += 3518317043;
+ hash_val += (uint32_t)3518317043;
hash_val += hash_ptr(const_val->data.x_ptr.data.base_struct.struct_val);
hash_val += hash_size(const_val->data.x_ptr.data.base_struct.field_index);
return hash_val;
case ConstPtrSpecialHardCodedAddr:
- hash_val += 4048518294;
+ hash_val += (uint32_t)4048518294;
hash_val += hash_size(const_val->data.x_ptr.data.hard_coded_addr.addr);
return hash_val;
case ConstPtrSpecialDiscard:
@@ -3954,7 +3958,7 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
ConstExprValue *child_value = &const_val->data.x_array.elements[i];
uint64_t big_c = child_value->data.x_bignum.data.x_uint;
assert(big_c <= UINT8_MAX);
- uint8_t c = big_c;
+ uint8_t c = (uint8_t)big_c;
if (c == '"') {
buf_append_str(buf, "\\\"");
} else {
@@ -4051,14 +4055,14 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
zig_unreachable();
}
-TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, size_t size_in_bits) {
+TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
entry->is_copyable = true;
entry->type_ref = LLVMIntType(size_in_bits);
const char u_or_i = is_signed ? 'i' : 'u';
buf_resize(&entry->name, 0);
- buf_appendf(&entry->name, "%c%zu", u_or_i, size_in_bits);
+ buf_appendf(&entry->name, "%c%" PRIu8, u_or_i, size_in_bits);
unsigned dwarf_tag;
if (is_signed) {
@@ -4111,16 +4115,16 @@ uint32_t type_id_hash(TypeId x) {
zig_unreachable();
case TypeTableEntryIdPointer:
return hash_ptr(x.data.pointer.child_type) +
- (x.data.pointer.is_const ? 2749109194 : 4047371087) +
- (x.data.pointer.is_volatile ? 536730450 : 1685612214) +
- (((uint32_t)x.data.pointer.bit_offset) * 2639019452) +
- (((uint32_t)x.data.pointer.unaligned_bit_count) * 529908881);
+ (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +
+ (x.data.pointer.is_volatile ? (uint32_t)536730450 : (uint32_t)1685612214) +
+ (((uint32_t)x.data.pointer.bit_offset) * (uint32_t)2639019452) +
+ (((uint32_t)x.data.pointer.unaligned_bit_count) * (uint32_t)529908881);
case TypeTableEntryIdArray:
return hash_ptr(x.data.array.child_type) +
- (x.data.array.size * 2122979968);
+ ((uint32_t)x.data.array.size * (uint32_t)2122979968);
case TypeTableEntryIdInt:
- return (x.data.integer.is_signed ? 2652528194 : 163929201) +
- (((uint32_t)x.data.integer.bit_count) * 2998081557);
+ return (x.data.integer.is_signed ? (uint32_t)2652528194 : (uint32_t)163929201) +
+ (((uint32_t)x.data.integer.bit_count) * (uint32_t)2998081557);
}
zig_unreachable();
}
@@ -4173,13 +4177,13 @@ bool type_id_eql(TypeId a, TypeId b) {
uint32_t zig_llvm_fn_key_hash(ZigLLVMFnKey x) {
switch (x.id) {
case ZigLLVMFnIdCtz:
- return x.data.ctz.bit_count * 810453934;
+ return (uint32_t)(x.data.ctz.bit_count) * (uint32_t)810453934;
case ZigLLVMFnIdClz:
- return x.data.clz.bit_count * 2428952817;
+ return (uint32_t)(x.data.clz.bit_count) * (uint32_t)2428952817;
case ZigLLVMFnIdOverflowArithmetic:
- return (x.data.overflow_arithmetic.bit_count * 87135777) +
- (x.data.overflow_arithmetic.add_sub_mul * 31640542) +
- (x.data.overflow_arithmetic.is_signed ? 1062315172 : 314955820);
+ return ((uint32_t)(x.data.overflow_arithmetic.bit_count) * 87135777) +
+ ((uint32_t)(x.data.overflow_arithmetic.add_sub_mul) * 31640542) +
+ ((uint32_t)(x.data.overflow_arithmetic.is_signed) ? 1062315172 : 314955820);
}
zig_unreachable();
}
src/analyze.hpp
@@ -20,8 +20,8 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
bool is_node_void_expr(AstNode *node);
uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry);
-TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint8_t size_in_bits);
-TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint8_t size_in_bits);
+TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_bits);
+TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);
TypeTableEntry *get_typedecl_type(CodeGen *g, const char *name, TypeTableEntry *child_type);
@@ -146,7 +146,7 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_
void init_const_undefined(CodeGen *g, ConstExprValue *const_val);
-TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, size_t size_in_bits);
+TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
ConstParent *get_const_val_parent(ConstExprValue *value);
FnTableEntry *get_extern_panic_fn(CodeGen *g);
TypeTableEntry *create_enum_tag_type(CodeGen *g, TypeTableEntry *enum_type, TypeTableEntry *int_type);
src/ast_render.cpp
@@ -409,8 +409,8 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
fprintf(ar->f, "%s%s%sfn ", pub_str, inline_str, extern_str);
print_symbol(ar, node->data.fn_proto.name);
fprintf(ar->f, "(");
- int arg_count = node->data.fn_proto.params.length;
- for (int arg_i = 0; arg_i < arg_count; arg_i += 1) {
+ size_t arg_count = node->data.fn_proto.params.length;
+ for (size_t arg_i = 0; arg_i < arg_count; arg_i += 1) {
AstNode *param_decl = node->data.fn_proto.params.at(arg_i);
assert(param_decl->type == NodeTypeParamDecl);
if (buf_len(param_decl->data.param_decl.name) > 0) {
src/bignum.cpp
@@ -154,7 +154,7 @@ void bignum_cast_to_float(BigNum *dest, BigNum *op) {
assert(op->kind == BigNumKindInt);
dest->kind = BigNumKindFloat;
- dest->data.x_float = op->data.x_uint;
+ dest->data.x_float = (double)op->data.x_uint;
if (op->is_negative) {
dest->data.x_float = -dest->data.x_float;
@@ -166,10 +166,10 @@ void bignum_cast_to_int(BigNum *dest, BigNum *op) {
dest->kind = BigNumKindInt;
if (op->data.x_float >= 0) {
- dest->data.x_uint = op->data.x_float;
+ dest->data.x_uint = (unsigned long long)op->data.x_float;
dest->is_negative = false;
} else {
- dest->data.x_uint = -op->data.x_float;
+ dest->data.x_uint = (unsigned long long)-op->data.x_float;
dest->is_negative = true;
}
}
src/buffer.hpp
@@ -169,7 +169,7 @@ uint32_t buf_hash(Buf *buf);
static inline void buf_upcase(Buf *buf) {
for (size_t i = 0; i < buf_len(buf); i += 1) {
- buf_ptr(buf)[i] = toupper(buf_ptr(buf)[i]);
+ buf_ptr(buf)[i] = (char)toupper(buf_ptr(buf)[i]);
}
}
src/c_tokenizer.cpp
@@ -548,7 +548,7 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
case '6':
case '7':
ctok->state = CTokStateStrOctal;
- ctok->cur_char = *c - '0';
+ ctok->cur_char = (uint8_t)(*c - '0');
ctok->octal_index = 1;
break;
case 'x':
@@ -578,12 +578,12 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
if (((long)ctok->cur_char) * 8 >= 256) {
zig_panic("TODO");
}
- ctok->cur_char *= 8;
+ ctok->cur_char = (uint8_t)(ctok->cur_char * (uint8_t)8);
// TODO @add_with_overflow
if (((long)ctok->cur_char) + (long)(*c - '0') >= 256) {
zig_panic("TODO");
}
- ctok->cur_char += *c - '0';
+ ctok->cur_char = (uint8_t)(ctok->cur_char + (uint8_t)(*c - '0'));
ctok->octal_index += 1;
if (ctok->octal_index == 3) {
if (ctok->cur_tok->id == CTokIdStrLit) {
src/codegen.cpp
@@ -267,7 +267,7 @@ static void addLLVMAttrStr(LLVMValueRef val, LLVMAttributeIndex attr_index,
const char *attr_name, const char *attr_val)
{
LLVMAttributeRef llvm_attr = LLVMCreateStringAttribute(LLVMGetGlobalContext(),
- attr_name, strlen(attr_name), attr_val, strlen(attr_val));
+ attr_name, (unsigned)strlen(attr_name), attr_val, (unsigned)strlen(attr_val));
LLVMAddAttributeAtIndex(val, attr_index, llvm_attr);
}
@@ -384,7 +384,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
LLVMSetSection(fn_table_entry->llvm_value, buf_ptr(fn_table_entry->section_name));
}
if (fn_table_entry->alignment) {
- LLVMSetAlignment(fn_table_entry->llvm_value, fn_table_entry->alignment);
+ LLVMSetAlignment(fn_table_entry->llvm_value, (unsigned)fn_table_entry->alignment);
}
return fn_table_entry->llvm_value;
@@ -405,7 +405,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
FnTableEntry *fn_table_entry = fn_scope->fn_entry;
if (!fn_table_entry->proto_node)
return get_di_scope(g, scope->parent);
- unsigned line_number = fn_table_entry->proto_node->line + 1;
+ unsigned line_number = (unsigned)fn_table_entry->proto_node->line + 1;
unsigned scope_line = line_number;
bool is_definition = fn_table_entry->body_node != nullptr;
unsigned flags = 0;
@@ -438,8 +438,8 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder,
get_di_scope(g, scope->parent),
import->di_file,
- scope->source_node->line + 1,
- scope->source_node->column + 1);
+ (unsigned)scope->source_node->line + 1,
+ (unsigned)scope->source_node->column + 1);
scope->di_scope = ZigLLVMLexicalBlockToScope(di_block);
return scope->di_scope;
}
@@ -462,7 +462,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_
assert(type_entry->id == TypeTableEntryIdInt);
const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;
- sprintf(fn_name, "llvm.%s.with.overflow.i%zu", signed_str, type_entry->data.integral.bit_count);
+ sprintf(fn_name, "llvm.%s.with.overflow.i%" PRIu32, signed_str, type_entry->data.integral.bit_count);
LLVMTypeRef return_elem_types[] = {
type_entry->type_ref,
@@ -486,7 +486,7 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
key.id = ZigLLVMFnIdOverflowArithmetic;
key.data.overflow_arithmetic.is_signed = type_entry->data.integral.is_signed;
key.data.overflow_arithmetic.add_sub_mul = add_sub_mul;
- key.data.overflow_arithmetic.bit_count = type_entry->data.integral.bit_count;
+ key.data.overflow_arithmetic.bit_count = (uint32_t)type_entry->data.integral.bit_count;
auto existing_entry = g->llvm_fn_table.maybe_get(key);
if (existing_entry)
@@ -601,8 +601,8 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg) {
TypeTableEntry *str_type = get_slice_type(g, g->builtin_types.entry_u8, true);
size_t ptr_index = str_type->data.structure.fields[slice_ptr_index].gen_index;
size_t len_index = str_type->data.structure.fields[slice_len_index].gen_index;
- LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, msg_arg, ptr_index, "");
- LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, msg_arg, len_index, "");
+ LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, msg_arg, (unsigned)ptr_index, "");
+ LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, msg_arg, (unsigned)len_index, "");
LLVMValueRef args[] = {
LLVMBuildLoad(g->builder, ptr_ptr, ""),
@@ -891,8 +891,8 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry
static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) {
AstNode *source_node = var->decl_node;
- ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc(source_node->line + 1, source_node->column + 1,
- get_di_scope(g, var->parent_scope));
+ ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1,
+ (unsigned)source_node->column + 1, get_di_scope(g, var->parent_scope));
ZigLLVMInsertDeclareAtEnd(g->dbuilder, var->value_ref, var->di_loc_var, debug_loc,
LLVMGetInsertBlock(g->builder));
}
@@ -1272,20 +1272,20 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
TypeTableEntry *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
- size_t actual_ptr_index = actual_type->data.structure.fields[0].gen_index;
- size_t actual_len_index = actual_type->data.structure.fields[1].gen_index;
- size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
- size_t wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
+ size_t actual_ptr_index = actual_type->data.structure.fields[slice_ptr_index].gen_index;
+ size_t actual_len_index = actual_type->data.structure.fields[slice_len_index].gen_index;
+ size_t wanted_ptr_index = wanted_type->data.structure.fields[slice_ptr_index].gen_index;
+ size_t wanted_len_index = wanted_type->data.structure.fields[slice_len_index].gen_index;
- LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, expr_val, actual_ptr_index, "");
+ LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, expr_val, (unsigned)actual_ptr_index, "");
LLVMValueRef src_ptr = LLVMBuildLoad(g->builder, src_ptr_ptr, "");
LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr,
wanted_type->data.structure.fields[0].type_entry->type_ref, "");
LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr,
- wanted_ptr_index, "");
+ (unsigned)wanted_ptr_index, "");
LLVMBuildStore(g->builder, src_ptr_casted, dest_ptr_ptr);
- LLVMValueRef src_len_ptr = LLVMBuildStructGEP(g->builder, expr_val, actual_len_index, "");
+ LLVMValueRef src_len_ptr = LLVMBuildStructGEP(g->builder, expr_val, (unsigned)actual_len_index, "");
LLVMValueRef src_len = LLVMBuildLoad(g->builder, src_len_ptr, "");
uint64_t src_size = type_size(g, actual_child_type);
uint64_t dest_size = type_size(g, wanted_child_type);
@@ -1315,7 +1315,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
}
LLVMValueRef dest_len_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr,
- wanted_len_index, "");
+ (unsigned)wanted_len_index, "");
LLVMBuildStore(g->builder, new_len, dest_len_ptr);
@@ -1333,12 +1333,14 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
- LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr, wanted_ptr_index, "");
+ LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr,
+ (unsigned)wanted_ptr_index, "");
LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, expr_val, wanted_pointer_type->type_ref, "");
LLVMBuildStore(g->builder, src_ptr_casted, dest_ptr_ptr);
size_t wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
- LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr, wanted_len_index, "");
+ LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr,
+ (unsigned)wanted_len_index, "");
LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
actual_type->data.array.len / type_size(g, wanted_child_type), false);
LLVMBuildStore(g->builder, len_val, len_ptr);
@@ -1721,14 +1723,14 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
if (safety_check_on) {
size_t len_index = array_type->data.structure.fields[1].gen_index;
assert(len_index != SIZE_MAX);
- LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, len_index, "");
+ LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)len_index, "");
LLVMValueRef len = LLVMBuildLoad(g->builder, len_ptr, "");
add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len);
}
size_t ptr_index = array_type->data.structure.fields[0].gen_index;
assert(ptr_index != SIZE_MAX);
- LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, ptr_index, "");
+ LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)ptr_index, "");
LLVMValueRef ptr = LLVMBuildLoad(g->builder, ptr_ptr, "");
return LLVMBuildInBoundsGEP(g->builder, ptr, &subscript_value, 1, "");
} else {
@@ -1772,12 +1774,12 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
}
LLVMValueRef result = ZigLLVMBuildCall(g->builder, fn_val,
- gen_param_values, gen_param_index, fn_type->data.fn.calling_convention, "");
+ gen_param_values, (unsigned)gen_param_index, fn_type->data.fn.calling_convention, "");
for (size_t param_i = 0; param_i < fn_type_id->param_count; param_i += 1) {
FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i];
if (gen_info->is_byval) {
- addLLVMCallsiteAttr(result, gen_info->gen_index, "byval");
+ addLLVMCallsiteAttr(result, (unsigned)gen_info->gen_index, "byval");
}
}
@@ -1810,7 +1812,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
}
assert(field->gen_index != SIZE_MAX);
- return LLVMBuildStructGEP(g->builder, struct_ptr, field->gen_index, "");
+ return LLVMBuildStructGEP(g->builder, struct_ptr, (unsigned)field->gen_index, "");
}
static LLVMValueRef ir_render_enum_field_ptr(CodeGen *g, IrExecutable *executable,
@@ -1948,14 +1950,14 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
} else {
ret_type = instruction->base.value.type->type_ref;
}
- LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, input_and_output_count, false);
+ LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false);
bool is_x86 = (g->zig_target.arch.arch == ZigLLVM_x86 || g->zig_target.arch.arch == ZigLLVM_x86_64);
bool is_volatile = asm_expr->is_volatile || (asm_expr->output_list.length == 0);
LLVMValueRef asm_fn = ZigLLVMConstInlineAsm(function_type, buf_ptr(&llvm_template),
buf_ptr(&constraint_buf), is_volatile, false, is_x86);
- return LLVMBuildCall(g->builder, asm_fn, param_values, input_and_output_count, "");
+ return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, "");
}
static LLVMValueRef gen_non_null_bit(CodeGen *g, TypeTableEntry *maybe_type, LLVMValueRef maybe_handle) {
@@ -2021,11 +2023,11 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, Bui
if (fn_id == BuiltinFnIdCtz) {
fn_name = "cttz";
key.id = ZigLLVMFnIdCtz;
- key.data.ctz.bit_count = int_type->data.integral.bit_count;
+ key.data.ctz.bit_count = (uint32_t)int_type->data.integral.bit_count;
} else {
fn_name = "ctlz";
key.id = ZigLLVMFnIdClz;
- key.data.clz.bit_count = int_type->data.integral.bit_count;
+ key.data.clz.bit_count = (uint32_t)int_type->data.integral.bit_count;
}
auto existing_entry = g->llvm_fn_table.maybe_get(key);
@@ -2033,7 +2035,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, Bui
return existing_entry->value;
char llvm_name[64];
- sprintf(llvm_name, "llvm.%s.i%zu", fn_name, int_type->data.integral.bit_count);
+ sprintf(llvm_name, "llvm.%s.i%" PRIu32, fn_name, int_type->data.integral.bit_count);
LLVMTypeRef param_types[] = {
int_type->type_ref,
LLVMInt1Type(),
@@ -2071,7 +2073,8 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru
static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, IrInstructionSwitchBr *instruction) {
LLVMValueRef target_value = ir_llvm_value(g, instruction->target_value);
LLVMBasicBlockRef else_block = instruction->else_block->llvm_block;
- LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, target_value, else_block, instruction->case_count);
+ LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, target_value, else_block,
+ (unsigned)instruction->case_count);
for (size_t i = 0; i < instruction->case_count; i += 1) {
IrInstructionSwitchBrCase *this_case = &instruction->cases[i];
LLVMAddCase(switch_instr, ir_llvm_value(g, this_case->value), this_case->block->llvm_block);
@@ -2097,7 +2100,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru
incoming_values[i] = ir_llvm_value(g, instruction->incoming_values[i]);
incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block;
}
- LLVMAddIncoming(phi, incoming_values, incoming_blocks, instruction->incoming_count);
+ LLVMAddIncoming(phi, incoming_values, incoming_blocks, (unsigned)instruction->incoming_count);
return phi;
}
@@ -2337,14 +2340,14 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
- size_t ptr_index = array_type->data.structure.fields[0].gen_index;
+ size_t ptr_index = array_type->data.structure.fields[slice_ptr_index].gen_index;
assert(ptr_index != SIZE_MAX);
- size_t len_index = array_type->data.structure.fields[1].gen_index;
+ size_t len_index = array_type->data.structure.fields[slice_len_index].gen_index;
assert(len_index != SIZE_MAX);
LLVMValueRef prev_end = nullptr;
if (!instruction->end || want_debug_safety) {
- LLVMValueRef src_len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, len_index, "");
+ LLVMValueRef src_len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)len_index, "");
prev_end = LLVMBuildLoad(g->builder, src_len_ptr, "");
}
@@ -2364,13 +2367,13 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
}
}
- LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, ptr_index, "");
+ LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)ptr_index, "");
LLVMValueRef src_ptr = LLVMBuildLoad(g->builder, src_ptr_ptr, "");
- LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, ptr_index, "");
- LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, src_ptr, &start_val, len_index, "");
+ LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, (unsigned)ptr_index, "");
+ LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, src_ptr, &start_val, (unsigned)len_index, "");
LLVMBuildStore(g->builder, slice_start_ptr, ptr_field_ptr);
- LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, len_index, "");
+ LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, (unsigned)len_index, "");
LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");
LLVMBuildStore(g->builder, len_value, len_field_ptr);
@@ -2650,12 +2653,13 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable,
if (!type_has_bits(type_struct_field->type_entry))
continue;
- LLVMValueRef field_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, type_struct_field->gen_index, "");
+ LLVMValueRef field_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr,
+ (unsigned)type_struct_field->gen_index, "");
LLVMValueRef value = ir_llvm_value(g, field->value);
TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_struct_field->type_entry,
false, false,
- type_struct_field->packed_bits_offset, type_struct_field->unaligned_bit_count);
+ (uint32_t)type_struct_field->packed_bits_offset, (uint32_t)type_struct_field->unaligned_bit_count);
gen_assign_raw(g, field_ptr, ptr_type, value);
}
@@ -2698,7 +2702,8 @@ static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
assert(source_node);
assert(scope);
- ZigLLVMSetCurrentDebugLocation(g->builder, source_node->line + 1, source_node->column + 1, get_di_scope(g, scope));
+ ZigLLVMSetCurrentDebugLocation(g->builder, (int)source_node->line + 1,
+ (int)source_node->column + 1, get_di_scope(g, scope));
}
static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, IrInstruction *instruction) {
@@ -2964,7 +2969,8 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
case TypeTableEntryIdFloat:
{
LLVMValueRef float_val = gen_const_val(g, const_val);
- LLVMValueRef int_val = LLVMConstFPToUI(float_val, LLVMIntType(canon_type->data.floating.bit_count));
+ LLVMValueRef int_val = LLVMConstFPToUI(float_val,
+ LLVMIntType((unsigned)canon_type->data.floating.bit_count));
return LLVMConstZExt(int_val, big_int_type_ref);
}
case TypeTableEntryIdPointer:
@@ -3027,7 +3033,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
if (const_val->data.x_bignum.kind == BigNumKindFloat) {
return LLVMConstReal(canon_type->type_ref, const_val->data.x_bignum.data.x_float);
} else {
- int64_t x = const_val->data.x_bignum.data.x_uint;
+ double x = (double)const_val->data.x_bignum.data.x_uint;
if (const_val->data.x_bignum.is_negative) {
x = -x;
}
@@ -3094,7 +3100,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
gen_const_val(g, &const_val->data.x_struct.fields[src_field_index]);
} else {
LLVMTypeRef big_int_type_ref = LLVMStructGetTypeAtIndex(canon_type->type_ref,
- type_struct_field->gen_index);
+ (unsigned)type_struct_field->gen_index);
LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false);
for (size_t i = src_field_index; i < src_field_index_end; i += 1) {
TypeStructField *it_field = &canon_type->data.structure.fields[i];
@@ -3136,7 +3142,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
ConstExprValue *elem_value = &const_val->data.x_array.elements[i];
values[i] = gen_const_val(g, elem_value);
}
- return LLVMConstArray(LLVMTypeOf(values[0]), values, len);
+ return LLVMConstArray(LLVMTypeOf(values[0]), values, (unsigned)len);
}
case TypeTableEntryIdEnum:
{
@@ -3162,7 +3168,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
} else {
LLVMValueRef fields[] = {
correctly_typed_value,
- LLVMGetUndef(LLVMArrayType(LLVMInt8Type(), pad_bytes)),
+ LLVMGetUndef(LLVMArrayType(LLVMInt8Type(), (unsigned)pad_bytes)),
};
union_value = LLVMConstStruct(fields, 2, false);
}
@@ -3352,7 +3358,7 @@ static bool should_skip_fn_codegen(CodeGen *g, FnTableEntry *fn_entry) {
static LLVMValueRef gen_test_fn_val(CodeGen *g, FnTableEntry *fn_entry) {
// Must match TestFn struct from test_runner.zig
Buf *fn_name = &fn_entry->symbol_name;
- LLVMValueRef str_init = LLVMConstString(buf_ptr(fn_name), buf_len(fn_name), true);
+ LLVMValueRef str_init = LLVMConstString(buf_ptr(fn_name), (unsigned)buf_len(fn_name), true);
LLVMValueRef str_global_val = LLVMAddGlobal(g->module, LLVMTypeOf(str_init), "");
LLVMSetInitializer(str_global_val, str_init);
LLVMSetLinkage(str_global_val, LLVMPrivateLinkage);
@@ -3392,7 +3398,7 @@ static void generate_error_name_table(CodeGen *g) {
assert(error_decl_node->type == NodeTypeErrorValueDecl);
Buf *name = error_decl_node->data.error_value_decl.name;
- LLVMValueRef str_init = LLVMConstString(buf_ptr(name), buf_len(name), true);
+ LLVMValueRef str_init = LLVMConstString(buf_ptr(name), (unsigned)buf_len(name), true);
LLVMValueRef str_global = LLVMAddGlobal(g->module, LLVMTypeOf(str_init), "");
LLVMSetInitializer(str_global, str_init);
LLVMSetLinkage(str_global, LLVMPrivateLinkage);
@@ -3406,7 +3412,7 @@ static void generate_error_name_table(CodeGen *g) {
values[i] = LLVMConstNamedStruct(str_type->type_ref, fields, 2);
}
- LLVMValueRef err_name_table_init = LLVMConstArray(str_type->type_ref, values, g->error_decls.length);
+ LLVMValueRef err_name_table_init = LLVMConstArray(str_type->type_ref, values, (unsigned)g->error_decls.length);
g->err_name_table = LLVMAddGlobal(g->module, LLVMTypeOf(err_name_table_init),
buf_ptr(get_mangled_name(g, buf_create_from_str("err_name_table"), false)));
@@ -3430,7 +3436,7 @@ static void generate_enum_name_tables(CodeGen *g) {
for (size_t field_i = 0; field_i < field_count; field_i += 1) {
Buf *name = enum_type->data.enumeration.fields[field_i].name;
- LLVMValueRef str_init = LLVMConstString(buf_ptr(name), buf_len(name), true);
+ LLVMValueRef str_init = LLVMConstString(buf_ptr(name), (unsigned)buf_len(name), true);
LLVMValueRef str_global = LLVMAddGlobal(g->module, LLVMTypeOf(str_init), "");
LLVMSetInitializer(str_global, str_init);
LLVMSetLinkage(str_global, LLVMPrivateLinkage);
@@ -3444,7 +3450,7 @@ static void generate_enum_name_tables(CodeGen *g) {
values[field_i] = LLVMConstNamedStruct(str_type->type_ref, fields, 2);
}
- LLVMValueRef name_table_init = LLVMConstArray(str_type->type_ref, values, field_count);
+ LLVMValueRef name_table_init = LLVMConstArray(str_type->type_ref, values, (unsigned)field_count);
Buf *table_name = get_mangled_name(g, buf_sprintf("%s_name_table", buf_ptr(&enum_type->name)), false);
LLVMValueRef name_table = LLVMAddGlobal(g->module, LLVMTypeOf(name_table_init), buf_ptr(table_name));
@@ -3478,7 +3484,8 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini
bool is_local_to_unit = true;
ZigLLVMCreateGlobalVariable(g->dbuilder, get_di_scope(g, var->parent_scope), buf_ptr(&var->name),
- buf_ptr(&var->name), import->di_file, var->decl_node->line + 1,
+ buf_ptr(&var->name), import->di_file,
+ (unsigned)(var->decl_node->line + 1),
type_entry->di_type, is_local_to_unit);
// TODO ^^ make an actual global variable
}
@@ -3606,16 +3613,16 @@ static void do_code_gen(CodeGen *g) {
TypeTableEntry *param_type = gen_info->type;
if (param_info->is_noalias) {
- addLLVMArgAttr(fn_val, gen_index, "noalias");
+ addLLVMArgAttr(fn_val, (unsigned)gen_index, "noalias");
}
if ((param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) || is_byval) {
- addLLVMArgAttr(fn_val, gen_index, "readonly");
+ addLLVMArgAttr(fn_val, (unsigned)gen_index, "readonly");
}
if (param_type->id == TypeTableEntryIdPointer) {
- addLLVMArgAttr(fn_val, gen_index, "nonnull");
+ addLLVMArgAttr(fn_val, (unsigned)gen_index, "nonnull");
}
if (is_byval) {
- addLLVMArgAttr(fn_val, gen_index, "byval");
+ addLLVMArgAttr(fn_val, (unsigned)gen_index, "byval");
}
}
@@ -3737,7 +3744,7 @@ static void do_code_gen(CodeGen *g) {
var->value_ref = build_alloca(g, var->value->type, buf_ptr(&var->name));
var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
- buf_ptr(&var->name), import->di_file, var->decl_node->line + 1,
+ buf_ptr(&var->name), import->di_file, (unsigned)(var->decl_node->line + 1),
var->value->type->di_type, !g->strip_debug_symbols, 0);
} else {
@@ -3751,15 +3758,16 @@ static void do_code_gen(CodeGen *g) {
} else {
gen_type = gen_info->type;
}
- var->value_ref = LLVMGetParam(fn, var->gen_arg_index);
+ var->value_ref = LLVMGetParam(fn, (unsigned)var->gen_arg_index);
} else {
gen_type = var->value->type;
var->value_ref = build_alloca(g, var->value->type, buf_ptr(&var->name));
}
if (var->decl_node) {
var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
- buf_ptr(&var->name), import->di_file, var->decl_node->line + 1,
- gen_type->di_type, !g->strip_debug_symbols, 0, var->gen_arg_index + 1);
+ buf_ptr(&var->name), import->di_file,
+ (unsigned)(var->decl_node->line + 1),
+ gen_type->di_type, !g->strip_debug_symbols, 0, (unsigned)(var->gen_arg_index + 1));
}
}
@@ -3784,7 +3792,7 @@ static void do_code_gen(CodeGen *g) {
if (!handle_is_ptr(variable->value->type)) {
clear_debug_source_node(g);
- LLVMBuildStore(g->builder, LLVMGetParam(fn, variable->gen_arg_index), variable->value_ref);
+ LLVMBuildStore(g->builder, LLVMGetParam(fn, (unsigned)variable->gen_arg_index), variable->value_ref);
}
if (variable->decl_node) {
@@ -3827,7 +3835,7 @@ static void do_code_gen(CodeGen *g) {
g->link_objects.append(out_file_o);
}
-static const size_t int_sizes_in_bits[] = {
+static const uint8_t int_sizes_in_bits[] = {
8,
16,
32,
@@ -3950,7 +3958,7 @@ static void define_builtin_types(CodeGen *g) {
}
for (size_t int_size_i = 0; int_size_i < array_length(int_sizes_in_bits); int_size_i += 1) {
- size_t size_in_bits = int_sizes_in_bits[int_size_i];
+ uint8_t size_in_bits = int_sizes_in_bits[int_size_i];
for (size_t is_sign_i = 0; is_sign_i < array_length(is_signed_list); is_sign_i += 1) {
bool is_signed = is_signed_list[is_sign_i];
TypeTableEntry *entry = make_int_type(g, is_signed, size_in_bits);
@@ -3961,7 +3969,7 @@ static void define_builtin_types(CodeGen *g) {
for (size_t i = 0; i < array_length(c_int_type_infos); i += 1) {
const CIntTypeInfo *info = &c_int_type_infos[i];
- uint64_t size_in_bits = get_c_type_size_in_bits(&g->zig_target, info->id);
+ uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id);
bool is_signed = info->is_signed;
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
@@ -4116,7 +4124,7 @@ static void define_builtin_types(CodeGen *g) {
{
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum);
buf_init_from_str(&entry->name, "Os");
- uint32_t field_count = target_os_count();
+ uint32_t field_count = (uint32_t)target_os_count();
entry->data.enumeration.src_field_count = field_count;
entry->data.enumeration.fields = allocate<TypeEnumField>(field_count);
for (uint32_t i = 0; i < field_count; i += 1) {
@@ -4140,7 +4148,7 @@ static void define_builtin_types(CodeGen *g) {
{
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum);
buf_init_from_str(&entry->name, "Arch");
- uint32_t field_count = target_arch_count();
+ uint32_t field_count = (uint32_t)target_arch_count();
entry->data.enumeration.src_field_count = field_count;
entry->data.enumeration.fields = allocate<TypeEnumField>(field_count);
for (uint32_t i = 0; i < field_count; i += 1) {
@@ -4170,7 +4178,7 @@ static void define_builtin_types(CodeGen *g) {
{
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum);
buf_init_from_str(&entry->name, "Environ");
- uint32_t field_count = target_environ_count();
+ uint32_t field_count = (uint32_t)target_environ_count();
entry->data.enumeration.src_field_count = field_count;
entry->data.enumeration.fields = allocate<TypeEnumField>(field_count);
for (uint32_t i = 0; i < field_count; i += 1) {
@@ -4194,7 +4202,7 @@ static void define_builtin_types(CodeGen *g) {
{
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnum);
buf_init_from_str(&entry->name, "ObjectFormat");
- uint32_t field_count = target_oformat_count();
+ uint32_t field_count = (uint32_t)target_oformat_count();
entry->data.enumeration.src_field_count = field_count;
entry->data.enumeration.fields = allocate<TypeEnumField>(field_count);
for (uint32_t i = 0; i < field_count; i += 1) {
@@ -4705,7 +4713,7 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
case TypeTableEntryIdInt:
g->c_want_stdint = true;
buf_resize(out_buf, 0);
- buf_appendf(out_buf, "%sint%zu_t",
+ buf_appendf(out_buf, "%sint%" PRIu32 "_t",
type_entry->data.integral.is_signed ? "" : "u",
type_entry->data.integral.bit_count);
break;
src/ir.cpp
@@ -7295,7 +7295,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
ConstExprValue *char_val = &array_val->data.x_array.elements[new_index];
uint64_t big_c = char_val->data.x_bignum.data.x_uint;
assert(big_c <= UINT8_MAX);
- uint8_t c = big_c;
+ uint8_t c = (uint8_t)big_c;
buf_ptr(result)[i] = c;
}
return result;
@@ -9062,7 +9062,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
return_type = get_pointer_to_type_extra(ira->codegen, child_type,
ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
- bit_offset, bit_width);
+ (uint32_t)bit_offset, (uint32_t)bit_width);
}
} else if (array_type->id == TypeTableEntryIdPointer) {
return_type = array_type;
@@ -9299,7 +9299,8 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field
field->unaligned_bit_count : type_size_bits(ira->codegen, field->type_entry);
ir_build_struct_field_ptr_from(&ira->new_irb, &field_ptr_instruction->base, container_ptr, field);
return get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile,
- ptr_bit_offset + field->packed_bits_offset, unaligned_bit_count_for_result_type);
+ (uint32_t)(ptr_bit_offset + field->packed_bits_offset),
+ (uint32_t)unaligned_bit_count_for_result_type);
} else {
return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
field_ptr_instruction, container_ptr, container_type);
@@ -9759,7 +9760,7 @@ static TypeTableEntry *ir_analyze_instruction_set_global_align(IrAnalyze *ira,
}
AstNode **set_global_align_node;
- uint64_t *alignment_ptr;
+ uint32_t *alignment_ptr;
if (tld->id == TldIdVar) {
TldVar *tld_var = (TldVar *)tld;
set_global_align_node = &tld_var->set_global_align_node;
@@ -9782,7 +9783,7 @@ static TypeTableEntry *ir_analyze_instruction_set_global_align(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_invalid;
}
*set_global_align_node = source_node;
- *alignment_ptr = scalar_align;
+ *alignment_ptr = (uint32_t)scalar_align;
ir_build_const_from(ira, &instruction->base);
return ira->codegen->builtin_types.entry_void;
@@ -11547,7 +11548,7 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_invalid;
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
- out_val->data.x_type = get_int_type(ira->codegen, is_signed, bit_count);
+ out_val->data.x_type = get_int_type(ira->codegen, is_signed, (uint32_t)bit_count);
return ira->codegen->builtin_types.entry_type;
}
src/link.cpp
@@ -503,21 +503,21 @@ static bool darwin_get_release_version(const char *str, int *major, int *minor,
return false;
char *end;
- *major = strtol(str, &end, 10);
+ *major = (int)strtol(str, &end, 10);
if (*str != '\0' && *end == '\0')
return true;
if (*end != '.')
return false;
str = end + 1;
- *minor = strtol(str, &end, 10);
+ *minor = (int)strtol(str, &end, 10);
if (*str != '\0' && *end == '\0')
return true;
if (*end != '.')
return false;
str = end + 1;
- *micro = strtol(str, &end, 10);
+ *micro = (int)strtol(str, &end, 10);
if (*str != '\0' && *end == '\0')
return true;
if (str == end)
src/list.hpp
@@ -69,7 +69,7 @@ struct ZigList {
size_t better_capacity = capacity;
do {
- better_capacity = better_capacity * 1.4 + 8;
+ better_capacity = better_capacity * 5 / 2 + 8;
} while (better_capacity < new_capacity);
items = reallocate_nonzero(items, capacity, better_capacity);
src/os.cpp
@@ -556,7 +556,7 @@ static int os_buf_to_tmp_file_posix(Buf *contents, Buf *suffix, Buf *out_tmp_pat
buf_resize(out_tmp_path, 0);
buf_appendf(out_tmp_path, "%s/XXXXXX%s", tmp_dir, buf_ptr(suffix));
- int fd = mkstemps(buf_ptr(out_tmp_path), buf_len(suffix));
+ int fd = mkstemps(buf_ptr(out_tmp_path), (int)buf_len(suffix));
if (fd < 0) {
return ErrorFileSystem;
}
@@ -629,5 +629,5 @@ int os_delete_file(Buf *path) {
}
void os_init(void) {
- srand(time(NULL));
+ srand((unsigned)time(NULL));
}
src/target.cpp
@@ -161,7 +161,7 @@ size_t target_oformat_count(void) {
return array_length(oformat_list);
}
-const ZigLLVM_ObjectFormatType get_target_oformat(int index) {
+const ZigLLVM_ObjectFormatType get_target_oformat(size_t index) {
return oformat_list[index];
}
@@ -179,7 +179,7 @@ size_t target_arch_count(void) {
return array_length(arch_list);
}
-const ArchType *get_target_arch(int index) {
+const ArchType *get_target_arch(size_t index) {
return &arch_list[index];
}
@@ -187,14 +187,14 @@ size_t target_vendor_count(void) {
return array_length(vendor_list);
}
-ZigLLVM_VendorType get_target_vendor(int index) {
+ZigLLVM_VendorType get_target_vendor(size_t index) {
return vendor_list[index];
}
size_t target_os_count(void) {
return array_length(os_list);
}
-ZigLLVM_OSType get_target_os(int index) {
+ZigLLVM_OSType get_target_os(size_t index) {
return os_list[index];
}
@@ -205,7 +205,7 @@ const char *get_target_os_name(ZigLLVM_OSType os_type) {
size_t target_environ_count(void) {
return array_length(environ_list);
}
-ZigLLVM_EnvironmentType get_target_environ(int index) {
+ZigLLVM_EnvironmentType get_target_environ(size_t index) {
return environ_list[index];
}
@@ -443,7 +443,7 @@ static int get_arch_pointer_bit_width(ZigLLVM_ArchType arch) {
zig_unreachable();
}
-int get_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
+uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
switch (target->os) {
case ZigLLVM_UnknownOS:
switch (id) {
src/target.hpp
@@ -39,22 +39,22 @@ enum CIntType {
};
size_t target_arch_count(void);
-const ArchType *get_target_arch(int index);
+const ArchType *get_target_arch(size_t index);
void get_arch_name(char *out_str, const ArchType *arch);
size_t target_vendor_count(void);
-ZigLLVM_VendorType get_target_vendor(int index);
+ZigLLVM_VendorType get_target_vendor(size_t index);
size_t target_os_count(void);
-ZigLLVM_OSType get_target_os(int index);
+ZigLLVM_OSType get_target_os(size_t index);
const char *get_target_os_name(ZigLLVM_OSType os_type);
size_t target_environ_count(void);
-ZigLLVM_EnvironmentType get_target_environ(int index);
+ZigLLVM_EnvironmentType get_target_environ(size_t index);
size_t target_oformat_count(void);
-const ZigLLVM_ObjectFormatType get_target_oformat(int index);
+const ZigLLVM_ObjectFormatType get_target_oformat(size_t index);
const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat);
void get_native_target(ZigTarget *target);
@@ -70,7 +70,7 @@ void get_target_triple(Buf *triple, const ZigTarget *target);
void resolve_target_object_format(ZigTarget *target);
-int get_c_type_size_in_bits(const ZigTarget *target, CIntType id);
+uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id);
const char *target_o_file_ext(ZigTarget *target);
src/tokenizer.cpp
@@ -309,7 +309,7 @@ static void end_float_token(Tokenize *t) {
if (t->is_exp_negative) {
specified_exponent = -specified_exponent;
}
- t->exponent_in_bin_or_dec += specified_exponent;
+ t->exponent_in_bin_or_dec = (int)(t->exponent_in_bin_or_dec + specified_exponent);
uint64_t significand = t->cur_tok->data.num_lit.bignum.data.x_uint;
uint64_t significand_bits;
@@ -352,7 +352,7 @@ static void end_token(Tokenize *t) {
}
} else if (t->cur_tok->id == TokenIdSymbol) {
char *token_mem = buf_ptr(t->buf) + t->cur_tok->start_pos;
- int token_len = t->cur_tok->end_pos - t->cur_tok->start_pos;
+ int token_len = (int)(t->cur_tok->end_pos - t->cur_tok->start_pos);
for (size_t i = 0; i < array_length(zig_keywords); i += 1) {
if (mem_eql_str(token_mem, token_len, zig_keywords[i].text)) {
@@ -1088,39 +1088,39 @@ void tokenize(Buf *buf, Tokenization *out) {
if (t.unicode) {
if (t.char_code <= 0x7f) {
// 00000000 00000000 00000000 0xxxxxxx
- handle_string_escape(&t, t.char_code);
+ handle_string_escape(&t, (uint8_t)t.char_code);
} else if (t.cur_tok->id == TokenIdCharLiteral) {
tokenize_error(&t, "unicode value too large for character literal: %x", t.char_code);
} else if (t.char_code <= 0x7ff) {
// 00000000 00000000 00000xxx xx000000
- handle_string_escape(&t, 0xc0 | (t.char_code >> 6));
+ handle_string_escape(&t, (uint8_t)(0xc0 | (t.char_code >> 6)));
// 00000000 00000000 00000000 00xxxxxx
- handle_string_escape(&t, 0x80 | (t.char_code & 0x3f));
+ handle_string_escape(&t, (uint8_t)(0x80 | (t.char_code & 0x3f)));
} else if (t.char_code <= 0xffff) {
// 00000000 00000000 xxxx0000 00000000
- handle_string_escape(&t, 0xe0 | (t.char_code >> 12));
+ handle_string_escape(&t, (uint8_t)(0xe0 | (t.char_code >> 12)));
// 00000000 00000000 0000xxxx xx000000
- handle_string_escape(&t, 0x80 | ((t.char_code >> 6) & 0x3f));
+ handle_string_escape(&t, (uint8_t)(0x80 | ((t.char_code >> 6) & 0x3f)));
// 00000000 00000000 00000000 00xxxxxx
- handle_string_escape(&t, 0x80 | (t.char_code & 0x3f));
+ handle_string_escape(&t, (uint8_t)(0x80 | (t.char_code & 0x3f)));
} else if (t.char_code <= 0x10ffff) {
// 00000000 000xxx00 00000000 00000000
- handle_string_escape(&t, 0xf0 | (t.char_code >> 18));
+ handle_string_escape(&t, (uint8_t)(0xf0 | (t.char_code >> 18)));
// 00000000 000000xx xxxx0000 00000000
- handle_string_escape(&t, 0x80 | ((t.char_code >> 12) & 0x3f));
+ handle_string_escape(&t, (uint8_t)(0x80 | ((t.char_code >> 12) & 0x3f)));
// 00000000 00000000 0000xxxx xx000000
- handle_string_escape(&t, 0x80 | ((t.char_code >> 6) & 0x3f));
+ handle_string_escape(&t, (uint8_t)(0x80 | ((t.char_code >> 6) & 0x3f)));
// 00000000 00000000 00000000 00xxxxxx
- handle_string_escape(&t, 0x80 | (t.char_code & 0x3f));
+ handle_string_escape(&t, (uint8_t)(0x80 | (t.char_code & 0x3f)));
} else {
tokenize_error(&t, "unicode value out of range: %x", t.char_code);
}
} else {
- if (t.cur_tok->id == TokenIdCharLiteral && t.char_code >= sizeof(uint8_t)) {
+ if (t.cur_tok->id == TokenIdCharLiteral && t.char_code > UINT8_MAX) {
tokenize_error(&t, "value too large for character literal: '%x'",
t.char_code);
}
- handle_string_escape(&t, t.char_code);
+ handle_string_escape(&t, (uint8_t)t.char_code);
}
}
}
@@ -1396,8 +1396,8 @@ void tokenize(Buf *buf, Tokenization *out) {
if (t.state != TokenizeStateError) {
if (t.tokens->length > 0) {
Token *last_token = &t.tokens->last();
- t.line = last_token->start_line;
- t.column = last_token->start_column;
+ t.line = (int)last_token->start_line;
+ t.column = (int)last_token->start_column;
t.pos = last_token->start_pos;
} else {
t.pos = 0;
src/util.cpp
@@ -36,7 +36,7 @@ bool uint64_eq(uint64_t a, uint64_t b) {
}
uint32_t ptr_hash(const void *ptr) {
- return ((uintptr_t)ptr) % UINT32_MAX;
+ return (uint32_t)(((uintptr_t)ptr) % UINT32_MAX);
}
bool ptr_eq(const void *a, const void *b) {