authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-09 14:52:06-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-09 14:52:06-04:00
log010963ce431db2648374368dfc886aa8482494a9
tree5779df01f7f570e9adf8c9e56b7d9217e25a1bf3
parentc459edac18a53854dbfdebe50a370d169e715145
signature Commit is signed but in an unrecognized format.

stage1: make some asserts print source location


3 files changed, 46 insertions(+), 25 deletions(-)

src/analyze.cpp+13
......@@ -7230,3 +7230,16 @@ ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type) {
72307230 assertNoError(type_resolve(g, type, ResolveStatusLLVMFull));
72317231 return type->llvm_di_type;
72327232}
7233
7234void src_assert(bool ok, AstNode *source_node) {
7235 if (ok) return;
7236 if (source_node == nullptr) {
7237 fprintf(stderr, "when analyzing (unknown source location): ");
7238 } else {
7239 fprintf(stderr, "when analyzing %s:%u:%u: ",
7240 buf_ptr(source_node->owner->data.structure.root_struct->path),
7241 (unsigned)source_node->line + 1, (unsigned)source_node->column + 1);
7242 }
7243 const char *msg = "assertion failed";
7244 stage2_panic(msg, strlen(msg));
7245}
src/analyze.hpp+2
......@@ -249,4 +249,6 @@ ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type);
249249
250250void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path, bool translate_c);
251251
252void src_assert(bool ok, AstNode *source_node);
253
252254#endif
src/ir.cpp+31-25
......@@ -7933,6 +7933,11 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction,
79337933 return ir_add_error_node(ira, source_instruction->source_node, msg);
79347934}
79357935
7936static void ir_assert(bool ok, IrInstruction *source_instruction) {
7937 if (ok) return;
7938 src_assert(ok, source_instruction->source_node);
7939}
7940
79367941// This function takes a comptime ptr and makes the child const value conform to the type
79377942// described by the pointer.
79387943static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
......@@ -13944,11 +13949,12 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
1394413949 zig_unreachable();
1394513950}
1394613951
13947static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, ZigFn *fn_entry, ZigType *fn_type,
13948 IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst)
13952static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, ZigFn *fn_entry,
13953 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,
13954 IrInstruction *async_allocator_inst)
1394913955{
1395013956 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);
13951 assert(async_allocator_inst->value.type->id == ZigTypeIdPointer);
13957 ir_assert(async_allocator_inst->value.type->id == ZigTypeIdPointer, &call_instruction->base);
1395213958 ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type;
1395313959 IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, realloc_field_name, &call_instruction->base,
1395413960 async_allocator_inst, container_type);
......@@ -13956,7 +13962,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c
1395613962 return ira->codegen->invalid_instruction;
1395713963 }
1395813964 ZigType *ptr_to_realloc_fn_type = field_ptr_inst->value.type;
13959 assert(ptr_to_realloc_fn_type->id == ZigTypeIdPointer);
13965 ir_assert(ptr_to_realloc_fn_type->id == ZigTypeIdPointer, &call_instruction->base);
1396013966
1396113967 ZigType *realloc_fn_type = ptr_to_realloc_fn_type->data.pointer.child_type;
1396213968 if (realloc_fn_type->id != ZigTypeIdFn) {
......@@ -21227,10 +21233,10 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2122721233 if (type_is_invalid(end_value->value.type))
2122821234 return ira->codegen->invalid_instruction;
2122921235
21230 assert(start_value->value.type->id == ZigTypeIdErrorSet);
21236 ir_assert(start_value->value.type->id == ZigTypeIdErrorSet, &instruction->base);
2123121237 uint32_t start_index = start_value->value.data.x_err_set->value;
2123221238
21233 assert(end_value->value.type->id == ZigTypeIdErrorSet);
21239 ir_assert(end_value->value.type->id == ZigTypeIdErrorSet, &instruction->base);
2123421240 uint32_t end_index = end_value->value.data.x_err_set->value;
2123521241
2123621242 if (start_index != end_index) {
......@@ -21755,7 +21761,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod
2175521761
2175621762static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val) {
2175721763 Error err;
21758 assert(val->special == ConstValSpecialStatic);
21764 src_assert(val->special == ConstValSpecialStatic, source_node);
2175921765 switch (val->type->id) {
2176021766 case ZigTypeIdInvalid:
2176121767 case ZigTypeIdMetaType:
......@@ -21805,7 +21811,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2180521811 zig_panic("TODO buf_read_value_bytes enum packed");
2180621812 case ContainerLayoutExtern: {
2180721813 ZigType *tag_int_type = val->type->data.enumeration.tag_int_type;
21808 assert(tag_int_type->id == ZigTypeIdInt);
21814 src_assert(tag_int_type->id == ZigTypeIdInt, source_node);
2180921815 bigint_read_twos_complement(&val->data.x_enum_tag, buf, tag_int_type->data.integral.bit_count,
2181021816 codegen->is_big_endian, tag_int_type->data.integral.is_signed);
2181121817 return ErrorNone;
......@@ -21860,7 +21866,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2186021866 bigint_read_twos_complement(&big_int, buf + offset, big_int_byte_count * 8, is_big_endian, false);
2186121867 while (src_i < src_field_count) {
2186221868 TypeStructField *field = &val->type->data.structure.fields[src_i];
21863 assert(field->gen_index != SIZE_MAX);
21869 src_assert(field->gen_index != SIZE_MAX, source_node);
2186421870 if (field->gen_index != gen_i)
2186521871 break;
2186621872 ConstExprValue *field_val = &val->data.x_struct.fields[src_i];
......@@ -21936,10 +21942,10 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
2193621942 Error err;
2193721943
2193821944 ZigType *src_type = value->value.type;
21939 assert(get_codegen_ptr_type(src_type) == nullptr);
21940 assert(type_can_bit_cast(src_type));
21941 assert(get_codegen_ptr_type(dest_type) == nullptr);
21942 assert(type_can_bit_cast(dest_type));
21945 ir_assert(get_codegen_ptr_type(src_type) == nullptr, source_instr);
21946 ir_assert(type_can_bit_cast(src_type), source_instr);
21947 ir_assert(get_codegen_ptr_type(dest_type) == nullptr, source_instr);
21948 ir_assert(type_can_bit_cast(dest_type), source_instr);
2194321949
2194421950 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusSizeKnown)))
2194521951 return ira->codegen->invalid_instruction;
......@@ -22029,8 +22035,8 @@ static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruct
2202922035static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
2203022036 ZigType *ptr_type)
2203122037{
22032 assert(get_src_ptr_type(ptr_type) != nullptr);
22033 assert(type_has_bits(ptr_type));
22038 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);
22039 ir_assert(type_has_bits(ptr_type), source_instr);
2203422040
2203522041 IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
2203622042 if (type_is_invalid(casted_int->value.type))
......@@ -22129,7 +22135,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
2212922135 case TldIdFn: {
2213022136 TldFn *tld_fn = (TldFn *)tld;
2213122137 ZigFn *fn_entry = tld_fn->fn_entry;
22132 assert(fn_entry->type_entry);
22138 ir_assert(fn_entry->type_entry, &instruction->base);
2213322139
2213422140 if (tld_fn->extern_lib_name != nullptr) {
2213522141 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, instruction->base.source_node);
......@@ -22327,7 +22333,7 @@ static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruct
2232722333 ZigType *result_type = fn_type_id->param_info[arg_index].type;
2232822334 if (result_type == nullptr) {
2232922335 // Args are only unresolved if our function is generic.
22330 assert(fn_type->data.fn.is_generic);
22336 ir_assert(fn_type->data.fn.is_generic, &instruction->base);
2233122337
2233222338 ir_add_error(ira, arg_index_inst,
2233322339 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",
......@@ -22413,7 +22419,7 @@ static IrInstruction *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstru
2241322419 return ira->codegen->invalid_instruction;
2241422420
2241522421 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
22416 assert(fn_entry != nullptr);
22422 ir_assert(fn_entry != nullptr, &instruction->base);
2241722423 IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
2241822424 coro_id, coro_mem_ptr);
2241922425 result->value.type = get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type);
......@@ -22651,7 +22657,7 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
2265122657 }
2265222658
2265322659 if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) {
22654 assert(instruction->ordering != nullptr);
22660 ir_assert(instruction->ordering != nullptr, &instruction->base);
2265522661 ir_add_error(ira, instruction->ordering,
2265622662 buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel"));
2265722663 return ira->codegen->invalid_instruction;
......@@ -22659,7 +22665,7 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
2265922665
2266022666 if (instr_is_comptime(casted_ptr)) {
2266122667 IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr);
22662 assert(result->value.type != nullptr);
22668 ir_assert(result->value.type != nullptr, &instruction->base);
2266322669 return result;
2266422670 }
2266522671
......@@ -22689,7 +22695,7 @@ static IrInstruction *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, I
2268922695 return ira->codegen->invalid_instruction;
2269022696
2269122697 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
22692 assert(fn_entry != nullptr);
22698 ir_assert(fn_entry != nullptr, &instruction->base);
2269322699
2269422700 if (type_can_fail(promise_result_type)) {
2269522701 fn_entry->calls_or_awaits_errorable_fn = true;
......@@ -22705,9 +22711,9 @@ static IrInstruction *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira
2270522711 if (type_is_invalid(coro_promise_ptr->value.type))
2270622712 return ira->codegen->invalid_instruction;
2270722713
22708 assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer);
22714 ir_assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer, &instruction->base);
2270922715 ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type;
22710 assert(promise_frame_type->id == ZigTypeIdStruct);
22716 ir_assert(promise_frame_type->id == ZigTypeIdStruct, &instruction->base);
2271122717 ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry;
2271222718
2271322719 if (!type_can_fail(promise_result_type)) {
......@@ -22799,7 +22805,7 @@ static IrInstruction *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionS
2279922805 return result;
2280022806 }
2280122807
22802 assert(float_type->id == ZigTypeIdFloat);
22808 ir_assert(float_type->id == ZigTypeIdFloat, &instruction->base);
2280322809 if (float_type->data.floating.bit_count != 16 &&
2280422810 float_type->data.floating.bit_count != 32 &&
2280522811 float_type->data.floating.bit_count != 64) {
......@@ -23290,7 +23296,7 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio
2329023296
2329123297static IrInstruction *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *old_instruction) {
2329223298 IrInstruction *new_instruction = ir_analyze_instruction_nocast(ira, old_instruction);
23293 assert(new_instruction->value.type != nullptr);
23299 ir_assert(new_instruction->value.type != nullptr, old_instruction);
2329423300 old_instruction->child = new_instruction;
2329523301 return new_instruction;
2329623302}