authorgravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-13 16:16:22-07:00
committergravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-13 16:16:22-07:00
log2a6ad23b52aa128dfbfc1fe975fadc38714850b4
tree7a7b3d03a76f7b39674cc9b286feab4f78fa650f
parent2cdd50c9b266ea828274578481e0c37dc0b19956
parent7f7823e23cfd82739401f43a329106bee0748b10

Merge branch 'master' of https://github.com/zig-lang/zig


5 files changed, 76 insertions(+), 22 deletions(-)

src/all_types.hpp+5-5
...@@ -144,6 +144,8 @@ enum ConstPtrSpecial {...@@ -144,6 +144,8 @@ enum ConstPtrSpecial {
144 // This means that the pointer represents memory of assigning to _.144 // This means that the pointer represents memory of assigning to _.
145 // That is, storing discards the data, and loading is invalid.145 // That is, storing discards the data, and loading is invalid.
146 ConstPtrSpecialDiscard,146 ConstPtrSpecialDiscard,
147 // This is actually a function.
148 ConstPtrSpecialFunction,
147};149};
148150
149enum ConstPtrMut {151enum ConstPtrMut {
...@@ -180,6 +182,9 @@ struct ConstPtrValue {...@@ -180,6 +182,9 @@ struct ConstPtrValue {
180 struct {182 struct {
181 uint64_t addr;183 uint64_t addr;
182 } hard_coded_addr;184 } hard_coded_addr;
185 struct {
186 FnTableEntry *fn_entry;
187 } fn;
183 } data;188 } data;
184};189};
185190
...@@ -222,10 +227,6 @@ enum RuntimeHintPtr {...@@ -222,10 +227,6 @@ enum RuntimeHintPtr {
222 RuntimeHintPtrNonStack,227 RuntimeHintPtrNonStack,
223};228};
224229
225struct ConstFn {
226 FnTableEntry *fn_entry;
227};
228
229struct ConstGlobalRefs {230struct ConstGlobalRefs {
230 LLVMValueRef llvm_value;231 LLVMValueRef llvm_value;
231 LLVMValueRef llvm_global;232 LLVMValueRef llvm_global;
...@@ -244,7 +245,6 @@ struct ConstExprValue {...@@ -244,7 +245,6 @@ struct ConstExprValue {
244 double x_f64;245 double x_f64;
245 float128_t x_f128;246 float128_t x_f128;
246 bool x_bool;247 bool x_bool;
247 ConstFn x_fn;
248 ConstBoundFnValue x_bound_fn;248 ConstBoundFnValue x_bound_fn;
249 TypeTableEntry *x_type;249 TypeTableEntry *x_type;
250 ConstExprValue *x_maybe;250 ConstExprValue *x_maybe;
src/analyze.cpp+25-10
...@@ -4451,6 +4451,10 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4451,6 +4451,10 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4451 case TypeTableEntryIdArgTuple:4451 case TypeTableEntryIdArgTuple:
4452 return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 +4452 return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 +
4453 (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768;4453 (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768;
4454 case TypeTableEntryIdFn:
4455 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
4456 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
4457 return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);
4454 case TypeTableEntryIdPointer:4458 case TypeTableEntryIdPointer:
4455 {4459 {
4456 uint32_t hash_val = 0;4460 uint32_t hash_val = 0;
...@@ -4490,6 +4494,10 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4490,6 +4494,10 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4490 case ConstPtrSpecialDiscard:4494 case ConstPtrSpecialDiscard:
4491 hash_val += 2010123162;4495 hash_val += 2010123162;
4492 return hash_val;4496 return hash_val;
4497 case ConstPtrSpecialFunction:
4498 hash_val += (uint32_t)2590901619;
4499 hash_val += hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);
4500 return hash_val;
4493 }4501 }
4494 zig_unreachable();4502 zig_unreachable();
4495 }4503 }
...@@ -4521,8 +4529,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4521,8 +4529,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4521 case TypeTableEntryIdErrorSet:4529 case TypeTableEntryIdErrorSet:
4522 assert(const_val->data.x_err_set != nullptr);4530 assert(const_val->data.x_err_set != nullptr);
4523 return const_val->data.x_err_set->value ^ 2630160122;4531 return const_val->data.x_err_set->value ^ 2630160122;
4524 case TypeTableEntryIdFn:
4525 return 4133894920 ^ hash_ptr(const_val->data.x_fn.fn_entry);
4526 case TypeTableEntryIdNamespace:4532 case TypeTableEntryIdNamespace:
4527 return hash_ptr(const_val->data.x_import);4533 return hash_ptr(const_val->data.x_import);
4528 case TypeTableEntryIdBlock:4534 case TypeTableEntryIdBlock:
...@@ -5154,8 +5160,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5154,8 +5160,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5154 return true;5160 return true;
5155 case TypeTableEntryIdErrorSet:5161 case TypeTableEntryIdErrorSet:
5156 return a->data.x_err_set->value == b->data.x_err_set->value;5162 return a->data.x_err_set->value == b->data.x_err_set->value;
5157 case TypeTableEntryIdFn:
5158 return a->data.x_fn.fn_entry == b->data.x_fn.fn_entry;
5159 case TypeTableEntryIdBool:5163 case TypeTableEntryIdBool:
5160 return a->data.x_bool == b->data.x_bool;5164 return a->data.x_bool == b->data.x_bool;
5161 case TypeTableEntryIdFloat:5165 case TypeTableEntryIdFloat:
...@@ -5176,6 +5180,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5176,6 +5180,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5176 case TypeTableEntryIdNumLitInt:5180 case TypeTableEntryIdNumLitInt:
5177 return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ;5181 return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ;
5178 case TypeTableEntryIdPointer:5182 case TypeTableEntryIdPointer:
5183 case TypeTableEntryIdFn:
5179 if (a->data.x_ptr.special != b->data.x_ptr.special)5184 if (a->data.x_ptr.special != b->data.x_ptr.special)
5180 return false;5185 return false;
5181 if (a->data.x_ptr.mut != b->data.x_ptr.mut)5186 if (a->data.x_ptr.mut != b->data.x_ptr.mut)
...@@ -5215,6 +5220,8 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5215,6 +5220,8 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5215 return true;5220 return true;
5216 case ConstPtrSpecialDiscard:5221 case ConstPtrSpecialDiscard:
5217 return true;5222 return true;
5223 case ConstPtrSpecialFunction:
5224 return a->data.x_ptr.data.fn.fn_entry == b->data.x_ptr.data.fn.fn_entry;
5218 }5225 }
5219 zig_unreachable();5226 zig_unreachable();
5220 case TypeTableEntryIdArray:5227 case TypeTableEntryIdArray:
...@@ -5375,6 +5382,14 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5375,6 +5382,14 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5375 buf_appendf(buf, "%s", value);5382 buf_appendf(buf, "%s", value);
5376 return;5383 return;
5377 }5384 }
5385 case TypeTableEntryIdFn:
5386 {
5387 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
5388 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
5389 FnTableEntry *fn_entry = const_val->data.x_ptr.data.fn.fn_entry;
5390 buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name));
5391 return;
5392 }
5378 case TypeTableEntryIdPointer:5393 case TypeTableEntryIdPointer:
5379 switch (const_val->data.x_ptr.special) {5394 switch (const_val->data.x_ptr.special) {
5380 case ConstPtrSpecialInvalid:5395 case ConstPtrSpecialInvalid:
...@@ -5400,14 +5415,14 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5400,14 +5415,14 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5400 case ConstPtrSpecialDiscard:5415 case ConstPtrSpecialDiscard:
5401 buf_append_str(buf, "&_");5416 buf_append_str(buf, "&_");
5402 return;5417 return;
5418 case ConstPtrSpecialFunction:
5419 {
5420 FnTableEntry *fn_entry = const_val->data.x_ptr.data.fn.fn_entry;
5421 buf_appendf(buf, "@ptrCast(%s, %s)", buf_ptr(&const_val->type->name), buf_ptr(&fn_entry->symbol_name));
5422 return;
5423 }
5403 }5424 }
5404 zig_unreachable();5425 zig_unreachable();
5405 case TypeTableEntryIdFn:
5406 {
5407 FnTableEntry *fn_entry = const_val->data.x_fn.fn_entry;
5408 buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name));
5409 return;
5410 }
5411 case TypeTableEntryIdBlock:5426 case TypeTableEntryIdBlock:
5412 {5427 {
5413 AstNode *node = const_val->data.x_block->source_node;5428 AstNode *node = const_val->data.x_block->source_node;
src/codegen.cpp+8-2
...@@ -4840,7 +4840,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -4840,7 +4840,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
4840 case TypeTableEntryIdEnum:4840 case TypeTableEntryIdEnum:
4841 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_enum_tag);4841 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_enum_tag);
4842 case TypeTableEntryIdFn:4842 case TypeTableEntryIdFn:
4843 return fn_llvm_value(g, const_val->data.x_fn.fn_entry);4843 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
4844 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
4845 return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry);
4844 case TypeTableEntryIdPointer:4846 case TypeTableEntryIdPointer:
4845 {4847 {
4846 render_const_val_global(g, const_val, name);4848 render_const_val_global(g, const_val, name);
...@@ -4909,6 +4911,8 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -4909,6 +4911,8 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
4909 render_const_val_global(g, const_val, "");4911 render_const_val_global(g, const_val, "");
4910 return const_val->global_refs->llvm_value;4912 return const_val->global_refs->llvm_value;
4911 }4913 }
4914 case ConstPtrSpecialFunction:
4915 return LLVMConstBitCast(fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry), const_val->type->type_ref);
4912 }4916 }
4913 }4917 }
4914 zig_unreachable();4918 zig_unreachable();
...@@ -6313,7 +6317,9 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -6313,7 +6317,9 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
6313 ConstExprValue *fn_field = &this_val->data.x_struct.fields[1];6317 ConstExprValue *fn_field = &this_val->data.x_struct.fields[1];
6314 fn_field->type = fn_type;6318 fn_field->type = fn_type;
6315 fn_field->special = ConstValSpecialStatic;6319 fn_field->special = ConstValSpecialStatic;
6316 fn_field->data.x_fn.fn_entry = test_fn_entry;6320 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;
6321 fn_field->data.x_ptr.mut = ConstPtrMutComptimeConst;
6322 fn_field->data.x_ptr.data.fn.fn_entry = test_fn_entry;
6317 }6323 }
63186324
6319 ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);6325 ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);
src/ir.cpp+31-5
...@@ -130,6 +130,8 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {...@@ -130,6 +130,8 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
130 zig_unreachable();130 zig_unreachable();
131 case ConstPtrSpecialDiscard:131 case ConstPtrSpecialDiscard:
132 zig_unreachable();132 zig_unreachable();
133 case ConstPtrSpecialFunction:
134 zig_unreachable();
133 }135 }
134 zig_unreachable();136 zig_unreachable();
135}137}
...@@ -875,7 +877,9 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *...@@ -875,7 +877,9 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *
875 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);877 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
876 const_instruction->base.value.type = fn_entry->type_entry;878 const_instruction->base.value.type = fn_entry->type_entry;
877 const_instruction->base.value.special = ConstValSpecialStatic;879 const_instruction->base.value.special = ConstValSpecialStatic;
878 const_instruction->base.value.data.x_fn.fn_entry = fn_entry;880 const_instruction->base.value.data.x_ptr.data.fn.fn_entry = fn_entry;
881 const_instruction->base.value.data.x_ptr.mut = ConstPtrMutComptimeConst;
882 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialFunction;
879 return &const_instruction->base;883 return &const_instruction->base;
880}884}
881885
...@@ -8723,7 +8727,8 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -8723,7 +8727,8 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
8723 if (!const_val)8727 if (!const_val)
8724 return nullptr;8728 return nullptr;
87258729
8726 return const_val->data.x_fn.fn_entry;8730 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
8731 return const_val->data.x_ptr.data.fn.fn_entry;
8727}8732}
87288733
8729static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {8734static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {
...@@ -11311,7 +11316,8 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi...@@ -11311,7 +11316,8 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
11311 case TypeTableEntryIdUnreachable:11316 case TypeTableEntryIdUnreachable:
11312 zig_unreachable();11317 zig_unreachable();
11313 case TypeTableEntryIdFn: {11318 case TypeTableEntryIdFn: {
11314 FnTableEntry *fn_entry = target->value.data.x_fn.fn_entry;11319 assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction);
11320 FnTableEntry *fn_entry = target->value.data.x_ptr.data.fn.fn_entry;
11315 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;11321 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
11316 switch (cc) {11322 switch (cc) {
11317 case CallingConventionUnspecified: {11323 case CallingConventionUnspecified: {
...@@ -12852,6 +12858,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -12852,6 +12858,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
12852 zig_panic("TODO elem ptr on a const inner struct");12858 zig_panic("TODO elem ptr on a const inner struct");
12853 case ConstPtrSpecialHardCodedAddr:12859 case ConstPtrSpecialHardCodedAddr:
12854 zig_unreachable();12860 zig_unreachable();
12861 case ConstPtrSpecialFunction:
12862 zig_panic("TODO element ptr of a function casted to a ptr");
12855 }12863 }
12856 if (new_index >= mem_size) {12864 if (new_index >= mem_size) {
12857 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,12865 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
...@@ -12901,6 +12909,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -12901,6 +12909,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
12901 zig_panic("TODO elem ptr on a slice backed by const inner struct");12909 zig_panic("TODO elem ptr on a slice backed by const inner struct");
12902 case ConstPtrSpecialHardCodedAddr:12910 case ConstPtrSpecialHardCodedAddr:
12903 zig_unreachable();12911 zig_unreachable();
12912 case ConstPtrSpecialFunction:
12913 zig_panic("TODO elem ptr on a slice that was ptrcast from a function");
12904 }12914 }
12905 return return_type;12915 return return_type;
12906 } else if (array_type->id == TypeTableEntryIdArray) {12916 } else if (array_type->id == TypeTableEntryIdArray) {
...@@ -13101,7 +13111,9 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -13101,7 +13111,9 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
13101 ConstExprValue *const_val = create_const_vals(1);13111 ConstExprValue *const_val = create_const_vals(1);
13102 const_val->special = ConstValSpecialStatic;13112 const_val->special = ConstValSpecialStatic;
13103 const_val->type = fn_entry->type_entry;13113 const_val->type = fn_entry->type_entry;
13104 const_val->data.x_fn.fn_entry = fn_entry;13114 const_val->data.x_ptr.data.fn.fn_entry = fn_entry;
13115 const_val->data.x_ptr.special = ConstPtrSpecialFunction;
13116 const_val->data.x_ptr.mut = ConstPtrMutComptimeConst;
1310513117
13106 if (tld_fn->extern_lib_name != nullptr) {13118 if (tld_fn->extern_lib_name != nullptr) {
13107 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);13119 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);
...@@ -13771,7 +13783,8 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,...@@ -13771,7 +13783,8 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
13771 fast_math_off_ptr = &block_scope->fast_math_off;13783 fast_math_off_ptr = &block_scope->fast_math_off;
13772 fast_math_set_node_ptr = &block_scope->fast_math_set_node;13784 fast_math_set_node_ptr = &block_scope->fast_math_set_node;
13773 } else if (target_type->id == TypeTableEntryIdFn) {13785 } else if (target_type->id == TypeTableEntryIdFn) {
13774 FnTableEntry *target_fn = target_val->data.x_fn.fn_entry;13786 assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction);
13787 FnTableEntry *target_fn = target_val->data.x_ptr.data.fn.fn_entry;
13775 assert(target_fn->def_scope);13788 assert(target_fn->def_scope);
13776 fast_math_off_ptr = &target_fn->def_scope->fast_math_off;13789 fast_math_off_ptr = &target_fn->def_scope->fast_math_off;
13777 fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node;13790 fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node;
...@@ -15673,6 +15686,8 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi...@@ -15673,6 +15686,8 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
15673 zig_panic("TODO memset on const inner struct");15686 zig_panic("TODO memset on const inner struct");
15674 case ConstPtrSpecialHardCodedAddr:15687 case ConstPtrSpecialHardCodedAddr:
15675 zig_unreachable();15688 zig_unreachable();
15689 case ConstPtrSpecialFunction:
15690 zig_panic("TODO memset on ptr cast from function");
15676 }15691 }
1567715692
15678 size_t count = bigint_as_unsigned(&casted_count->value.data.x_bigint);15693 size_t count = bigint_as_unsigned(&casted_count->value.data.x_bigint);
...@@ -15769,6 +15784,8 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi...@@ -15769,6 +15784,8 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
15769 zig_panic("TODO memcpy on const inner struct");15784 zig_panic("TODO memcpy on const inner struct");
15770 case ConstPtrSpecialHardCodedAddr:15785 case ConstPtrSpecialHardCodedAddr:
15771 zig_unreachable();15786 zig_unreachable();
15787 case ConstPtrSpecialFunction:
15788 zig_panic("TODO memcpy on ptr cast from function");
15772 }15789 }
1577315790
15774 if (dest_start + count > dest_end) {15791 if (dest_start + count > dest_end) {
...@@ -15803,6 +15820,8 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi...@@ -15803,6 +15820,8 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
15803 zig_panic("TODO memcpy on const inner struct");15820 zig_panic("TODO memcpy on const inner struct");
15804 case ConstPtrSpecialHardCodedAddr:15821 case ConstPtrSpecialHardCodedAddr:
15805 zig_unreachable();15822 zig_unreachable();
15823 case ConstPtrSpecialFunction:
15824 zig_panic("TODO memcpy on ptr cast from function");
15806 }15825 }
1580715826
15808 if (src_start + count > src_end) {15827 if (src_start + count > src_end) {
...@@ -15925,6 +15944,8 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -15925,6 +15944,8 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
15925 abs_offset = 0;15944 abs_offset = 0;
15926 rel_end = SIZE_MAX;15945 rel_end = SIZE_MAX;
15927 break;15946 break;
15947 case ConstPtrSpecialFunction:
15948 zig_panic("TODO slice of ptr cast from function");
15928 }15949 }
15929 } else if (is_slice(array_type)) {15950 } else if (is_slice(array_type)) {
15930 ConstExprValue *slice_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);15951 ConstExprValue *slice_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
...@@ -15952,6 +15973,8 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -15952,6 +15973,8 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
15952 abs_offset = 0;15973 abs_offset = 0;
15953 rel_end = bigint_as_unsigned(&len_val->data.x_bigint);15974 rel_end = bigint_as_unsigned(&len_val->data.x_bigint);
15954 break;15975 break;
15976 case ConstPtrSpecialFunction:
15977 zig_panic("TODO slice of slice cast from function");
15955 }15978 }
15956 } else {15979 } else {
15957 zig_unreachable();15980 zig_unreachable();
...@@ -16021,6 +16044,9 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -16021,6 +16044,9 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
16021 parent_ptr->type->data.pointer.child_type,16044 parent_ptr->type->data.pointer.child_type,
16022 parent_ptr->data.x_ptr.data.hard_coded_addr.addr + start_scalar,16045 parent_ptr->data.x_ptr.data.hard_coded_addr.addr + start_scalar,
16023 slice_is_const(return_type));16046 slice_is_const(return_type));
16047 break;
16048 case ConstPtrSpecialFunction:
16049 zig_panic("TODO");
16024 }16050 }
1602516051
16026 ConstExprValue *len_val = &out_val->data.x_struct.fields[slice_len_index];16052 ConstExprValue *len_val = &out_val->data.x_struct.fields[slice_len_index];
test/cases/misc.zig+7
...@@ -660,3 +660,10 @@ test "slicing zero length array" {...@@ -660,3 +660,10 @@ test "slicing zero length array" {
660 assert(mem.eql(u8, s1, ""));660 assert(mem.eql(u8, s1, ""));
661 assert(mem.eql(u32, s2, []u32{}));661 assert(mem.eql(u32, s2, []u32{}));
662}662}
663
664
665const addr1 = @ptrCast(&const u8, emptyFn);
666test "comptime cast fn to ptr" {
667 const addr2 = @ptrCast(&const u8, emptyFn);
668 comptime assert(addr1 == addr2);
669}