@@ -381,21 +381,22 @@ TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) {
381
381
}
382
382
383
383
TypeTableEntry *get_pointer_to_type_extra (CodeGen *g, TypeTableEntry *child_type, bool is_const,
384
- bool is_volatile, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count)
384
+ bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count)
385
385
{
386
386
assert (!type_is_invalid (child_type));
387
387
388
388
TypeId type_id = {};
389
389
TypeTableEntry **parent_pointer = nullptr ;
390
390
uint32_t abi_alignment = get_abi_alignment (g, child_type);
391
- if (unaligned_bit_count != 0 || is_volatile || byte_alignment != abi_alignment) {
391
+ if (unaligned_bit_count != 0 || is_volatile || byte_alignment != abi_alignment || ptr_len != PtrLenSingle ) {
392
392
type_id.id = TypeTableEntryIdPointer;
393
393
type_id.data .pointer .child_type = child_type;
394
394
type_id.data .pointer .is_const = is_const;
395
395
type_id.data .pointer .is_volatile = is_volatile;
396
396
type_id.data .pointer .alignment = byte_alignment;
397
397
type_id.data .pointer .bit_offset = bit_offset;
398
398
type_id.data .pointer .unaligned_bit_count = unaligned_bit_count;
399
+ type_id.data .pointer .ptr_len = ptr_len;
399
400
400
401
auto existing_entry = g->type_table .maybe_get (type_id);
401
402
if (existing_entry)
@@ -414,16 +415,17 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
414
415
TypeTableEntry *entry = new_type_table_entry (TypeTableEntryIdPointer);
415
416
entry->is_copyable = true ;
416
417
418
+ const char *star_str = ptr_len == PtrLenSingle ? " *" : " [*]" ;
417
419
const char *const_str = is_const ? " const " : " " ;
418
420
const char *volatile_str = is_volatile ? " volatile " : " " ;
419
421
buf_resize (&entry->name , 0 );
420
422
if (unaligned_bit_count == 0 && byte_alignment == abi_alignment) {
421
- buf_appendf (&entry->name , " * %s%s%s" , const_str, volatile_str, buf_ptr (&child_type->name ));
423
+ buf_appendf (&entry->name , " %s%s%s%s " , star_str , const_str, volatile_str, buf_ptr (&child_type->name ));
422
424
} else if (unaligned_bit_count == 0 ) {
423
- buf_appendf (&entry->name , " *align (%" PRIu32 " ) %s%s%s" , byte_alignment,
425
+ buf_appendf (&entry->name , " %salign (%" PRIu32 " ) %s%s%s" , star_str , byte_alignment,
424
426
const_str, volatile_str, buf_ptr (&child_type->name ));
425
427
} else {
426
- buf_appendf (&entry->name , " *align (%" PRIu32 " :%" PRIu32 " :%" PRIu32 " ) %s%s%s" , byte_alignment,
428
+ buf_appendf (&entry->name , " %salign (%" PRIu32 " :%" PRIu32 " :%" PRIu32 " ) %s%s%s" , star_str , byte_alignment,
427
429
bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr (&child_type->name ));
428
430
}
429
431
@@ -433,7 +435,9 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
433
435
434
436
if (!entry->zero_bits ) {
435
437
assert (byte_alignment > 0 );
436
- if (is_const || is_volatile || unaligned_bit_count != 0 || byte_alignment != abi_alignment) {
438
+ if (is_const || is_volatile || unaligned_bit_count != 0 || byte_alignment != abi_alignment ||
439
+ ptr_len != PtrLenSingle)
440
+ {
437
441
TypeTableEntry *peer_type = get_pointer_to_type (g, child_type, false );
438
442
entry->type_ref = peer_type->type_ref ;
439
443
entry->di_type = peer_type->di_type ;
@@ -451,6 +455,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
451
455
entry->di_type = g->builtin_types .entry_void ->di_type ;
452
456
}
453
457
458
+ entry->data .pointer .ptr_len = ptr_len;
454
459
entry->data .pointer .child_type = child_type;
455
460
entry->data .pointer .is_const = is_const;
456
461
entry->data .pointer .is_volatile = is_volatile;
@@ -467,7 +472,8 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
467
472
}
468
473
469
474
TypeTableEntry *get_pointer_to_type (CodeGen *g, TypeTableEntry *child_type, bool is_const) {
470
- return get_pointer_to_type_extra (g, child_type, is_const, false , get_abi_alignment (g, child_type), 0 , 0 );
475
+ return get_pointer_to_type_extra (g, child_type, is_const, false , PtrLenSingle,
476
+ get_abi_alignment (g, child_type), 0 , 0 );
471
477
}
472
478
473
479
TypeTableEntry *get_promise_frame_type (CodeGen *g, TypeTableEntry *return_type) {
@@ -757,6 +763,7 @@ static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, Typ
757
763
758
764
TypeTableEntry *get_slice_type (CodeGen *g, TypeTableEntry *ptr_type) {
759
765
assert (ptr_type->id == TypeTableEntryIdPointer);
766
+ assert (ptr_type->data .pointer .ptr_len == PtrLenUnknown);
760
767
761
768
TypeTableEntry **parent_pointer = &ptr_type->data .pointer .slice_parent ;
762
769
if (*parent_pointer) {
@@ -768,14 +775,16 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
768
775
769
776
// replace the & with [] to go from a ptr type name to a slice type name
770
777
buf_resize (&entry->name , 0 );
771
- buf_appendf (&entry->name , " []%s" , buf_ptr (&ptr_type->name ) + 1 );
778
+ size_t name_offset = (ptr_type->data .pointer .ptr_len == PtrLenSingle) ? 1 : 3 ;
779
+ buf_appendf (&entry->name , " []%s" , buf_ptr (&ptr_type->name ) + name_offset);
772
780
773
781
TypeTableEntry *child_type = ptr_type->data .pointer .child_type ;
774
- uint32_t abi_alignment;
782
+ uint32_t abi_alignment = get_abi_alignment (g, child_type) ;
775
783
if (ptr_type->data .pointer .is_const || ptr_type->data .pointer .is_volatile ||
776
- ptr_type->data .pointer .alignment != ( abi_alignment = get_abi_alignment (g, child_type)) )
784
+ ptr_type->data .pointer .alignment != abi_alignment)
777
785
{
778
- TypeTableEntry *peer_ptr_type = get_pointer_to_type (g, child_type, false );
786
+ TypeTableEntry *peer_ptr_type = get_pointer_to_type_extra (g, child_type, false , false ,
787
+ PtrLenUnknown, abi_alignment, 0 , 0 );
779
788
TypeTableEntry *peer_slice_type = get_slice_type (g, peer_ptr_type);
780
789
781
790
slice_type_common_init (g, ptr_type, entry);
@@ -799,9 +808,11 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
799
808
if (child_ptr_type->data .pointer .is_const || child_ptr_type->data .pointer .is_volatile ||
800
809
child_ptr_type->data .pointer .alignment != get_abi_alignment (g, grand_child_type))
801
810
{
802
- TypeTableEntry *bland_child_ptr_type = get_pointer_to_type (g, grand_child_type, false );
811
+ TypeTableEntry *bland_child_ptr_type = get_pointer_to_type_extra (g, grand_child_type, false , false ,
812
+ PtrLenUnknown, get_abi_alignment (g, grand_child_type), 0 , 0 );
803
813
TypeTableEntry *bland_child_slice = get_slice_type (g, bland_child_ptr_type);
804
- TypeTableEntry *peer_ptr_type = get_pointer_to_type (g, bland_child_slice, false );
814
+ TypeTableEntry *peer_ptr_type = get_pointer_to_type_extra (g, bland_child_slice, false , false ,
815
+ PtrLenUnknown, get_abi_alignment (g, bland_child_slice), 0 , 0 );
805
816
TypeTableEntry *peer_slice_type = get_slice_type (g, peer_ptr_type);
806
817
807
818
entry->type_ref = peer_slice_type->type_ref ;
@@ -1284,7 +1295,8 @@ static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_
1284
1295
}
1285
1296
1286
1297
static bool analyze_const_string (CodeGen *g, Scope *scope, AstNode *node, Buf **out_buffer) {
1287
- TypeTableEntry *ptr_type = get_pointer_to_type (g, g->builtin_types .entry_u8 , true );
1298
+ TypeTableEntry *ptr_type = get_pointer_to_type_extra (g, g->builtin_types .entry_u8 , true , false ,
1299
+ PtrLenUnknown, get_abi_alignment (g, g->builtin_types .entry_u8 ), 0 , 0 );
1288
1300
TypeTableEntry *str_type = get_slice_type (g, ptr_type);
1289
1301
IrInstruction *instr = analyze_const_value (g, scope, node, str_type, nullptr );
1290
1302
if (type_is_invalid (instr->value .type ))
@@ -2954,7 +2966,8 @@ static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {
2954
2966
if (fn_type_id->param_count != 2 ) {
2955
2967
return wrong_panic_prototype (g, proto_node, fn_type);
2956
2968
}
2957
- TypeTableEntry *const_u8_ptr = get_pointer_to_type (g, g->builtin_types .entry_u8 , true );
2969
+ TypeTableEntry *const_u8_ptr = get_pointer_to_type_extra (g, g->builtin_types .entry_u8 , true , false ,
2970
+ PtrLenUnknown, get_abi_alignment (g, g->builtin_types .entry_u8 ), 0 , 0 );
2958
2971
TypeTableEntry *const_u8_slice = get_slice_type (g, const_u8_ptr);
2959
2972
if (fn_type_id->param_info [0 ].type != const_u8_slice) {
2960
2973
return wrong_panic_prototype (g, proto_node, fn_type);
@@ -4994,7 +5007,9 @@ void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
4994
5007
4995
5008
// then make the pointer point to it
4996
5009
const_val->special = ConstValSpecialStatic;
4997
- const_val->type = get_pointer_to_type (g, g->builtin_types .entry_u8 , true );
5010
+ // TODO make this `[*]null u8` instead of `[*]u8`
5011
+ const_val->type = get_pointer_to_type_extra (g, g->builtin_types .entry_u8 , true , false ,
5012
+ PtrLenUnknown, get_abi_alignment (g, g->builtin_types .entry_u8 ), 0 , 0 );
4998
5013
const_val->data .x_ptr .special = ConstPtrSpecialBaseArray;
4999
5014
const_val->data .x_ptr .data .base_array .array_val = array_val;
5000
5015
const_val->data .x_ptr .data .base_array .elem_index = 0 ;
@@ -5135,7 +5150,9 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr
5135
5150
{
5136
5151
assert (array_val->type ->id == TypeTableEntryIdArray);
5137
5152
5138
- TypeTableEntry *ptr_type = get_pointer_to_type (g, array_val->type ->data .array .child_type , is_const);
5153
+ TypeTableEntry *ptr_type = get_pointer_to_type_extra (g, array_val->type ->data .array .child_type ,
5154
+ is_const, false , PtrLenUnknown, get_abi_alignment (g, array_val->type ->data .array .child_type ),
5155
+ 0 , 0 );
5139
5156
5140
5157
const_val->special = ConstValSpecialStatic;
5141
5158
const_val->type = get_slice_type (g, ptr_type);
@@ -5759,6 +5776,7 @@ uint32_t type_id_hash(TypeId x) {
5759
5776
return hash_ptr (x.data .error_union .err_set_type ) ^ hash_ptr (x.data .error_union .payload_type );
5760
5777
case TypeTableEntryIdPointer:
5761
5778
return hash_ptr (x.data .pointer .child_type ) +
5779
+ ((x.data .pointer .ptr_len == PtrLenSingle) ? (uint32_t )1120226602 : (uint32_t )3200913342 ) +
5762
5780
(x.data .pointer .is_const ? (uint32_t )2749109194 : (uint32_t )4047371087 ) +
5763
5781
(x.data .pointer .is_volatile ? (uint32_t )536730450 : (uint32_t )1685612214 ) +
5764
5782
(((uint32_t )x.data .pointer .alignment ) ^ (uint32_t )0x777fbe0e ) +
@@ -5807,6 +5825,7 @@ bool type_id_eql(TypeId a, TypeId b) {
5807
5825
5808
5826
case TypeTableEntryIdPointer:
5809
5827
return a.data .pointer .child_type == b.data .pointer .child_type &&
5828
+ a.data .pointer .ptr_len == b.data .pointer .ptr_len &&
5810
5829
a.data .pointer .is_const == b.data .pointer .is_const &&
5811
5830
a.data .pointer .is_volatile == b.data .pointer .is_volatile &&
5812
5831
a.data .pointer .alignment == b.data .pointer .alignment &&
0 commit comments