| author | |
| committer | |
| log | c6295fe9abf5508d522ab4000b577a6f30a98a88 |
| tree | de5ff247f235fbf8f9cfe6f8ad2267c897c4d022 |
| parent | 6db589fff5be05e3e782a34443a1133ebc6ef17d |
adds test case for #394
partially reverts a32b5929ccf8cbf79396d8924097a1a911985dac13 files changed, 109 insertions(+), 122 deletions(-)
CMakeLists.txt+1-1| ... | ... | @@ -585,8 +585,8 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/special/compiler_rt/udivmod.zig" DESTINAT |
| 585 | 585 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/compiler_rt/udivmoddi4.zig" DESTINATION "${ZIG_STD_DEST}/special/compiler_rt") |
| 586 | 586 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/compiler_rt/udivmodti4.zig" DESTINATION "${ZIG_STD_DEST}/special/compiler_rt") |
| 587 | 587 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/compiler_rt/umodti3.zig" DESTINATION "${ZIG_STD_DEST}/special/compiler_rt") |
| 588 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/panic.zig" DESTINATION "${ZIG_STD_DEST}/special") | |
| 588 | 589 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/test_runner.zig" DESTINATION "${ZIG_STD_DEST}/special") |
| 589 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/zigrt.zig" DESTINATION "${ZIG_STD_DEST}/special") | |
| 590 | 590 | |
| 591 | 591 | if (ZIG_TEST_COVERAGE) |
| 592 | 592 | add_custom_target(coverage |
src/all_types.hpp+2-4| ... | ... | @@ -1472,7 +1472,7 @@ struct CodeGen { |
| 1472 | 1472 | bool is_native_target; |
| 1473 | 1473 | PackageTableEntry *root_package; |
| 1474 | 1474 | PackageTableEntry *std_package; |
| 1475 | PackageTableEntry *zigrt_package; | |
| 1475 | PackageTableEntry *panic_package; | |
| 1476 | 1476 | PackageTableEntry *test_runner_package; |
| 1477 | 1477 | PackageTableEntry *compile_var_package; |
| 1478 | 1478 | ImportTableEntry *compile_var_import; |
| ... | ... | @@ -1484,7 +1484,6 @@ struct CodeGen { |
| 1484 | 1484 | Buf *mios_version_min; |
| 1485 | 1485 | bool linker_rdynamic; |
| 1486 | 1486 | const char *linker_script; |
| 1487 | bool omit_zigrt; | |
| 1488 | 1487 | |
| 1489 | 1488 | // The function definitions this module includes. There must be a corresponding |
| 1490 | 1489 | // fn_protos entry. |
| ... | ... | @@ -1498,8 +1497,7 @@ struct CodeGen { |
| 1498 | 1497 | OutType out_type; |
| 1499 | 1498 | FnTableEntry *cur_fn; |
| 1500 | 1499 | FnTableEntry *main_fn; |
| 1501 | FnTableEntry *user_panic_fn; | |
| 1502 | FnTableEntry *extern_panic_fn; | |
| 1500 | FnTableEntry *panic_fn; | |
| 1503 | 1501 | LLVMValueRef cur_ret_ptr; |
| 1504 | 1502 | LLVMValueRef cur_fn_val; |
| 1505 | 1503 | bool c_want_stdint; |
src/analyze.cpp+7-48| ... | ... | @@ -2072,11 +2072,10 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 2072 | 2072 | if (fn_def_node) |
| 2073 | 2073 | g->fn_defs.append(fn_table_entry); |
| 2074 | 2074 | |
| 2075 | if (g->have_pub_main && scope_is_root_decls(tld_fn->base.parent_scope) && | |
| 2076 | ((!g->is_test_build && import == g->root_import) || | |
| 2077 | (g->is_test_build && import == g->test_runner_import))) | |
| 2075 | if (scope_is_root_decls(tld_fn->base.parent_scope) && | |
| 2076 | (import == g->root_import || import->package == g->panic_package)) | |
| 2078 | 2077 | { |
| 2079 | if (buf_eql_str(&fn_table_entry->symbol_name, "main")) { | |
| 2078 | if (g->have_pub_main && buf_eql_str(&fn_table_entry->symbol_name, "main")) { | |
| 2080 | 2079 | g->main_fn = fn_table_entry; |
| 2081 | 2080 | |
| 2082 | 2081 | if (tld_fn->base.visib_mod != VisibModExport) { |
| ... | ... | @@ -2088,13 +2087,12 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 2088 | 2087 | buf_ptr(&actual_return_type->name))); |
| 2089 | 2088 | } |
| 2090 | 2089 | } |
| 2091 | } else if (buf_eql_str(&fn_table_entry->symbol_name, "panic")) { | |
| 2090 | } else if ((import->package == g->panic_package || g->have_pub_panic) && | |
| 2091 | buf_eql_str(&fn_table_entry->symbol_name, "panic")) | |
| 2092 | { | |
| 2093 | g->panic_fn = fn_table_entry; | |
| 2092 | 2094 | typecheck_panic_fn(g, fn_table_entry); |
| 2093 | 2095 | } |
| 2094 | } else if (import->package == g->zigrt_package && scope_is_root_decls(tld_fn->base.parent_scope)) { | |
| 2095 | if (buf_eql_str(&fn_table_entry->symbol_name, "__zig_panic")) { | |
| 2096 | g->extern_panic_fn = fn_table_entry; | |
| 2097 | } | |
| 2098 | 2096 | } |
| 2099 | 2097 | } |
| 2100 | 2098 | } else if (source_node->type == NodeTypeTestDecl) { |
| ... | ... | @@ -2272,14 +2270,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 2272 | 2270 | tld_fn->extern_lib_name = node->data.fn_proto.lib_name; |
| 2273 | 2271 | add_top_level_decl(g, decls_scope, &tld_fn->base); |
| 2274 | 2272 | |
| 2275 | ImportTableEntry *import = get_scope_import(&decls_scope->base); | |
| 2276 | if (import == g->root_import && scope_is_root_decls(&decls_scope->base) && | |
| 2277 | buf_eql_str(fn_name, "panic")) | |
| 2278 | { | |
| 2279 | update_compile_var(g, buf_create_from_str("__zig_panic_implementation_provided"), | |
| 2280 | create_const_bool(g, true)); | |
| 2281 | } | |
| 2282 | ||
| 2283 | 2273 | break; |
| 2284 | 2274 | } |
| 2285 | 2275 | case NodeTypeUse: |
| ... | ... | @@ -4606,37 +4596,6 @@ ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) { |
| 4606 | 4596 | return nullptr; |
| 4607 | 4597 | } |
| 4608 | 4598 | |
| 4609 | FnTableEntry *get_extern_panic_fn(CodeGen *g) { | |
| 4610 | if (g->extern_panic_fn) | |
| 4611 | return g->extern_panic_fn; | |
| 4612 | ||
| 4613 | FnTypeId fn_type_id = {0}; | |
| 4614 | fn_type_id.cc = CallingConventionCold; | |
| 4615 | fn_type_id.param_count = 2; | |
| 4616 | fn_type_id.param_info = allocate<FnTypeParamInfo>(2); | |
| 4617 | fn_type_id.next_param_index = 0; | |
| 4618 | fn_type_id.param_info[0].type = get_pointer_to_type(g, g->builtin_types.entry_u8, true); | |
| 4619 | fn_type_id.param_info[1].type = g->builtin_types.entry_usize; | |
| 4620 | fn_type_id.return_type = g->builtin_types.entry_unreachable; | |
| 4621 | ||
| 4622 | TypeTableEntry *fn_type = get_fn_type(g, &fn_type_id); | |
| 4623 | assert(!type_is_invalid(fn_type)); | |
| 4624 | ||
| 4625 | FnTableEntry *fn_entry = create_fn_raw(FnInlineAuto, GlobalLinkageIdStrong); | |
| 4626 | buf_init_from_str(&fn_entry->symbol_name, "__zig_panic"); | |
| 4627 | ||
| 4628 | TldFn *tld_fn = allocate<TldFn>(1); | |
| 4629 | init_tld(&tld_fn->base, TldIdFn, &fn_entry->symbol_name, VisibModPrivate, nullptr, nullptr); | |
| 4630 | tld_fn->fn_entry = fn_entry; | |
| 4631 | ||
| 4632 | g->external_prototypes.put_unique(tld_fn->base.name, &tld_fn->base); | |
| 4633 | ||
| 4634 | fn_entry->type_entry = fn_type; | |
| 4635 | ||
| 4636 | g->extern_panic_fn = fn_entry; | |
| 4637 | return g->extern_panic_fn; | |
| 4638 | } | |
| 4639 | ||
| 4640 | 4599 | static const TypeTableEntryId all_type_ids[] = { |
| 4641 | 4600 | TypeTableEntryIdMetaType, |
| 4642 | 4601 | TypeTableEntryIdVoid, |
src/analyze.hpp-1| ... | ... | @@ -157,7 +157,6 @@ ConstExprValue *create_const_vals(size_t count); |
| 157 | 157 | |
| 158 | 158 | TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); |
| 159 | 159 | ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value); |
| 160 | FnTableEntry *get_extern_panic_fn(CodeGen *g); | |
| 161 | 160 | TypeTableEntry *create_enum_tag_type(CodeGen *g, TypeTableEntry *enum_type, TypeTableEntry *int_type); |
| 162 | 161 | void expand_undef_array(CodeGen *g, ConstExprValue *const_val); |
| 163 | 162 | void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value); |
src/codegen.cpp+49-45| ... | ... | @@ -157,10 +157,6 @@ void codegen_set_llvm_argv(CodeGen *g, const char **args, size_t len) { |
| 157 | 157 | g->llvm_argv_len = len; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | void codegen_set_omit_zigrt(CodeGen *g, bool omit_zigrt) { | |
| 161 | g->omit_zigrt = omit_zigrt; | |
| 162 | } | |
| 163 | ||
| 164 | 160 | void codegen_set_test_filter(CodeGen *g, Buf *filter) { |
| 165 | 161 | g->test_filter = filter; |
| 166 | 162 | } |
| ... | ... | @@ -751,26 +747,12 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) { |
| 751 | 747 | return val->global_refs->llvm_global; |
| 752 | 748 | } |
| 753 | 749 | |
| 754 | static void gen_panic_raw(CodeGen *g, LLVMValueRef msg_ptr, LLVMValueRef msg_len) { | |
| 755 | FnTableEntry *panic_fn = get_extern_panic_fn(g); | |
| 756 | LLVMValueRef fn_val = fn_llvm_value(g, panic_fn); | |
| 757 | LLVMValueRef args[] = { msg_ptr, msg_len }; | |
| 758 | LLVMCallConv llvm_cc = get_llvm_cc(g, panic_fn->type_entry->data.fn.fn_type_id.cc); | |
| 759 | ZigLLVMBuildCall(g->builder, fn_val, args, 2, llvm_cc, false, ""); | |
| 760 | LLVMBuildUnreachable(g->builder); | |
| 761 | } | |
| 762 | ||
| 763 | 750 | static void gen_panic(CodeGen *g, LLVMValueRef msg_arg) { |
| 764 | TypeTableEntry *ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true); | |
| 765 | TypeTableEntry *str_type = get_slice_type(g, ptr_type); | |
| 766 | size_t ptr_index = str_type->data.structure.fields[slice_ptr_index].gen_index; | |
| 767 | size_t len_index = str_type->data.structure.fields[slice_len_index].gen_index; | |
| 768 | LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, msg_arg, (unsigned)ptr_index, ""); | |
| 769 | LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, msg_arg, (unsigned)len_index, ""); | |
| 770 | ||
| 771 | LLVMValueRef msg_ptr = gen_load_untyped(g, ptr_ptr, 0, false, ""); | |
| 772 | LLVMValueRef msg_len = gen_load_untyped(g, len_ptr, 0, false, ""); | |
| 773 | gen_panic_raw(g, msg_ptr, msg_len); | |
| 751 | assert(g->panic_fn != nullptr); | |
| 752 | LLVMValueRef fn_val = fn_llvm_value(g, g->panic_fn); | |
| 753 | LLVMCallConv llvm_cc = get_llvm_cc(g, g->panic_fn->type_entry->data.fn.fn_type_id.cc); | |
| 754 | ZigLLVMBuildCall(g->builder, fn_val, &msg_arg, 1, llvm_cc, false, ""); | |
| 755 | LLVMBuildUnreachable(g->builder); | |
| 774 | 756 | } |
| 775 | 757 | |
| 776 | 758 | static void gen_debug_safety_crash(CodeGen *g, PanicMsgId msg_id) { |
| ... | ... | @@ -818,26 +800,40 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) { |
| 818 | 800 | } |
| 819 | 801 | uint32_t u8_align_bytes = get_abi_alignment(g, g->builtin_types.entry_u8); |
| 820 | 802 | LLVMValueRef init_value = LLVMConstArray(LLVMInt8Type(), err_buf_vals, err_buf_len); |
| 821 | Buf *global_name = get_mangled_name(g, buf_create_from_str("__zig_panic_buf"), false); | |
| 822 | LLVMValueRef global_value = LLVMAddGlobal(g->module, LLVMTypeOf(init_value), buf_ptr(global_name)); | |
| 823 | LLVMSetInitializer(global_value, init_value); | |
| 824 | LLVMSetLinkage(global_value, LLVMInternalLinkage); | |
| 825 | LLVMSetGlobalConstant(global_value, false); | |
| 826 | LLVMSetUnnamedAddr(global_value, true); | |
| 827 | LLVMSetAlignment(global_value, u8_align_bytes); | |
| 803 | LLVMValueRef global_array = LLVMAddGlobal(g->module, LLVMTypeOf(init_value), ""); | |
| 804 | LLVMSetInitializer(global_array, init_value); | |
| 805 | LLVMSetLinkage(global_array, LLVMInternalLinkage); | |
| 806 | LLVMSetGlobalConstant(global_array, false); | |
| 807 | LLVMSetUnnamedAddr(global_array, true); | |
| 808 | LLVMSetAlignment(global_array, u8_align_bytes); | |
| 828 | 809 | |
| 829 | 810 | TypeTableEntry *usize = g->builtin_types.entry_usize; |
| 830 | 811 | LLVMValueRef full_buf_ptr_indices[] = { |
| 831 | 812 | LLVMConstNull(usize->type_ref), |
| 832 | 813 | LLVMConstNull(usize->type_ref), |
| 833 | 814 | }; |
| 834 | LLVMValueRef full_buf_ptr = LLVMConstInBoundsGEP(global_value, full_buf_ptr_indices, 2); | |
| 815 | LLVMValueRef full_buf_ptr = LLVMConstInBoundsGEP(global_array, full_buf_ptr_indices, 2); | |
| 816 | ||
| 817 | ||
| 818 | TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true); | |
| 819 | TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type); | |
| 820 | LLVMValueRef global_slice_fields[] = { | |
| 821 | full_buf_ptr, | |
| 822 | LLVMConstNull(usize->type_ref), | |
| 823 | }; | |
| 824 | LLVMValueRef slice_init_value = LLVMConstNamedStruct(str_type->type_ref, global_slice_fields, 2); | |
| 825 | LLVMValueRef global_slice = LLVMAddGlobal(g->module, LLVMTypeOf(slice_init_value), ""); | |
| 826 | LLVMSetInitializer(global_slice, slice_init_value); | |
| 827 | LLVMSetLinkage(global_slice, LLVMInternalLinkage); | |
| 828 | LLVMSetGlobalConstant(global_slice, false); | |
| 829 | LLVMSetUnnamedAddr(global_slice, true); | |
| 830 | LLVMSetAlignment(global_slice, get_abi_alignment(g, str_type)); | |
| 835 | 831 | |
| 836 | 832 | LLVMValueRef offset_ptr_indices[] = { |
| 837 | 833 | LLVMConstNull(usize->type_ref), |
| 838 | 834 | LLVMConstInt(usize->type_ref, unwrap_err_msg_text_len, false), |
| 839 | 835 | }; |
| 840 | LLVMValueRef offset_buf_ptr = LLVMConstInBoundsGEP(global_value, offset_ptr_indices, 2); | |
| 836 | LLVMValueRef offset_buf_ptr = LLVMConstInBoundsGEP(global_array, offset_ptr_indices, 2); | |
| 841 | 837 | |
| 842 | 838 | Buf *fn_name = get_mangled_name(g, buf_create_from_str("__zig_fail_unwrap"), false); |
| 843 | 839 | LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMVoidType(), &g->err_tag_type->type_ref, 1, false); |
| ... | ... | @@ -888,7 +884,10 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) { |
| 888 | 884 | LLVMValueRef const_prefix_len = LLVMConstInt(LLVMTypeOf(err_name_len), strlen(unwrap_err_msg_text), false); |
| 889 | 885 | LLVMValueRef full_buf_len = LLVMBuildNUWAdd(g->builder, const_prefix_len, err_name_len, ""); |
| 890 | 886 | |
| 891 | gen_panic_raw(g, full_buf_ptr, full_buf_len); | |
| 887 | LLVMValueRef global_slice_len_field_ptr = LLVMBuildStructGEP(g->builder, global_slice, slice_len_index, ""); | |
| 888 | gen_store(g, full_buf_len, global_slice_len_field_ptr, u8_ptr_type); | |
| 889 | ||
| 890 | gen_panic(g, global_slice); | |
| 892 | 891 | |
| 893 | 892 | LLVMPositionBuilderAtEnd(g->builder, prev_block); |
| 894 | 893 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); |
| ... | ... | @@ -3744,8 +3743,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3744 | 3743 | fields[type_struct_field->gen_index] = gen_const_val(g, &const_val->data.x_struct.fields[i]); |
| 3745 | 3744 | } |
| 3746 | 3745 | } |
| 3747 | return LLVMConstStruct(fields, type_entry->data.structure.gen_field_count, | |
| 3748 | type_entry->data.structure.layout == ContainerLayoutPacked); | |
| 3746 | return LLVMConstNamedStruct(type_entry->type_ref, fields, type_entry->data.structure.gen_field_count); | |
| 3749 | 3747 | } |
| 3750 | 3748 | case TypeTableEntryIdUnion: |
| 3751 | 3749 | { |
| ... | ... | @@ -4103,7 +4101,7 @@ static void validate_inline_fns(CodeGen *g) { |
| 4103 | 4101 | } |
| 4104 | 4102 | |
| 4105 | 4103 | static void do_code_gen(CodeGen *g) { |
| 4106 | if (g->verbose || g->verbose_ir) { | |
| 4104 | if (g->verbose) { | |
| 4107 | 4105 | fprintf(stderr, "\nCode Generation:\n"); |
| 4108 | 4106 | fprintf(stderr, "------------------\n"); |
| 4109 | 4107 | } |
| ... | ... | @@ -4918,8 +4916,6 @@ static void define_builtin_compile_vars(CodeGen *g) { |
| 4918 | 4916 | buf_appendf(contents, "pub const mode = %s;\n", build_mode_to_str(g->build_mode)); |
| 4919 | 4917 | buf_appendf(contents, "pub const link_libc = %s;\n", bool_to_str(g->libc_link_lib != nullptr)); |
| 4920 | 4918 | |
| 4921 | buf_appendf(contents, "pub const __zig_panic_implementation_provided = %s; // overwritten later\n", | |
| 4922 | bool_to_str(false)); | |
| 4923 | 4919 | buf_appendf(contents, "pub const __zig_test_fn_slice = {}; // overwritten later\n"); |
| 4924 | 4920 | |
| 4925 | 4921 | ensure_cache_dir(g); |
| ... | ... | @@ -5105,10 +5101,8 @@ static PackageTableEntry *create_test_runner_pkg(CodeGen *g) { |
| 5105 | 5101 | return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "test_runner.zig"); |
| 5106 | 5102 | } |
| 5107 | 5103 | |
| 5108 | static PackageTableEntry *create_zigrt_pkg(CodeGen *g) { | |
| 5109 | PackageTableEntry *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "zigrt.zig"); | |
| 5110 | package->package_table.put(buf_create_from_str("@root"), g->root_package); | |
| 5111 | return package; | |
| 5104 | static PackageTableEntry *create_panic_pkg(CodeGen *g) { | |
| 5105 | return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "panic.zig"); | |
| 5112 | 5106 | } |
| 5113 | 5107 | |
| 5114 | 5108 | static void create_test_compile_var_and_add_test_runner(CodeGen *g) { |
| ... | ... | @@ -5190,9 +5184,19 @@ static void gen_root_source(CodeGen *g) { |
| 5190 | 5184 | { |
| 5191 | 5185 | g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap.zig"); |
| 5192 | 5186 | } |
| 5193 | if (!g->omit_zigrt) { | |
| 5194 | g->zigrt_package = create_zigrt_pkg(g); | |
| 5195 | add_special_code(g, g->zigrt_package, "zigrt.zig"); | |
| 5187 | ImportTableEntry *import_with_panic; | |
| 5188 | if (g->have_pub_panic) { | |
| 5189 | import_with_panic = g->root_import; | |
| 5190 | } else { | |
| 5191 | g->panic_package = create_panic_pkg(g); | |
| 5192 | import_with_panic = add_special_code(g, g->panic_package, "panic.zig"); | |
| 5193 | } | |
| 5194 | // Zig has lazy top level definitions. Here we semantically analyze the panic function. | |
| 5195 | { | |
| 5196 | scan_import(g, import_with_panic); | |
| 5197 | Tld *panic_tld = find_decl(g, &import_with_panic->decls_scope->base, buf_create_from_str("panic")); | |
| 5198 | assert(panic_tld != nullptr); | |
| 5199 | resolve_top_level_decl(g, panic_tld, false, nullptr); | |
| 5196 | 5200 | } |
| 5197 | 5201 | |
| 5198 | 5202 | if (g->verbose) { |
src/codegen.hpp-1| ... | ... | @@ -41,7 +41,6 @@ void codegen_set_rdynamic(CodeGen *g, bool rdynamic); |
| 41 | 41 | void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min); |
| 42 | 42 | void codegen_set_mios_version_min(CodeGen *g, Buf *mios_version_min); |
| 43 | 43 | void codegen_set_linker_script(CodeGen *g, const char *linker_script); |
| 44 | void codegen_set_omit_zigrt(CodeGen *g, bool omit_zigrt); | |
| 45 | 44 | void codegen_set_test_filter(CodeGen *g, Buf *filter); |
| 46 | 45 | void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix); |
| 47 | 46 | void codegen_set_lib_version(CodeGen *g, size_t major, size_t minor, size_t patch); |
src/link.cpp-1| ... | ... | @@ -35,7 +35,6 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) |
| 35 | 35 | ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target; |
| 36 | 36 | CodeGen *child_gen = codegen_create(full_path, child_target, OutTypeObj, parent_gen->build_mode); |
| 37 | 37 | |
| 38 | codegen_set_omit_zigrt(child_gen, true); | |
| 39 | 38 | child_gen->want_h_file = false; |
| 40 | 39 | child_gen->verbose_link = parent_gen->verbose_link; |
| 41 | 40 |
std/special/builtin.zig+16-3| ... | ... | @@ -1,11 +1,21 @@ |
| 1 | 1 | // These functions are provided when not linking against libc because LLVM |
| 2 | 2 | // sometimes generates code that calls them. |
| 3 | 3 | |
| 4 | // Note that these functions do not return `dest`, like the libc API. | |
| 5 | // The semantics of these functions is dictated by the corresponding | |
| 6 | // LLVM intrinsics, not by the libc API. | |
| 7 | 4 | const builtin = @import("builtin"); |
| 8 | 5 | |
| 6 | // Avoid dragging in the debug safety mechanisms into this .o file, | |
| 7 | // unless we're trying to test this file. | |
| 8 | pub coldcc fn panic(msg: []const u8) -> noreturn { | |
| 9 | if (builtin.is_test) { | |
| 10 | @import("std").debug.panic("{}", msg); | |
| 11 | } else { | |
| 12 | unreachable; | |
| 13 | } | |
| 14 | } | |
| 15 | ||
| 16 | // Note that memset does not return `dest`, like the libc API. | |
| 17 | // The semantics of memset is dictated by the corresponding | |
| 18 | // LLVM intrinsics, not by the libc API. | |
| 9 | 19 | export fn memset(dest: ?&u8, c: u8, n: usize) { |
| 10 | 20 | @setDebugSafety(this, false); |
| 11 | 21 | |
| ... | ... | @@ -14,6 +24,9 @@ export fn memset(dest: ?&u8, c: u8, n: usize) { |
| 14 | 24 | (??dest)[index] = c; |
| 15 | 25 | } |
| 16 | 26 | |
| 27 | // Note that memcpy does not return `dest`, like the libc API. | |
| 28 | // The semantics of memcpy is dictated by the corresponding | |
| 29 | // LLVM intrinsics, not by the libc API. | |
| 17 | 30 | export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) { |
| 18 | 31 | @setDebugSafety(this, false); |
| 19 | 32 |
std/special/compiler_rt/index.zig+10| ... | ... | @@ -23,6 +23,16 @@ const assert = @import("../../debug.zig").assert; |
| 23 | 23 | |
| 24 | 24 | const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4; |
| 25 | 25 | |
| 26 | // Avoid dragging in the debug safety mechanisms into this .o file, | |
| 27 | // unless we're trying to test this file. | |
| 28 | pub coldcc fn panic(msg: []const u8) -> noreturn { | |
| 29 | if (is_test) { | |
| 30 | @import("std").debug.panic("{}", msg); | |
| 31 | } else { | |
| 32 | unreachable; | |
| 33 | } | |
| 34 | } | |
| 35 | ||
| 26 | 36 | export fn __udivdi3(a: u64, b: u64) -> u64 { |
| 27 | 37 | @setDebugSafety(this, is_test); |
| 28 | 38 | @setGlobalLinkage(__udivdi3, builtin.GlobalLinkage.LinkOnce); |
std/special/panic.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | // This file is the default panic handler if the root source file does not | |
| 2 | // have a `pub fn panic`. | |
| 3 | // If this file wants to import other files *by name*, support for that would | |
| 4 | // have to be added in the compiler. | |
| 5 | ||
| 6 | const builtin = @import("builtin"); | |
| 7 | ||
| 8 | pub coldcc fn panic(msg: []const u8) -> noreturn { | |
| 9 | if (builtin.os == builtin.Os.freestanding) { | |
| 10 | while (true) {} | |
| 11 | } else { | |
| 12 | @import("std").debug.panic("{}", msg); | |
| 13 | } | |
| 14 | } |
std/special/zigrt.zig deleted-18| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | // This file contains functions that zig depends on to coordinate between | |
| 2 | // multiple .o files. The symbols are defined LinkOnce so that multiple | |
| 3 | // instances of zig_rt.zig do not conflict with each other. | |
| 4 | ||
| 5 | const builtin = @import("builtin"); | |
| 6 | ||
| 7 | export coldcc fn __zig_panic(message_ptr: &const u8, message_len: usize) -> noreturn { | |
| 8 | @setGlobalLinkage(__zig_panic, builtin.GlobalLinkage.LinkOnce); | |
| 9 | @setDebugSafety(this, false); | |
| 10 | ||
| 11 | if (builtin.__zig_panic_implementation_provided) { | |
| 12 | @import("@root").panic(message_ptr[0..message_len]); | |
| 13 | } else if (builtin.os == builtin.Os.freestanding) { | |
| 14 | while (true) {} | |
| 15 | } else { | |
| 16 | @import("std").debug.panic("{}", message_ptr[0..message_len]); | |
| 17 | } | |
| 18 | } |
test/behavior.zig+1| ... | ... | @@ -6,6 +6,7 @@ comptime { |
| 6 | 6 | _ = @import("cases/atomics.zig"); |
| 7 | 7 | _ = @import("cases/bitcast.zig"); |
| 8 | 8 | _ = @import("cases/bool.zig"); |
| 9 | _ = @import("cases/bugs/394.zig"); | |
| 9 | 10 | _ = @import("cases/cast.zig"); |
| 10 | 11 | _ = @import("cases/const_slice_child.zig"); |
| 11 | 12 | _ = @import("cases/defer.zig"); |
test/cases/bugs/394.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | const E = enum { A: [9]u8, B: u64, }; | |
| 2 | const S = struct { x: u8, y: E, }; | |
| 3 | ||
| 4 | const assert = @import("std").debug.assert; | |
| 5 | ||
| 6 | test "bug 394 fixed" { | |
| 7 | const x = S { .x = 3, .y = E.B {1} }; | |
| 8 | assert(x.x == 3); | |
| 9 | } |