authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-04 01:09:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-04 01:39:57-04:00
log96164ce61377b36bcaf0c4087ca9b1ab822b9457
treedb4ab07dd179c8f72a05028edb6ad60bfabd4a74
parent4c273126dfc44cf4fcf9d5d97bf1cb1da07d7bd7

disallow single-item pointer indexing

add pointer arithmetic for unknown length pointer

35 files changed, 584 insertions(+), 443 deletions(-)

doc/langref.html.in+28-20
......@@ -458,7 +458,7 @@ test "string literals" {
458458
459459 // A C string literal is a null terminated pointer.
460460 const null_terminated_bytes = c"hello";
461 assert(@typeOf(null_terminated_bytes) == *const u8);
461 assert(@typeOf(null_terminated_bytes) == [*]const u8);
462462 assert(null_terminated_bytes[5] == 0);
463463}
464464 {#code_end#}
......@@ -547,7 +547,7 @@ const c_string_literal =
547547;
548548 {#code_end#}
549549 <p>
550 In this example the variable <code>c_string_literal</code> has type <code>*const char</code> and
550 In this example the variable <code>c_string_literal</code> has type <code>[*]const char</code> and
551551 has a terminating null byte.
552552 </p>
553553 {#see_also|@embedFile#}
......@@ -1288,7 +1288,7 @@ const assert = @import("std").debug.assert;
12881288const mem = @import("std").mem;
12891289
12901290// array literal
1291const message = []u8{'h', 'e', 'l', 'l', 'o'};
1291const message = []u8{ 'h', 'e', 'l', 'l', 'o' };
12921292
12931293// get the size of an array
12941294comptime {
......@@ -1324,11 +1324,11 @@ test "modify an array" {
13241324
13251325// array concatenation works if the values are known
13261326// at compile time
1327const part_one = []i32{1, 2, 3, 4};
1328const part_two = []i32{5, 6, 7, 8};
1327const part_one = []i32{ 1, 2, 3, 4 };
1328const part_two = []i32{ 5, 6, 7, 8 };
13291329const all_of_it = part_one ++ part_two;
13301330comptime {
1331 assert(mem.eql(i32, all_of_it, []i32{1,2,3,4,5,6,7,8}));
1331 assert(mem.eql(i32, all_of_it, []i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
13321332}
13331333
13341334// remember that string literals are arrays
......@@ -1357,7 +1357,7 @@ comptime {
13571357var fancy_array = init: {
13581358 var initial_value: [10]Point = undefined;
13591359 for (initial_value) |*pt, i| {
1360 pt.* = Point {
1360 pt.* = Point{
13611361 .x = i32(i),
13621362 .y = i32(i) * 2,
13631363 };
......@@ -1377,7 +1377,7 @@ test "compile-time array initalization" {
13771377// call a function to initialize an array
13781378var more_points = []Point{makePoint(3)} ** 10;
13791379fn makePoint(x: i32) Point {
1380 return Point {
1380 return Point{
13811381 .x = x,
13821382 .y = x * 2,
13831383 };
......@@ -1414,25 +1414,24 @@ test "address of syntax" {
14141414}
14151415
14161416test "pointer array access" {
1417 // Pointers do not support pointer arithmetic. If you
1418 // need such a thing, use array index syntax:
1417 // Taking an address of an individual element gives a
1418 // pointer to a single item. This kind of pointer
1419 // does not support pointer arithmetic.
14191420
14201421 var array = []u8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
1421 const ptr = &array[1];
1422 const ptr = &array[2];
1423 assert(@typeOf(ptr) == *u8);
14221424
14231425 assert(array[2] == 3);
1424 ptr[1] += 1;
1426 ptr.* += 1;
14251427 assert(array[2] == 4);
14261428}
14271429
14281430test "pointer slicing" {
14291431 // In Zig, we prefer using slices over null-terminated pointers.
1430 // You can turn a pointer into a slice using slice syntax:
1432 // You can turn an array into a slice using slice syntax:
14311433 var array = []u8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
1432 const ptr = &array[1];
1433 const slice = ptr[1..3];
1434
1435 assert(slice.ptr == &ptr[1]);
1434 const slice = array[2..4];
14361435 assert(slice.len == 2);
14371436
14381437 // Slices have bounds checking and are therefore protected
......@@ -1622,18 +1621,27 @@ fn foo(bytes: []u8) u32 {
16221621const assert = @import("std").debug.assert;
16231622
16241623test "basic slices" {
1625 var array = []i32{1, 2, 3, 4};
1624 var array = []i32{ 1, 2, 3, 4 };
16261625 // A slice is a pointer and a length. The difference between an array and
16271626 // a slice is that the array's length is part of the type and known at
16281627 // compile-time, whereas the slice's length is known at runtime.
16291628 // Both can be accessed with the `len` field.
16301629 const slice = array[0..array.len];
1631 assert(slice.ptr == &array[0]);
1630 assert(&slice[0] == &array[0]);
16321631 assert(slice.len == array.len);
16331632
1633 // Using the address-of operator on a slice gives a pointer to a single
1634 // item, while using the `ptr` field gives an unknown length pointer.
1635 assert(@typeOf(slice.ptr) == [*]i32);
1636 assert(@typeOf(&slice[0]) == *i32);
1637 assert(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));
1638
16341639 // Slices have array bounds checking. If you try to access something out
16351640 // of bounds, you'll get a safety check failure:
16361641 slice[10] += 1;
1642
1643 // Note that `slice.ptr` does not invoke safety checking, while `&slice[0]`
1644 // asserts that the slice has len >= 1.
16371645}
16381646 {#code_end#}
16391647 <p>This is one reason we prefer slices to pointers.</p>
......@@ -5937,7 +5945,7 @@ pub const __zig_test_fn_slice = {}; // overwritten later
59375945 {#header_open|C String Literals#}
59385946 {#code_begin|exe#}
59395947 {#link_libc#}
5940extern fn puts(*const u8) void;
5948extern fn puts([*]const u8) void;
59415949
59425950pub fn main() void {
59435951 puts(c"this has a null terminator");
src/all_types.hpp+9
......@@ -974,8 +974,14 @@ struct FnTypeId {
974974uint32_t fn_type_id_hash(FnTypeId*);
975975bool fn_type_id_eql(FnTypeId *a, FnTypeId *b);
976976
977enum PtrLen {
978 PtrLenUnknown,
979 PtrLenSingle,
980};
981
977982struct TypeTableEntryPointer {
978983 TypeTableEntry *child_type;
984 PtrLen ptr_len;
979985 bool is_const;
980986 bool is_volatile;
981987 uint32_t alignment;
......@@ -1397,6 +1403,7 @@ struct TypeId {
13971403 union {
13981404 struct {
13991405 TypeTableEntry *child_type;
1406 PtrLen ptr_len;
14001407 bool is_const;
14011408 bool is_volatile;
14021409 uint32_t alignment;
......@@ -2268,6 +2275,7 @@ struct IrInstructionElemPtr {
22682275
22692276 IrInstruction *array_ptr;
22702277 IrInstruction *elem_index;
2278 PtrLen ptr_len;
22712279 bool is_const;
22722280 bool safety_check_on;
22732281};
......@@ -2419,6 +2427,7 @@ struct IrInstructionPtrType {
24192427 IrInstruction *child_type;
24202428 uint32_t bit_offset_start;
24212429 uint32_t bit_offset_end;
2430 PtrLen ptr_len;
24222431 bool is_const;
24232432 bool is_volatile;
24242433};
src/analyze.cpp+36-17
......@@ -381,14 +381,14 @@ TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) {
381381}
382382
383383TypeTableEntry *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)
385385{
386386 assert(!type_is_invalid(child_type));
387387
388388 TypeId type_id = {};
389389 TypeTableEntry **parent_pointer = nullptr;
390390 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) {
392392 type_id.id = TypeTableEntryIdPointer;
393393 type_id.data.pointer.child_type = child_type;
394394 type_id.data.pointer.is_const = is_const;
......@@ -396,6 +396,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
396396 type_id.data.pointer.alignment = byte_alignment;
397397 type_id.data.pointer.bit_offset = bit_offset;
398398 type_id.data.pointer.unaligned_bit_count = unaligned_bit_count;
399 type_id.data.pointer.ptr_len = ptr_len;
399400
400401 auto existing_entry = g->type_table.maybe_get(type_id);
401402 if (existing_entry)
......@@ -414,16 +415,17 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
414415 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPointer);
415416 entry->is_copyable = true;
416417
418 const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]";
417419 const char *const_str = is_const ? "const " : "";
418420 const char *volatile_str = is_volatile ? "volatile " : "";
419421 buf_resize(&entry->name, 0);
420422 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));
422424 } 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,
424426 const_str, volatile_str, buf_ptr(&child_type->name));
425427 } 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,
427429 bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));
428430 }
429431
......@@ -433,7 +435,9 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
433435
434436 if (!entry->zero_bits) {
435437 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 {
437441 TypeTableEntry *peer_type = get_pointer_to_type(g, child_type, false);
438442 entry->type_ref = peer_type->type_ref;
439443 entry->di_type = peer_type->di_type;
......@@ -451,6 +455,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
451455 entry->di_type = g->builtin_types.entry_void->di_type;
452456 }
453457
458 entry->data.pointer.ptr_len = ptr_len;
454459 entry->data.pointer.child_type = child_type;
455460 entry->data.pointer.is_const = is_const;
456461 entry->data.pointer.is_volatile = is_volatile;
......@@ -467,7 +472,8 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
467472}
468473
469474TypeTableEntry *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);
471477}
472478
473479TypeTableEntry *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
757763
758764TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
759765 assert(ptr_type->id == TypeTableEntryIdPointer);
766 assert(ptr_type->data.pointer.ptr_len == PtrLenUnknown);
760767
761768 TypeTableEntry **parent_pointer = &ptr_type->data.pointer.slice_parent;
762769 if (*parent_pointer) {
......@@ -768,14 +775,16 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
768775
769776 // replace the & with [] to go from a ptr type name to a slice type name
770777 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);
772780
773781 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);
775783 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)
777785 {
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);
779788 TypeTableEntry *peer_slice_type = get_slice_type(g, peer_ptr_type);
780789
781790 slice_type_common_init(g, ptr_type, entry);
......@@ -799,9 +808,11 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
799808 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
800809 child_ptr_type->data.pointer.alignment != get_abi_alignment(g, grand_child_type))
801810 {
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);
803813 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);
805816 TypeTableEntry *peer_slice_type = get_slice_type(g, peer_ptr_type);
806817
807818 entry->type_ref = peer_slice_type->type_ref;
......@@ -1284,7 +1295,8 @@ static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_
12841295}
12851296
12861297static 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);
12881300 TypeTableEntry *str_type = get_slice_type(g, ptr_type);
12891301 IrInstruction *instr = analyze_const_value(g, scope, node, str_type, nullptr);
12901302 if (type_is_invalid(instr->value.type))
......@@ -2954,7 +2966,8 @@ static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {
29542966 if (fn_type_id->param_count != 2) {
29552967 return wrong_panic_prototype(g, proto_node, fn_type);
29562968 }
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);
29582971 TypeTableEntry *const_u8_slice = get_slice_type(g, const_u8_ptr);
29592972 if (fn_type_id->param_info[0].type != const_u8_slice) {
29602973 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) {
49945007
49955008 // then make the pointer point to it
49965009 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);
49985013 const_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
49995014 const_val->data.x_ptr.data.base_array.array_val = array_val;
50005015 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
51355150{
51365151 assert(array_val->type->id == TypeTableEntryIdArray);
51375152
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);
51395156
51405157 const_val->special = ConstValSpecialStatic;
51415158 const_val->type = get_slice_type(g, ptr_type);
......@@ -5759,6 +5776,7 @@ uint32_t type_id_hash(TypeId x) {
57595776 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);
57605777 case TypeTableEntryIdPointer:
57615778 return hash_ptr(x.data.pointer.child_type) +
5779 ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +
57625780 (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +
57635781 (x.data.pointer.is_volatile ? (uint32_t)536730450 : (uint32_t)1685612214) +
57645782 (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +
......@@ -5807,6 +5825,7 @@ bool type_id_eql(TypeId a, TypeId b) {
58075825
58085826 case TypeTableEntryIdPointer:
58095827 return a.data.pointer.child_type == b.data.pointer.child_type &&
5828 a.data.pointer.ptr_len == b.data.pointer.ptr_len &&
58105829 a.data.pointer.is_const == b.data.pointer.is_const &&
58115830 a.data.pointer.is_volatile == b.data.pointer.is_volatile &&
58125831 a.data.pointer.alignment == b.data.pointer.alignment &&
src/analyze.hpp+1-1
......@@ -16,7 +16,7 @@ ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *m
1616TypeTableEntry *new_type_table_entry(TypeTableEntryId id);
1717TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);
1818TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,
19 bool is_volatile, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count);
19 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count);
2020uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
2121uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry);
2222TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_bits);
src/ast_render.cpp+7-1
......@@ -625,7 +625,13 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
625625 case NodeTypePointerType:
626626 {
627627 if (!grouped) fprintf(ar->f, "(");
628 fprintf(ar->f, "*");
628 const char *star = "[*]";
629 if (node->data.pointer_type.star_token != nullptr &&
630 (node->data.pointer_type.star_token->id == TokenIdStar || node->data.pointer_type.star_token->id == TokenIdStarStar))
631 {
632 star = "*";
633 }
634 fprintf(ar->f, "%s", star);
629635 if (node->data.pointer_type.align_expr != nullptr) {
630636 fprintf(ar->f, "align(");
631637 render_node_grouped(ar, node->data.pointer_type.align_expr);
src/codegen.cpp+35-14
......@@ -893,7 +893,8 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
893893 assert(val->global_refs->llvm_global);
894894 }
895895
896 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
896 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
897 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
897898 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
898899 return LLVMConstBitCast(val->global_refs->llvm_global, LLVMPointerType(str_type->type_ref, 0));
899900}
......@@ -1461,7 +1462,8 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
14611462 LLVMValueRef full_buf_ptr = LLVMConstInBoundsGEP(global_array, full_buf_ptr_indices, 2);
14621463
14631464
1464 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
1465 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
1466 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
14651467 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
14661468 LLVMValueRef global_slice_fields[] = {
14671469 full_buf_ptr,
......@@ -2212,9 +2214,13 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
22122214 IrInstruction *op2 = bin_op_instruction->op2;
22132215
22142216 assert(op1->value.type == op2->value.type || op_id == IrBinOpBitShiftLeftLossy ||
2215 op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||
2216 op_id == IrBinOpBitShiftRightExact ||
2217 (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet));
2217 op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||
2218 op_id == IrBinOpBitShiftRightExact ||
2219 (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) ||
2220 (op1->value.type->id == TypeTableEntryIdPointer &&
2221 (op_id == IrBinOpAdd || op_id == IrBinOpSub) &&
2222 op1->value.type->data.pointer.ptr_len == PtrLenUnknown)
2223 );
22182224 TypeTableEntry *type_entry = op1->value.type;
22192225
22202226 bool want_runtime_safety = bin_op_instruction->safety_check_on &&
......@@ -2222,6 +2228,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
22222228
22232229 LLVMValueRef op1_value = ir_llvm_value(g, op1);
22242230 LLVMValueRef op2_value = ir_llvm_value(g, op2);
2231
2232
22252233 switch (op_id) {
22262234 case IrBinOpInvalid:
22272235 case IrBinOpArrayCat:
......@@ -2260,7 +2268,11 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
22602268 }
22612269 case IrBinOpAdd:
22622270 case IrBinOpAddWrap:
2263 if (type_entry->id == TypeTableEntryIdFloat) {
2271 if (type_entry->id == TypeTableEntryIdPointer) {
2272 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
2273 // TODO runtime safety
2274 return LLVMBuildInBoundsGEP(g->builder, op1_value, &op2_value, 1, "");
2275 } else if (type_entry->id == TypeTableEntryIdFloat) {
22642276 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
22652277 return LLVMBuildFAdd(g->builder, op1_value, op2_value, "");
22662278 } else if (type_entry->id == TypeTableEntryIdInt) {
......@@ -2323,7 +2335,12 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
23232335 }
23242336 case IrBinOpSub:
23252337 case IrBinOpSubWrap:
2326 if (type_entry->id == TypeTableEntryIdFloat) {
2338 if (type_entry->id == TypeTableEntryIdPointer) {
2339 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
2340 // TODO runtime safety
2341 LLVMValueRef subscript_value = LLVMBuildNeg(g->builder, op2_value, "");
2342 return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, "");
2343 } else if (type_entry->id == TypeTableEntryIdFloat) {
23272344 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
23282345 return LLVMBuildFSub(g->builder, op1_value, op2_value, "");
23292346 } else if (type_entry->id == TypeTableEntryIdInt) {
......@@ -2770,7 +2787,7 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
27702787 if (have_init_expr) {
27712788 assert(var->value->type == init_value->value.type);
27722789 TypeTableEntry *var_ptr_type = get_pointer_to_type_extra(g, var->value->type, false, false,
2773 var->align_bytes, 0, 0);
2790 PtrLenSingle, var->align_bytes, 0, 0);
27742791 gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value));
27752792 } else {
27762793 bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base);
......@@ -4172,7 +4189,7 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable,
41724189 uint32_t field_align_bytes = get_abi_alignment(g, type_struct_field->type_entry);
41734190
41744191 TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_struct_field->type_entry,
4175 false, false, field_align_bytes,
4192 false, false, PtrLenSingle, field_align_bytes,
41764193 (uint32_t)type_struct_field->packed_bits_offset, (uint32_t)type_struct_field->unaligned_bit_count);
41774194
41784195 gen_assign_raw(g, field_ptr, ptr_type, value);
......@@ -4188,7 +4205,7 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I
41884205
41894206 uint32_t field_align_bytes = get_abi_alignment(g, type_union_field->type_entry);
41904207 TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_union_field->type_entry,
4191 false, false, field_align_bytes,
4208 false, false, PtrLenSingle, field_align_bytes,
41924209 0, 0);
41934210
41944211 LLVMValueRef uncasted_union_ptr;
......@@ -4435,7 +4452,8 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
44354452
44364453 LLVMPositionBuilderAtEnd(g->builder, ok_block);
44374454 LLVMValueRef payload_ptr = LLVMBuildStructGEP(g->builder, sret_ptr, err_union_payload_index, "");
4438 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
4455 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
4456 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
44394457 TypeTableEntry *slice_type = get_slice_type(g, u8_ptr_type);
44404458 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
44414459 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, payload_ptr, ptr_field_index, "");
......@@ -5377,7 +5395,8 @@ static void generate_error_name_table(CodeGen *g) {
53775395
53785396 assert(g->errors_by_index.length > 0);
53795397
5380 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
5398 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
5399 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
53815400 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
53825401
53835402 LLVMValueRef *values = allocate<LLVMValueRef>(g->errors_by_index.length);
......@@ -5415,7 +5434,8 @@ static void generate_error_name_table(CodeGen *g) {
54155434}
54165435
54175436static void generate_enum_name_tables(CodeGen *g) {
5418 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
5437 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
5438 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
54195439 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
54205440
54215441 TypeTableEntry *usize = g->builtin_types.entry_usize;
......@@ -6869,7 +6889,8 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
68696889 exit(0);
68706890 }
68716891
6872 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
6892 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
6893 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
68736894 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
68746895 TypeTableEntry *fn_type = get_test_fn_type(g);
68756896
src/ir.cpp+126-51
......@@ -1009,12 +1009,13 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so
10091009}
10101010
10111011static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr,
1012 IrInstruction *elem_index, bool safety_check_on)
1012 IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len)
10131013{
10141014 IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node);
10151015 instruction->array_ptr = array_ptr;
10161016 instruction->elem_index = elem_index;
10171017 instruction->safety_check_on = safety_check_on;
1018 instruction->ptr_len = ptr_len;
10181019
10191020 ir_ref_instruction(array_ptr, irb->current_basic_block);
10201021 ir_ref_instruction(elem_index, irb->current_basic_block);
......@@ -1022,15 +1023,6 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s
10221023 return &instruction->base;
10231024}
10241025
1025static IrInstruction *ir_build_elem_ptr_from(IrBuilder *irb, IrInstruction *old_instruction,
1026 IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on)
1027{
1028 IrInstruction *new_instruction = ir_build_elem_ptr(irb, old_instruction->scope,
1029 old_instruction->source_node, array_ptr, elem_index, safety_check_on);
1030 ir_link_new_instruction(new_instruction, old_instruction);
1031 return new_instruction;
1032}
1033
10341026static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node,
10351027 IrInstruction *container_ptr, IrInstruction *field_name_expr)
10361028{
......@@ -1188,14 +1180,15 @@ static IrInstruction *ir_build_br_from(IrBuilder *irb, IrInstruction *old_instru
11881180}
11891181
11901182static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
1191 IrInstruction *child_type, bool is_const, bool is_volatile, IrInstruction *align_value,
1192 uint32_t bit_offset_start, uint32_t bit_offset_end)
1183 IrInstruction *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,
1184 IrInstruction *align_value, uint32_t bit_offset_start, uint32_t bit_offset_end)
11931185{
11941186 IrInstructionPtrType *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrType>(irb, scope, source_node);
11951187 ptr_type_of_instruction->align_value = align_value;
11961188 ptr_type_of_instruction->child_type = child_type;
11971189 ptr_type_of_instruction->is_const = is_const;
11981190 ptr_type_of_instruction->is_volatile = is_volatile;
1191 ptr_type_of_instruction->ptr_len = ptr_len;
11991192 ptr_type_of_instruction->bit_offset_start = bit_offset_start;
12001193 ptr_type_of_instruction->bit_offset_end = bit_offset_end;
12011194
......@@ -3547,7 +3540,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode
35473540 return subscript_instruction;
35483541
35493542 IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
3550 subscript_instruction, true);
3543 subscript_instruction, true, PtrLenSingle);
35513544 if (lval.is_ptr)
35523545 return ptr_instruction;
35533546
......@@ -4626,6 +4619,11 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
46264619
46274620static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) {
46284621 assert(node->type == NodeTypePointerType);
4622 // The null check here is for C imports which don't set a token on the AST node. We could potentially
4623 // update that code to create a fake token and then remove this check.
4624 PtrLen ptr_len = (node->data.pointer_type.star_token != nullptr &&
4625 (node->data.pointer_type.star_token->id == TokenIdStar ||
4626 node->data.pointer_type.star_token->id == TokenIdStarStar)) ? PtrLenSingle : PtrLenUnknown;
46294627 bool is_const = node->data.pointer_type.is_const;
46304628 bool is_volatile = node->data.pointer_type.is_volatile;
46314629 AstNode *expr_node = node->data.pointer_type.op_expr;
......@@ -4675,7 +4673,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
46754673 }
46764674
46774675 return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile,
4678 align_value, bit_offset_start, bit_offset_end);
4676 ptr_len, align_value, bit_offset_start, bit_offset_end);
46794677}
46804678
46814679static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node,
......@@ -5172,7 +5170,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
51725170 ir_mark_gen(ir_build_cond_br(irb, child_scope, node, cond, body_block, else_block, is_comptime));
51735171
51745172 ir_set_cursor_at_end_and_append_block(irb, body_block);
5175 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, child_scope, node, array_val_ptr, index_val, false);
5173 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, child_scope, node, array_val_ptr, index_val, false, PtrLenSingle);
51765174 IrInstruction *elem_val;
51775175 if (node->data.for_expr.elem_is_ptr) {
51785176 elem_val = elem_ptr;
......@@ -6811,9 +6809,13 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
68116809
68126810 ir_set_cursor_at_end_and_append_block(irb, irb->exec->coro_normal_final);
68136811 if (type_has_bits(return_type)) {
6812 IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node,
6813 get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8,
6814 false, false, PtrLenUnknown, get_abi_alignment(irb->codegen, irb->codegen->builtin_types.entry_u8),
6815 0, 0));
68146816 IrInstruction *result_ptr = ir_build_load_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr);
6815 IrInstruction *result_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, result_ptr);
6816 IrInstruction *return_value_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type,
6817 IrInstruction *result_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len, result_ptr);
6818 IrInstruction *return_value_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len,
68176819 irb->exec->coro_result_field_ptr);
68186820 IrInstruction *return_type_inst = ir_build_const_type(irb, scope, node,
68196821 fn_entry->type_entry->data.fn.fn_type_id.return_type);
......@@ -7691,6 +7693,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
76917693 // pointer const
76927694 if (expected_type->id == TypeTableEntryIdPointer &&
76937695 actual_type->id == TypeTableEntryIdPointer &&
7696 (actual_type->data.pointer.ptr_len == expected_type->data.pointer.ptr_len) &&
76947697 (!actual_type->data.pointer.is_const || expected_type->data.pointer.is_const) &&
76957698 (!actual_type->data.pointer.is_volatile || expected_type->data.pointer.is_volatile) &&
76967699 actual_type->data.pointer.bit_offset == expected_type->data.pointer.bit_offset &&
......@@ -8644,7 +8647,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
86448647
86458648 if (convert_to_const_slice) {
86468649 assert(prev_inst->value.type->id == TypeTableEntryIdArray);
8647 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, prev_inst->value.type->data.array.child_type, true);
8650 TypeTableEntry *ptr_type = get_pointer_to_type_extra(
8651 ira->codegen, prev_inst->value.type->data.array.child_type,
8652 true, false, PtrLenUnknown,
8653 get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type),
8654 0, 0);
86488655 TypeTableEntry *slice_type = get_slice_type(ira->codegen, ptr_type);
86498656 if (err_set_type != nullptr) {
86508657 return get_error_union_type(ira->codegen, err_set_type, slice_type);
......@@ -8961,7 +8968,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
89618968 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
89628969{
89638970 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
8964 ptr_is_const, ptr_is_volatile, ptr_align, 0, 0);
8971 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0);
89658972 IrInstruction *const_instr = ir_get_const(ira, instruction);
89668973 ConstExprValue *const_val = &const_instr->value;
89678974 const_val->type = ptr_type;
......@@ -9302,7 +9309,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
93029309 }
93039310
93049311 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type,
9305 is_const, is_volatile, get_abi_alignment(ira->codegen, value->value.type), 0, 0);
9312 is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0);
93069313 IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope,
93079314 source_instruction->source_node, value, is_const, is_volatile);
93089315 new_instruction->value.type = ptr_type;
......@@ -10399,7 +10406,9 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
1039910406 if (type_is_invalid(value->value.type))
1040010407 return nullptr;
1040110408
10402 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
10409 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
10410 true, false, PtrLenUnknown,
10411 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
1040310412 TypeTableEntry *str_type = get_slice_type(ira->codegen, ptr_type);
1040410413 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
1040510414 if (type_is_invalid(casted_value->value.type))
......@@ -11054,11 +11063,27 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1105411063static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
1105511064 IrInstruction *op1 = bin_op_instruction->op1->other;
1105611065 IrInstruction *op2 = bin_op_instruction->op2->other;
11066 IrBinOp op_id = bin_op_instruction->op_id;
11067
11068 // look for pointer math
11069 if (op1->value.type->id == TypeTableEntryIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown &&
11070 (op_id == IrBinOpAdd || op_id == IrBinOpSub))
11071 {
11072 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
11073 if (casted_op2 == ira->codegen->invalid_instruction)
11074 return ira->codegen->builtin_types.entry_invalid;
11075
11076 IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope,
11077 bin_op_instruction->base.source_node, op_id, op1, casted_op2, true);
11078 result->value.type = op1->value.type;
11079 ir_link_new_instruction(result, &bin_op_instruction->base);
11080 return result->value.type;
11081 }
11082
1105711083 IrInstruction *instructions[] = {op1, op2};
1105811084 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2);
1105911085 if (type_is_invalid(resolved_type))
1106011086 return resolved_type;
11061 IrBinOp op_id = bin_op_instruction->op_id;
1106211087
1106311088 bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdNumLitInt;
1106411089 bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdNumLitFloat;
......@@ -11331,7 +11356,8 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1133111356
1133211357 out_array_val = out_val;
1133311358 } else if (is_slice(op1_type) || is_slice(op2_type)) {
11334 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, child_type, true);
11359 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
11360 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0);
1133511361 result_type = get_slice_type(ira->codegen, ptr_type);
1133611362 out_array_val = create_const_vals(1);
1133711363 out_array_val->special = ConstValSpecialStatic;
......@@ -11351,7 +11377,9 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1135111377 } else {
1135211378 new_len += 1; // null byte
1135311379
11354 result_type = get_pointer_to_type(ira->codegen, child_type, true);
11380 // TODO make this `[*]null T` instead of `[*]T`
11381 result_type = get_pointer_to_type_extra(ira->codegen, child_type, true, false,
11382 PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0);
1135511383
1135611384 out_array_val = create_const_vals(1);
1135711385 out_array_val->special = ConstValSpecialStatic;
......@@ -12173,7 +12201,7 @@ no_mem_slot:
1217312201 IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb,
1217412202 instruction->scope, instruction->source_node, var);
1217512203 var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type,
12176 var->src_is_const, is_volatile, var->align_bytes, 0, 0);
12204 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0);
1217712205 type_ensure_zero_bits_known(ira->codegen, var->value->type);
1217812206
1217912207 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);
......@@ -12352,7 +12380,9 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1235212380
1235312381 IrInstruction *casted_new_stack = nullptr;
1235412382 if (call_instruction->new_stack != nullptr) {
12355 TypeTableEntry *u8_ptr = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
12383 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
12384 false, false, PtrLenUnknown,
12385 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
1235612386 TypeTableEntry *u8_slice = get_slice_type(ira->codegen, u8_ptr);
1235712387 IrInstruction *new_stack = call_instruction->new_stack->other;
1235812388 if (type_is_invalid(new_stack->value.type))
......@@ -13112,10 +13142,21 @@ static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, ui
1311213142 return get_pointer_to_type_extra(g,
1311313143 ptr_type->data.pointer.child_type,
1311413144 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
13145 ptr_type->data.pointer.ptr_len,
1311513146 new_align,
1311613147 ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);
1311713148}
1311813149
13150static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrLen ptr_len) {
13151 assert(ptr_type->id == TypeTableEntryIdPointer);
13152 return get_pointer_to_type_extra(g,
13153 ptr_type->data.pointer.child_type,
13154 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
13155 ptr_len,
13156 ptr_type->data.pointer.alignment,
13157 ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);
13158}
13159
1311913160static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
1312013161 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other;
1312113162 if (type_is_invalid(array_ptr->value.type))
......@@ -13146,6 +13187,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1314613187 if (ptr_type->data.pointer.unaligned_bit_count == 0) {
1314713188 return_type = get_pointer_to_type_extra(ira->codegen, child_type,
1314813189 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
13190 elem_ptr_instruction->ptr_len,
1314913191 ptr_type->data.pointer.alignment, 0, 0);
1315013192 } else {
1315113193 uint64_t elem_val_scalar;
......@@ -13157,12 +13199,19 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1315713199
1315813200 return_type = get_pointer_to_type_extra(ira->codegen, child_type,
1315913201 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
13202 elem_ptr_instruction->ptr_len,
1316013203 1, (uint32_t)bit_offset, (uint32_t)bit_width);
1316113204 }
1316213205 } else if (array_type->id == TypeTableEntryIdPointer) {
13163 return_type = array_type;
13206 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
13207 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
13208 buf_sprintf("indexing not allowed on pointer to single item"));
13209 return ira->codegen->builtin_types.entry_invalid;
13210 }
13211 return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len);
1316413212 } else if (is_slice(array_type)) {
13165 return_type = array_type->data.structure.fields[slice_ptr_index].type_entry;
13213 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry,
13214 elem_ptr_instruction->ptr_len);
1316613215 } else if (array_type->id == TypeTableEntryIdArgTuple) {
1316713216 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
1316813217 if (!ptr_val)
......@@ -13304,8 +13353,10 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1330413353 } else if (is_slice(array_type)) {
1330513354 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];
1330613355 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
13307 ir_build_elem_ptr_from(&ira->new_irb, &elem_ptr_instruction->base, array_ptr,
13308 casted_elem_index, false);
13356 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
13357 array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len);
13358 result->value.type = return_type;
13359 ir_link_new_instruction(result, &elem_ptr_instruction->base);
1330913360 return return_type;
1331013361 }
1331113362 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
......@@ -13373,8 +13424,10 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1337313424 }
1337413425 }
1337513426
13376 ir_build_elem_ptr_from(&ira->new_irb, &elem_ptr_instruction->base, array_ptr,
13377 casted_elem_index, safety_check_on);
13427 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
13428 array_ptr, casted_elem_index, safety_check_on, elem_ptr_instruction->ptr_len);
13429 result->value.type = return_type;
13430 ir_link_new_instruction(result, &elem_ptr_instruction->base);
1337813431 return return_type;
1337913432}
1338013433
......@@ -13449,7 +13502,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1344913502 return ira->codegen->invalid_instruction;
1345013503 ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index];
1345113504 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type,
13452 is_const, is_volatile, align_bytes,
13505 is_const, is_volatile, PtrLenSingle, align_bytes,
1345313506 (uint32_t)(ptr_bit_offset + field->packed_bits_offset),
1345413507 (uint32_t)unaligned_bit_count_for_result_type);
1345513508 IrInstruction *result = ir_get_const(ira, source_instr);
......@@ -13465,6 +13518,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1346513518 IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node,
1346613519 container_ptr, field);
1346713520 result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile,
13521 PtrLenSingle,
1346813522 align_bytes,
1346913523 (uint32_t)(ptr_bit_offset + field->packed_bits_offset),
1347013524 (uint32_t)unaligned_bit_count_for_result_type);
......@@ -13511,7 +13565,9 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1351113565 payload_val->type = field_type;
1351213566 }
1351313567
13514 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, is_const, is_volatile,
13568 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
13569 is_const, is_volatile,
13570 PtrLenSingle,
1351513571 get_abi_alignment(ira->codegen, field_type), 0, 0);
1351613572
1351713573 IrInstruction *result = ir_get_const(ira, source_instr);
......@@ -13526,7 +13582,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1352613582
1352713583 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field);
1352813584 result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile,
13529 get_abi_alignment(ira->codegen, field->type_entry), 0, 0);
13585 PtrLenSingle, get_abi_alignment(ira->codegen, field->type_entry), 0, 0);
1353013586 return result;
1353113587 } else {
1353213588 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
......@@ -14119,7 +14175,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
1411914175 if (type_entry->id == TypeTableEntryIdArray) {
1412014176 ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false);
1412114177 } else if (is_slice(type_entry)) {
14122 ptr_type = type_entry->data.structure.fields[0].type_entry;
14178 ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle);
1412314179 } else if (type_entry->id == TypeTableEntryIdArgTuple) {
1412414180 ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad);
1412514181 if (!arg_tuple_val)
......@@ -14367,7 +14423,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1436714423 {
1436814424 type_ensure_zero_bits_known(ira->codegen, child_type);
1436914425 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
14370 is_const, is_volatile, align_bytes, 0, 0);
14426 is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0);
1437114427 TypeTableEntry *result_type = get_slice_type(ira->codegen, slice_ptr_type);
1437214428 ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base);
1437314429 out_val->data.x_type = result_type;
......@@ -14619,6 +14675,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1461914675 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
1462014676 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
1462114677 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
14678 PtrLenSingle,
1462214679 get_abi_alignment(ira->codegen, child_type), 0, 0);
1462314680
1462414681 if (instr_is_comptime(value)) {
......@@ -15566,7 +15623,8 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
1556615623 if (type_is_invalid(casted_value->value.type))
1556715624 return ira->codegen->builtin_types.entry_invalid;
1556815625
15569 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
15626 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
15627 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
1557015628 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
1557115629 if (casted_value->value.special == ConstValSpecialStatic) {
1557215630 ErrorTableEntry *err = casted_value->value.data.x_err_set;
......@@ -15607,7 +15665,11 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn
1560715665 IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope,
1560815666 instruction->base.source_node, target);
1560915667 ir_link_new_instruction(result, &instruction->base);
15610 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
15668 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(
15669 ira->codegen, ira->codegen->builtin_types.entry_u8,
15670 true, false, PtrLenUnknown,
15671 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8),
15672 0, 0);
1561115673 result->value.type = get_slice_type(ira->codegen, u8_ptr_type);
1561215674 return result->value.type;
1561315675}
......@@ -15660,6 +15722,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1566015722 TypeTableEntry *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,
1566115723 field_ptr->value.type->data.pointer.is_const,
1566215724 field_ptr->value.type->data.pointer.is_volatile,
15725 PtrLenSingle,
1566315726 field_ptr_align, 0, 0);
1566415727 IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);
1566515728 if (type_is_invalid(casted_field_ptr->value.type))
......@@ -15668,6 +15731,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1566815731 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
1566915732 casted_field_ptr->value.type->data.pointer.is_const,
1567015733 casted_field_ptr->value.type->data.pointer.is_volatile,
15734 PtrLenSingle,
1567115735 parent_ptr_align, 0, 0);
1567215736
1567315737 if (instr_is_comptime(casted_field_ptr)) {
......@@ -15983,11 +16047,13 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1598316047 // lib_name: ?[]const u8
1598416048 ensure_field_index(fn_def_val->type, "lib_name", 6);
1598516049 fn_def_fields[6].special = ConstValSpecialStatic;
15986 fn_def_fields[6].type = get_maybe_type(ira->codegen,
15987 get_slice_type(ira->codegen, get_pointer_to_type(ira->codegen,
15988 ira->codegen->builtin_types.entry_u8, true)));
15989 if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0)
15990 {
16050 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(
16051 ira->codegen, ira->codegen->builtin_types.entry_u8,
16052 true, false, PtrLenUnknown,
16053 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8),
16054 0, 0);
16055 fn_def_fields[6].type = get_maybe_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
16056 if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) {
1599116057 fn_def_fields[6].data.x_maybe = create_const_vals(1);
1599216058 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name);
1599316059 init_const_slice(ira->codegen, fn_def_fields[6].data.x_maybe, lib_name, 0, buf_len(fn_node->lib_name), true);
......@@ -16009,8 +16075,8 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1600916075 size_t fn_arg_count = fn_entry->variable_list.length;
1601016076 ConstExprValue *fn_arg_name_array = create_const_vals(1);
1601116077 fn_arg_name_array->special = ConstValSpecialStatic;
16012 fn_arg_name_array->type = get_array_type(ira->codegen, get_slice_type(ira->codegen,
16013 get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true)), fn_arg_count);
16078 fn_arg_name_array->type = get_array_type(ira->codegen,
16079 get_slice_type(ira->codegen, u8_ptr), fn_arg_count);
1601416080 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;
1601516081 fn_arg_name_array->data.x_array.s_none.parent.id = ConstParentIdNone;
1601616082 fn_arg_name_array->data.x_array.s_none.elements = create_const_vals(fn_arg_count);
......@@ -17088,7 +17154,8 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
1708817154 TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;
1708917155 uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ?
1709017156 dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
17091 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, dest_align, 0, 0);
17157 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
17158 PtrLenUnknown, dest_align, 0, 0);
1709217159
1709317160 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
1709417161 if (type_is_invalid(casted_dest_ptr->value.type))
......@@ -17184,8 +17251,10 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
1718417251 src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
1718517252
1718617253 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
17187 TypeTableEntry *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, dest_align, 0, 0);
17188 TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, src_align, 0, 0);
17254 TypeTableEntry *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
17255 PtrLenUnknown, dest_align, 0, 0);
17256 TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
17257 PtrLenUnknown, src_align, 0, 0);
1718917258
1719017259 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
1719117260 if (type_is_invalid(casted_dest_ptr->value.type))
......@@ -17333,11 +17402,13 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1733317402 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
1733417403 ptr_type->data.pointer.is_const || is_comptime_const,
1733517404 ptr_type->data.pointer.is_volatile,
17405 PtrLenUnknown,
1733617406 byte_alignment, 0, 0);
1733717407 return_type = get_slice_type(ira->codegen, slice_ptr_type);
1733817408 } else if (array_type->id == TypeTableEntryIdPointer) {
1733917409 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type,
1734017410 array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,
17411 PtrLenUnknown,
1734117412 array_type->data.pointer.alignment, 0, 0);
1734217413 return_type = get_slice_type(ira->codegen, slice_ptr_type);
1734317414 if (!end) {
......@@ -17774,6 +17845,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1777417845 if (result_ptr->value.type->id == TypeTableEntryIdPointer) {
1777517846 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
1777617847 false, result_ptr->value.type->data.pointer.is_volatile,
17848 PtrLenSingle,
1777717849 result_ptr->value.type->data.pointer.alignment, 0, 0);
1777817850 } else {
1777917851 expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);
......@@ -17929,6 +18001,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1792918001 TypeTableEntry *payload_type = type_entry->data.error_union.payload_type;
1793018002 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,
1793118003 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
18004 PtrLenSingle,
1793218005 get_abi_alignment(ira->codegen, payload_type), 0, 0);
1793318006 if (instr_is_comptime(value)) {
1793418007 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
......@@ -18270,7 +18343,8 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio
1827018343 return ir_unreach_error(ira);
1827118344 }
1827218345
18273 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
18346 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
18347 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
1827418348 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
1827518349 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
1827618350 if (type_is_invalid(casted_msg->value.type))
......@@ -18801,7 +18875,8 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc
1880118875
1880218876 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1880318877 out_val->data.x_type = get_pointer_to_type_extra(ira->codegen, child_type,
18804 instruction->is_const, instruction->is_volatile, align_bytes,
18878 instruction->is_const, instruction->is_volatile,
18879 instruction->ptr_len, align_bytes,
1880518880 instruction->bit_offset_start, instruction->bit_offset_end - instruction->bit_offset_start);
1880618881
1880718882 return ira->codegen->builtin_types.entry_type;
src/parser.cpp+1
......@@ -1225,6 +1225,7 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index,
12251225 AstNode *child_node = ast_parse_pointer_type(pc, token_index, token);
12261226 child_node->column += 1;
12271227 AstNode *parent_node = ast_create_node(pc, NodeTypePointerType, token);
1228 parent_node->data.pointer_type.star_token = token;
12281229 parent_node->data.pointer_type.op_expr = child_node;
12291230 return parent_node;
12301231 }
std/buffer.zig+1-1
......@@ -122,7 +122,7 @@ pub const Buffer = struct {
122122 }
123123
124124 /// For passing to C functions.
125 pub fn ptr(self: *const Buffer) *u8 {
125 pub fn ptr(self: *const Buffer) [*]u8 {
126126 return self.list.items.ptr;
127127 }
128128};
std/c/darwin.zig+2-2
......@@ -1,7 +1,7 @@
11extern "c" fn __error() *c_int;
2pub extern "c" fn _NSGetExecutablePath(buf: *u8, bufsize: *u32) c_int;
2pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int;
33
4pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: *u8, buf_len: usize, basep: *i64) usize;
4pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize;
55
66pub extern "c" fn mach_absolute_time() u64;
77pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) void;
std/c/index.zig+26-24
......@@ -9,6 +9,8 @@ pub use switch (builtin.os) {
99};
1010const empty_import = @import("../empty.zig");
1111
12// TODO https://github.com/ziglang/zig/issues/265 on this whole file
13
1214pub extern "c" fn abort() noreturn;
1315pub extern "c" fn exit(code: c_int) noreturn;
1416pub extern "c" fn isatty(fd: c_int) c_int;
......@@ -16,45 +18,45 @@ pub extern "c" fn close(fd: c_int) c_int;
1618pub extern "c" fn fstat(fd: c_int, buf: *Stat) c_int;
1719pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: *Stat) c_int;
1820pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) isize;
19pub extern "c" fn open(path: *const u8, oflag: c_int, ...) c_int;
21pub extern "c" fn open(path: [*]const u8, oflag: c_int, ...) c_int;
2022pub extern "c" fn raise(sig: c_int) c_int;
21pub extern "c" fn read(fd: c_int, buf: *c_void, nbyte: usize) isize;
22pub extern "c" fn stat(noalias path: *const u8, noalias buf: *Stat) c_int;
23pub extern "c" fn write(fd: c_int, buf: *const c_void, nbyte: usize) isize;
24pub extern "c" fn mmap(addr: ?*c_void, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: isize) ?*c_void;
25pub extern "c" fn munmap(addr: *c_void, len: usize) c_int;
26pub extern "c" fn unlink(path: *const u8) c_int;
27pub extern "c" fn getcwd(buf: *u8, size: usize) ?*u8;
23pub extern "c" fn read(fd: c_int, buf: [*]c_void, nbyte: usize) isize;
24pub extern "c" fn stat(noalias path: [*]const u8, noalias buf: *Stat) c_int;
25pub extern "c" fn write(fd: c_int, buf: [*]const c_void, nbyte: usize) isize;
26pub extern "c" fn mmap(addr: ?[*]c_void, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: isize) ?[*]c_void;
27pub extern "c" fn munmap(addr: [*]c_void, len: usize) c_int;
28pub extern "c" fn unlink(path: [*]const u8) c_int;
29pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;
2830pub extern "c" fn waitpid(pid: c_int, stat_loc: *c_int, options: c_int) c_int;
2931pub extern "c" fn fork() c_int;
30pub extern "c" fn access(path: *const u8, mode: c_uint) c_int;
31pub extern "c" fn pipe(fds: *c_int) c_int;
32pub extern "c" fn mkdir(path: *const u8, mode: c_uint) c_int;
33pub extern "c" fn symlink(existing: *const u8, new: *const u8) c_int;
34pub extern "c" fn rename(old: *const u8, new: *const u8) c_int;
35pub extern "c" fn chdir(path: *const u8) c_int;
36pub extern "c" fn execve(path: *const u8, argv: *const ?*const u8, envp: *const ?*const u8) c_int;
32pub extern "c" fn access(path: [*]const u8, mode: c_uint) c_int;
33pub extern "c" fn pipe(fds: *[2]c_int) c_int;
34pub extern "c" fn mkdir(path: [*]const u8, mode: c_uint) c_int;
35pub extern "c" fn symlink(existing: [*]const u8, new: [*]const u8) c_int;
36pub extern "c" fn rename(old: [*]const u8, new: [*]const u8) c_int;
37pub extern "c" fn chdir(path: [*]const u8) c_int;
38pub extern "c" fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) c_int;
3739pub extern "c" fn dup(fd: c_int) c_int;
3840pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;
39pub extern "c" fn readlink(noalias path: *const u8, noalias buf: *u8, bufsize: usize) isize;
40pub extern "c" fn realpath(noalias file_name: *const u8, noalias resolved_name: *u8) ?*u8;
41pub extern "c" fn readlink(noalias path: [*]const u8, noalias buf: [*]u8, bufsize: usize) isize;
42pub extern "c" fn realpath(noalias file_name: [*]const u8, noalias resolved_name: [*]u8) ?[*]u8;
4143pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int;
4244pub extern "c" fn gettimeofday(tv: ?*timeval, tz: ?*timezone) c_int;
4345pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
4446pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
4547pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
4648pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
47pub extern "c" fn rmdir(path: *const u8) c_int;
49pub extern "c" fn rmdir(path: [*]const u8) c_int;
4850
49pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?*c_void;
50pub extern "c" fn malloc(usize) ?*c_void;
51pub extern "c" fn realloc(*c_void, usize) ?*c_void;
52pub extern "c" fn free(*c_void) void;
53pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize) c_int;
51pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?[*]c_void;
52pub extern "c" fn malloc(usize) ?[*]c_void;
53pub extern "c" fn realloc([*]c_void, usize) ?[*]c_void;
54pub extern "c" fn free([*]c_void) void;
55pub extern "c" fn posix_memalign(memptr: *[*]c_void, alignment: usize, size: usize) c_int;
5456
5557pub extern "pthread" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: extern fn (?*c_void) ?*c_void, noalias arg: ?*c_void) c_int;
5658pub extern "pthread" fn pthread_attr_init(attr: *pthread_attr_t) c_int;
57pub extern "pthread" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;
59pub extern "pthread" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: [*]c_void, stacksize: usize) c_int;
5860pub extern "pthread" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;
5961pub extern "pthread" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;
6062
std/c/linux.zig+1-1
......@@ -1,6 +1,6 @@
11pub use @import("../os/linux/errno.zig");
22
3pub extern "c" fn getrandom(buf_ptr: *u8, buf_len: usize, flags: c_uint) c_int;
3pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int;
44extern "c" fn __errno_location() *c_int;
55pub const _errno = __errno_location;
66
std/cstr.zig+5-5
......@@ -57,7 +57,7 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![]u8 {
5757pub const NullTerminated2DArray = struct {
5858 allocator: *mem.Allocator,
5959 byte_count: usize,
60 ptr: ?*?*u8,
60 ptr: ?[*]?[*]u8,
6161
6262 /// Takes N lists of strings, concatenates the lists together, and adds a null terminator
6363 /// Caller must deinit result
......@@ -79,12 +79,12 @@ pub const NullTerminated2DArray = struct {
7979 errdefer allocator.free(buf);
8080
8181 var write_index = index_size;
82 const index_buf = ([]?*u8)(buf);
82 const index_buf = ([]?[*]u8)(buf);
8383
8484 var i: usize = 0;
8585 for (slices) |slice| {
8686 for (slice) |inner| {
87 index_buf[i] = &buf[write_index];
87 index_buf[i] = buf.ptr + write_index;
8888 i += 1;
8989 mem.copy(u8, buf[write_index..], inner);
9090 write_index += inner.len;
......@@ -97,12 +97,12 @@ pub const NullTerminated2DArray = struct {
9797 return NullTerminated2DArray{
9898 .allocator = allocator,
9999 .byte_count = byte_count,
100 .ptr = @ptrCast(?*?*u8, buf.ptr),
100 .ptr = @ptrCast(?[*]?[*]u8, buf.ptr),
101101 };
102102 }
103103
104104 pub fn deinit(self: *NullTerminated2DArray) void {
105 const buf = @ptrCast(*u8, self.ptr);
105 const buf = @ptrCast([*]u8, self.ptr);
106106 self.allocator.free(buf[0..self.byte_count]);
107107 }
108108};
std/heap.zig+9-9
......@@ -18,11 +18,11 @@ var c_allocator_state = Allocator{
1818
1919fn cAlloc(self: *Allocator, n: usize, alignment: u29) ![]u8 {
2020 assert(alignment <= @alignOf(c_longdouble));
21 return if (c.malloc(n)) |buf| @ptrCast(*u8, buf)[0..n] else error.OutOfMemory;
21 return if (c.malloc(n)) |buf| @ptrCast([*]u8, buf)[0..n] else error.OutOfMemory;
2222}
2323
2424fn cRealloc(self: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
25 const old_ptr = @ptrCast(*c_void, old_mem.ptr);
25 const old_ptr = @ptrCast([*]c_void, old_mem.ptr);
2626 if (c.realloc(old_ptr, new_size)) |buf| {
2727 return @ptrCast(*u8, buf)[0..new_size];
2828 } else if (new_size <= old_mem.len) {
......@@ -33,7 +33,7 @@ fn cRealloc(self: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![
3333}
3434
3535fn cFree(self: *Allocator, old_mem: []u8) void {
36 const old_ptr = @ptrCast(*c_void, old_mem.ptr);
36 const old_ptr = @ptrCast([*]c_void, old_mem.ptr);
3737 c.free(old_ptr);
3838}
3939
......@@ -74,7 +74,7 @@ pub const DirectAllocator = struct {
7474 const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);
7575 if (addr == p.MAP_FAILED) return error.OutOfMemory;
7676
77 if (alloc_size == n) return @intToPtr(*u8, addr)[0..n];
77 if (alloc_size == n) return @intToPtr([*]u8, addr)[0..n];
7878
7979 var aligned_addr = addr & ~usize(alignment - 1);
8080 aligned_addr += alignment;
......@@ -93,7 +93,7 @@ pub const DirectAllocator = struct {
9393 //It is impossible that there is an unoccupied page at the top of our
9494 // mmap.
9595
96 return @intToPtr(*u8, aligned_addr)[0..n];
96 return @intToPtr([*]u8, aligned_addr)[0..n];
9797 },
9898 Os.windows => {
9999 const amt = n + alignment + @sizeOf(usize);
......@@ -109,7 +109,7 @@ pub const DirectAllocator = struct {
109109 const adjusted_addr = root_addr + march_forward_bytes;
110110 const record_addr = adjusted_addr + n;
111111 @intToPtr(*align(1) usize, record_addr).* = root_addr;
112 return @intToPtr(*u8, adjusted_addr)[0..n];
112 return @intToPtr([*]u8, adjusted_addr)[0..n];
113113 },
114114 else => @compileError("Unsupported OS"),
115115 }
......@@ -140,7 +140,7 @@ pub const DirectAllocator = struct {
140140 const old_adjusted_addr = @ptrToInt(old_mem.ptr);
141141 const old_record_addr = old_adjusted_addr + old_mem.len;
142142 const root_addr = @intToPtr(*align(1) usize, old_record_addr).*;
143 const old_ptr = @intToPtr(os.windows.LPVOID, root_addr);
143 const old_ptr = @intToPtr([*]c_void, root_addr);
144144 const amt = new_size + alignment + @sizeOf(usize);
145145 const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: {
146146 if (new_size > old_mem.len) return error.OutOfMemory;
......@@ -154,7 +154,7 @@ pub const DirectAllocator = struct {
154154 assert(new_adjusted_addr % alignment == 0);
155155 const new_record_addr = new_adjusted_addr + new_size;
156156 @intToPtr(*align(1) usize, new_record_addr).* = new_root_addr;
157 return @intToPtr(*u8, new_adjusted_addr)[0..new_size];
157 return @intToPtr([*]u8, new_adjusted_addr)[0..new_size];
158158 },
159159 else => @compileError("Unsupported OS"),
160160 }
......@@ -170,7 +170,7 @@ pub const DirectAllocator = struct {
170170 Os.windows => {
171171 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;
172172 const root_addr = @intToPtr(*align(1) usize, record_addr).*;
173 const ptr = @intToPtr(os.windows.LPVOID, root_addr);
173 const ptr = @intToPtr([*]c_void, root_addr);
174174 _ = os.windows.HeapFree(??self.heap_handle, 0, ptr);
175175 },
176176 else => @compileError("Unsupported OS"),
std/os/child_process.zig+1-1
......@@ -639,7 +639,7 @@ pub const ChildProcess = struct {
639639 }
640640};
641641
642fn windowsCreateProcess(app_name: *u8, cmd_line: *u8, envp_ptr: ?*u8, cwd_ptr: ?*u8, lpStartupInfo: *windows.STARTUPINFOA, lpProcessInformation: *windows.PROCESS_INFORMATION) !void {
642fn windowsCreateProcess(app_name: [*]u8, cmd_line: [*]u8, envp_ptr: ?[*]u8, cwd_ptr: ?[*]u8, lpStartupInfo: *windows.STARTUPINFOA, lpProcessInformation: *windows.PROCESS_INFORMATION) !void {
643643 if (windows.CreateProcessA(app_name, cmd_line, null, null, windows.TRUE, 0, @ptrCast(?*c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation) == 0) {
644644 const err = windows.GetLastError();
645645 return switch (err) {
std/os/darwin.zig+23-22
......@@ -317,7 +317,8 @@ pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {
317317 return errnoWrap(c.lseek(fd, offset, whence));
318318}
319319
320pub fn open(path: *const u8, flags: u32, mode: usize) usize {
320// TODO https://github.com/ziglang/zig/issues/265 on the whole file
321pub fn open(path: [*]const u8, flags: u32, mode: usize) usize {
321322 return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
322323}
323324
......@@ -325,33 +326,33 @@ pub fn raise(sig: i32) usize {
325326 return errnoWrap(c.raise(sig));
326327}
327328
328pub fn read(fd: i32, buf: *u8, nbyte: usize) usize {
329 return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte));
329pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize {
330 return errnoWrap(c.read(fd, @ptrCast([*]c_void, buf), nbyte));
330331}
331332
332pub fn stat(noalias path: *const u8, noalias buf: *stat) usize {
333pub fn stat(noalias path: [*]const u8, noalias buf: *stat) usize {
333334 return errnoWrap(c.stat(path, buf));
334335}
335336
336pub fn write(fd: i32, buf: *const u8, nbyte: usize) usize {
337 return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte));
337pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize {
338 return errnoWrap(c.write(fd, @ptrCast([*]const c_void, buf), nbyte));
338339}
339340
340pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
341 const ptr_result = c.mmap(@ptrCast(*c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);
341pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
342 const ptr_result = c.mmap(@ptrCast([*]c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);
342343 const isize_result = @bitCast(isize, @ptrToInt(ptr_result));
343344 return errnoWrap(isize_result);
344345}
345346
346347pub fn munmap(address: usize, length: usize) usize {
347 return errnoWrap(c.munmap(@intToPtr(*c_void, address), length));
348 return errnoWrap(c.munmap(@intToPtr([*]c_void, address), length));
348349}
349350
350pub fn unlink(path: *const u8) usize {
351pub fn unlink(path: [*]const u8) usize {
351352 return errnoWrap(c.unlink(path));
352353}
353354
354pub fn getcwd(buf: *u8, size: usize) usize {
355pub fn getcwd(buf: [*]u8, size: usize) usize {
355356 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
356357}
357358
......@@ -364,40 +365,40 @@ pub fn fork() usize {
364365 return errnoWrap(c.fork());
365366}
366367
367pub fn access(path: *const u8, mode: u32) usize {
368pub fn access(path: [*]const u8, mode: u32) usize {
368369 return errnoWrap(c.access(path, mode));
369370}
370371
371372pub fn pipe(fds: *[2]i32) usize {
372373 comptime assert(i32.bit_count == c_int.bit_count);
373 return errnoWrap(c.pipe(@ptrCast(*c_int, fds)));
374 return errnoWrap(c.pipe(@ptrCast(*[2]c_int, fds)));
374375}
375376
376pub fn getdirentries64(fd: i32, buf_ptr: *u8, buf_len: usize, basep: *i64) usize {
377pub fn getdirentries64(fd: i32, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize {
377378 return errnoWrap(@bitCast(isize, c.__getdirentries64(fd, buf_ptr, buf_len, basep)));
378379}
379380
380pub fn mkdir(path: *const u8, mode: u32) usize {
381pub fn mkdir(path: [*]const u8, mode: u32) usize {
381382 return errnoWrap(c.mkdir(path, mode));
382383}
383384
384pub fn symlink(existing: *const u8, new: *const u8) usize {
385pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
385386 return errnoWrap(c.symlink(existing, new));
386387}
387388
388pub fn rename(old: *const u8, new: *const u8) usize {
389pub fn rename(old: [*]const u8, new: [*]const u8) usize {
389390 return errnoWrap(c.rename(old, new));
390391}
391392
392pub fn rmdir(path: *const u8) usize {
393pub fn rmdir(path: [*]const u8) usize {
393394 return errnoWrap(c.rmdir(path));
394395}
395396
396pub fn chdir(path: *const u8) usize {
397pub fn chdir(path: [*]const u8) usize {
397398 return errnoWrap(c.chdir(path));
398399}
399400
400pub fn execve(path: *const u8, argv: *const ?*const u8, envp: *const ?*const u8) usize {
401pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
401402 return errnoWrap(c.execve(path, argv, envp));
402403}
403404
......@@ -405,7 +406,7 @@ pub fn dup2(old: i32, new: i32) usize {
405406 return errnoWrap(c.dup2(old, new));
406407}
407408
408pub fn readlink(noalias path: *const u8, noalias buf_ptr: *u8, buf_len: usize) usize {
409pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
409410 return errnoWrap(c.readlink(path, buf_ptr, buf_len));
410411}
411412
......@@ -417,7 +418,7 @@ pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
417418 return errnoWrap(c.nanosleep(req, rem));
418419}
419420
420pub fn realpath(noalias filename: *const u8, noalias resolved_name: *u8) usize {
421pub fn realpath(noalias filename: [*]const u8, noalias resolved_name: [*]u8) usize {
421422 return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
422423}
423424
std/os/file.zig+2-2
......@@ -313,7 +313,7 @@ pub const File = struct {
313313 if (is_posix) {
314314 var index: usize = 0;
315315 while (index < buffer.len) {
316 const amt_read = posix.read(self.handle, &buffer[index], buffer.len - index);
316 const amt_read = posix.read(self.handle, buffer.ptr + index, buffer.len - index);
317317 const read_err = posix.getErrno(amt_read);
318318 if (read_err > 0) {
319319 switch (read_err) {
......@@ -334,7 +334,7 @@ pub const File = struct {
334334 while (index < buffer.len) {
335335 const want_read_count = windows.DWORD(math.min(windows.DWORD(@maxValue(windows.DWORD)), buffer.len - index));
336336 var amt_read: windows.DWORD = undefined;
337 if (windows.ReadFile(self.handle, @ptrCast(*c_void, &buffer[index]), want_read_count, &amt_read, null) == 0) {
337 if (windows.ReadFile(self.handle, @ptrCast([*]c_void, buffer.ptr + index), want_read_count, &amt_read, null) == 0) {
338338 const err = windows.GetLastError();
339339 return switch (err) {
340340 windows.ERROR.OPERATION_ABORTED => continue,
std/os/index.zig+31-70
......@@ -134,20 +134,7 @@ pub fn getRandomBytes(buf: []u8) !void {
134134 }
135135 },
136136 Os.zen => {
137 const randomness = []u8{
138 42,
139 1,
140 7,
141 12,
142 22,
143 17,
144 99,
145 16,
146 26,
147 87,
148 41,
149 45,
150 };
137 const randomness = []u8{ 42, 1, 7, 12, 22, 17, 99, 16, 26, 87, 41, 45 };
151138 var i: usize = 0;
152139 while (i < buf.len) : (i += 1) {
153140 if (i > randomness.len) return error.Unknown;
......@@ -238,7 +225,7 @@ pub fn posixRead(fd: i32, buf: []u8) !void {
238225 var index: usize = 0;
239226 while (index < buf.len) {
240227 const want_to_read = math.min(buf.len - index, usize(max_buf_len));
241 const rc = posix.read(fd, &buf[index], want_to_read);
228 const rc = posix.read(fd, buf.ptr + index, want_to_read);
242229 const err = posix.getErrno(rc);
243230 if (err > 0) {
244231 return switch (err) {
......@@ -278,7 +265,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) !void {
278265 var index: usize = 0;
279266 while (index < bytes.len) {
280267 const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len));
281 const rc = posix.write(fd, &bytes[index], amt_to_write);
268 const rc = posix.write(fd, bytes.ptr + index, amt_to_write);
282269 const write_err = posix.getErrno(rc);
283270 if (write_err > 0) {
284271 return switch (write_err) {
......@@ -328,7 +315,8 @@ pub fn posixOpen(allocator: *Allocator, file_path: []const u8, flags: u32, perm:
328315 return posixOpenC(path_with_null.ptr, flags, perm);
329316}
330317
331pub fn posixOpenC(file_path: *const u8, flags: u32, perm: usize) !i32 {
318// TODO https://github.com/ziglang/zig/issues/265
319pub fn posixOpenC(file_path: [*]const u8, flags: u32, perm: usize) !i32 {
332320 while (true) {
333321 const result = posix.open(file_path, flags, perm);
334322 const err = posix.getErrno(result);
......@@ -374,19 +362,19 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) !void {
374362 }
375363}
376364
377pub fn createNullDelimitedEnvMap(allocator: *Allocator, env_map: *const BufMap) ![]?*u8 {
365pub fn createNullDelimitedEnvMap(allocator: *Allocator, env_map: *const BufMap) ![]?[*]u8 {
378366 const envp_count = env_map.count();
379 const envp_buf = try allocator.alloc(?*u8, envp_count + 1);
380 mem.set(?*u8, envp_buf, null);
367 const envp_buf = try allocator.alloc(?[*]u8, envp_count + 1);
368 mem.set(?[*]u8, envp_buf, null);
381369 errdefer freeNullDelimitedEnvMap(allocator, envp_buf);
382370 {
383371 var it = env_map.iterator();
384372 var i: usize = 0;
385373 while (it.next()) |pair| : (i += 1) {
386374 const env_buf = try allocator.alloc(u8, pair.key.len + pair.value.len + 2);
387 @memcpy(&env_buf[0], pair.key.ptr, pair.key.len);
375 @memcpy(env_buf.ptr, pair.key.ptr, pair.key.len);
388376 env_buf[pair.key.len] = '=';
389 @memcpy(&env_buf[pair.key.len + 1], pair.value.ptr, pair.value.len);
377 @memcpy(env_buf.ptr + pair.key.len + 1, pair.value.ptr, pair.value.len);
390378 env_buf[env_buf.len - 1] = 0;
391379
392380 envp_buf[i] = env_buf.ptr;
......@@ -397,7 +385,7 @@ pub fn createNullDelimitedEnvMap(allocator: *Allocator, env_map: *const BufMap)
397385 return envp_buf;
398386}
399387
400pub fn freeNullDelimitedEnvMap(allocator: *Allocator, envp_buf: []?*u8) void {
388pub fn freeNullDelimitedEnvMap(allocator: *Allocator, envp_buf: []?[*]u8) void {
401389 for (envp_buf) |env| {
402390 const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break;
403391 allocator.free(env_buf);
......@@ -411,8 +399,8 @@ pub fn freeNullDelimitedEnvMap(allocator: *Allocator, envp_buf: []?*u8) void {
411399/// `argv[0]` is the executable path.
412400/// This function also uses the PATH environment variable to get the full path to the executable.
413401pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator: *Allocator) !void {
414 const argv_buf = try allocator.alloc(?*u8, argv.len + 1);
415 mem.set(?*u8, argv_buf, null);
402 const argv_buf = try allocator.alloc(?[*]u8, argv.len + 1);
403 mem.set(?[*]u8, argv_buf, null);
416404 defer {
417405 for (argv_buf) |arg| {
418406 const arg_buf = if (arg) |ptr| cstr.toSlice(ptr) else break;
......@@ -422,7 +410,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator:
422410 }
423411 for (argv) |arg, i| {
424412 const arg_buf = try allocator.alloc(u8, arg.len + 1);
425 @memcpy(&arg_buf[0], arg.ptr, arg.len);
413 @memcpy(arg_buf.ptr, arg.ptr, arg.len);
426414 arg_buf[arg.len] = 0;
427415
428416 argv_buf[i] = arg_buf.ptr;
......@@ -494,7 +482,7 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {
494482}
495483
496484pub var linux_aux_raw = []usize{0} ** 38;
497pub var posix_environ_raw: []*u8 = undefined;
485pub var posix_environ_raw: [][*]u8 = undefined;
498486
499487/// Caller must free result when done.
500488pub fn getEnvMap(allocator: *Allocator) !BufMap {
......@@ -1311,7 +1299,7 @@ pub const Dir = struct {
13111299 const next_index = self.index + linux_entry.d_reclen;
13121300 self.index = next_index;
13131301
1314 const name = cstr.toSlice(&linux_entry.d_name);
1302 const name = cstr.toSlice(@ptrCast([*]u8, &linux_entry.d_name));
13151303
13161304 // skip . and .. entries
13171305 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
......@@ -1485,12 +1473,12 @@ pub const ArgIteratorPosix = struct {
14851473
14861474 /// This is marked as public but actually it's only meant to be used
14871475 /// internally by zig's startup code.
1488 pub var raw: []*u8 = undefined;
1476 pub var raw: [][*]u8 = undefined;
14891477};
14901478
14911479pub const ArgIteratorWindows = struct {
14921480 index: usize,
1493 cmd_line: *const u8,
1481 cmd_line: [*]const u8,
14941482 in_quote: bool,
14951483 quote_count: usize,
14961484 seen_quote_count: usize,
......@@ -1501,7 +1489,7 @@ pub const ArgIteratorWindows = struct {
15011489 return initWithCmdLine(windows.GetCommandLineA());
15021490 }
15031491
1504 pub fn initWithCmdLine(cmd_line: *const u8) ArgIteratorWindows {
1492 pub fn initWithCmdLine(cmd_line: [*]const u8) ArgIteratorWindows {
15051493 return ArgIteratorWindows{
15061494 .index = 0,
15071495 .cmd_line = cmd_line,
......@@ -1616,7 +1604,7 @@ pub const ArgIteratorWindows = struct {
16161604 }
16171605 }
16181606
1619 fn countQuotes(cmd_line: *const u8) usize {
1607 fn countQuotes(cmd_line: [*]const u8) usize {
16201608 var result: usize = 0;
16211609 var backslash_count: usize = 0;
16221610 var index: usize = 0;
......@@ -1722,39 +1710,12 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
17221710}
17231711
17241712test "windows arg parsing" {
1725 testWindowsCmdLine(c"a b\tc d", [][]const u8{
1726 "a",
1727 "b",
1728 "c",
1729 "d",
1730 });
1731 testWindowsCmdLine(c"\"abc\" d e", [][]const u8{
1732 "abc",
1733 "d",
1734 "e",
1735 });
1736 testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8{
1737 "a\\\\\\b",
1738 "de fg",
1739 "h",
1740 });
1741 testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8{
1742 "a\\\"b",
1743 "c",
1744 "d",
1745 });
1746 testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8{
1747 "a\\\\b c",
1748 "d",
1749 "e",
1750 });
1751 testWindowsCmdLine(c"a b\tc \"d f", [][]const u8{
1752 "a",
1753 "b",
1754 "c",
1755 "\"d",
1756 "f",
1757 });
1713 testWindowsCmdLine(c"a b\tc d", [][]const u8{ "a", "b", "c", "d" });
1714 testWindowsCmdLine(c"\"abc\" d e", [][]const u8{ "abc", "d", "e" });
1715 testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8{ "a\\\\\\b", "de fg", "h" });
1716 testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8{ "a\\\"b", "c", "d" });
1717 testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8{ "a\\\\b c", "d", "e" });
1718 testWindowsCmdLine(c"a b\tc \"d f", [][]const u8{ "a", "b", "c", "\"d", "f" });
17581719
17591720 testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [][]const u8{
17601721 ".\\..\\zig-cache\\build",
......@@ -1765,7 +1726,7 @@ test "windows arg parsing" {
17651726 });
17661727}
17671728
1768fn testWindowsCmdLine(input_cmd_line: *const u8, expected_args: []const []const u8) void {
1729fn testWindowsCmdLine(input_cmd_line: [*]const u8, expected_args: []const []const u8) void {
17691730 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
17701731 for (expected_args) |expected_arg| {
17711732 const arg = ??it.next(debug.global_allocator) catch unreachable;
......@@ -2350,7 +2311,7 @@ pub fn posixConnectAsync(sockfd: i32, sockaddr: *const posix.sockaddr) PosixConn
23502311pub fn posixGetSockOptConnectError(sockfd: i32) PosixConnectError!void {
23512312 var err_code: i32 = undefined;
23522313 var size: u32 = @sizeOf(i32);
2353 const rc = posix.getsockopt(sockfd, posix.SOL_SOCKET, posix.SO_ERROR, @ptrCast(*u8, &err_code), &size);
2314 const rc = posix.getsockopt(sockfd, posix.SOL_SOCKET, posix.SO_ERROR, @ptrCast([*]u8, &err_code), &size);
23542315 assert(size == 4);
23552316 const err = posix.getErrno(rc);
23562317 switch (err) {
......@@ -2401,7 +2362,7 @@ pub const Thread = struct {
24012362 },
24022363 builtin.Os.windows => struct {
24032364 handle: windows.HANDLE,
2404 alloc_start: *c_void,
2365 alloc_start: [*]c_void,
24052366 heap_handle: windows.HANDLE,
24062367 },
24072368 else => @compileError("Unsupported OS"),
......@@ -2500,7 +2461,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread
25002461 const byte_count = @alignOf(WinThread.OuterContext) + @sizeOf(WinThread.OuterContext);
25012462 const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) ?? return SpawnThreadError.OutOfMemory;
25022463 errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);
2503 const bytes = @ptrCast(*u8, bytes_ptr)[0..byte_count];
2464 const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];
25042465 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable;
25052466 outer_context.inner = context;
25062467 outer_context.thread.data.heap_handle = heap_handle;
......@@ -2572,7 +2533,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread
25722533
25732534 // align to page
25742535 stack_end -= stack_end % os.page_size;
2575 assert(c.pthread_attr_setstack(&attr, @intToPtr(*c_void, stack_addr), stack_end - stack_addr) == 0);
2536 assert(c.pthread_attr_setstack(&attr, @intToPtr([*]c_void, stack_addr), stack_end - stack_addr) == 0);
25762537
25772538 const err = c.pthread_create(&thread_ptr.data.handle, &attr, MainFuncs.posixThreadMain, @intToPtr(*c_void, arg));
25782539 switch (err) {
std/os/linux/index.zig+76-47
......@@ -665,15 +665,18 @@ pub fn dup2(old: i32, new: i32) usize {
665665 return syscall2(SYS_dup2, usize(old), usize(new));
666666}
667667
668pub fn chdir(path: *const u8) usize {
668// TODO https://github.com/ziglang/zig/issues/265
669pub fn chdir(path: [*]const u8) usize {
669670 return syscall1(SYS_chdir, @ptrToInt(path));
670671}
671672
672pub fn chroot(path: *const u8) usize {
673// TODO https://github.com/ziglang/zig/issues/265
674pub fn chroot(path: [*]const u8) usize {
673675 return syscall1(SYS_chroot, @ptrToInt(path));
674676}
675677
676pub fn execve(path: *const u8, argv: *const ?*const u8, envp: *const ?*const u8) usize {
678// TODO https://github.com/ziglang/zig/issues/265
679pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
677680 return syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
678681}
679682
......@@ -685,11 +688,11 @@ pub fn futex_wait(uaddr: usize, futex_op: u32, val: i32, timeout: ?*timespec) us
685688 return syscall4(SYS_futex, uaddr, futex_op, @bitCast(u32, val), @ptrToInt(timeout));
686689}
687690
688pub fn getcwd(buf: *u8, size: usize) usize {
691pub fn getcwd(buf: [*]u8, size: usize) usize {
689692 return syscall2(SYS_getcwd, @ptrToInt(buf), size);
690693}
691694
692pub fn getdents(fd: i32, dirp: *u8, count: usize) usize {
695pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
693696 return syscall3(SYS_getdents, usize(fd), @ptrToInt(dirp), count);
694697}
695698
......@@ -698,27 +701,32 @@ pub fn isatty(fd: i32) bool {
698701 return syscall3(SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
699702}
700703
701pub fn readlink(noalias path: *const u8, noalias buf_ptr: *u8, buf_len: usize) usize {
704// TODO https://github.com/ziglang/zig/issues/265
705pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
702706 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
703707}
704708
705pub fn mkdir(path: *const u8, mode: u32) usize {
709// TODO https://github.com/ziglang/zig/issues/265
710pub fn mkdir(path: [*]const u8, mode: u32) usize {
706711 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
707712}
708713
709pub fn mount(special: *const u8, dir: *const u8, fstype: *const u8, flags: usize, data: usize) usize {
714// TODO https://github.com/ziglang/zig/issues/265
715pub fn mount(special: [*]const u8, dir: [*]const u8, fstype: [*]const u8, flags: usize, data: usize) usize {
710716 return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data);
711717}
712718
713pub fn umount(special: *const u8) usize {
719// TODO https://github.com/ziglang/zig/issues/265
720pub fn umount(special: [*]const u8) usize {
714721 return syscall2(SYS_umount2, @ptrToInt(special), 0);
715722}
716723
717pub fn umount2(special: *const u8, flags: u32) usize {
724// TODO https://github.com/ziglang/zig/issues/265
725pub fn umount2(special: [*]const u8, flags: u32) usize {
718726 return syscall2(SYS_umount2, @ptrToInt(special), flags);
719727}
720728
721pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
729pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
722730 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), @bitCast(usize, offset));
723731}
724732
......@@ -726,23 +734,26 @@ pub fn munmap(address: usize, length: usize) usize {
726734 return syscall2(SYS_munmap, address, length);
727735}
728736
729pub fn read(fd: i32, buf: *u8, count: usize) usize {
737pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
730738 return syscall3(SYS_read, usize(fd), @ptrToInt(buf), count);
731739}
732740
733pub fn rmdir(path: *const u8) usize {
741// TODO https://github.com/ziglang/zig/issues/265
742pub fn rmdir(path: [*]const u8) usize {
734743 return syscall1(SYS_rmdir, @ptrToInt(path));
735744}
736745
737pub fn symlink(existing: *const u8, new: *const u8) usize {
746// TODO https://github.com/ziglang/zig/issues/265
747pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
738748 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
739749}
740750
741pub fn pread(fd: i32, buf: *u8, count: usize, offset: usize) usize {
751pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
742752 return syscall4(SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
743753}
744754
745pub fn access(path: *const u8, mode: u32) usize {
755// TODO https://github.com/ziglang/zig/issues/265
756pub fn access(path: [*]const u8, mode: u32) usize {
746757 return syscall2(SYS_access, @ptrToInt(path), mode);
747758}
748759
......@@ -754,27 +765,31 @@ pub fn pipe2(fd: *[2]i32, flags: usize) usize {
754765 return syscall2(SYS_pipe2, @ptrToInt(fd), flags);
755766}
756767
757pub fn write(fd: i32, buf: *const u8, count: usize) usize {
768pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
758769 return syscall3(SYS_write, usize(fd), @ptrToInt(buf), count);
759770}
760771
761pub fn pwrite(fd: i32, buf: *const u8, count: usize, offset: usize) usize {
772pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
762773 return syscall4(SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset);
763774}
764775
765pub fn rename(old: *const u8, new: *const u8) usize {
776// TODO https://github.com/ziglang/zig/issues/265
777pub fn rename(old: [*]const u8, new: [*]const u8) usize {
766778 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
767779}
768780
769pub fn open(path: *const u8, flags: u32, perm: usize) usize {
781// TODO https://github.com/ziglang/zig/issues/265
782pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
770783 return syscall3(SYS_open, @ptrToInt(path), flags, perm);
771784}
772785
773pub fn create(path: *const u8, perm: usize) usize {
786// TODO https://github.com/ziglang/zig/issues/265
787pub fn create(path: [*]const u8, perm: usize) usize {
774788 return syscall2(SYS_creat, @ptrToInt(path), perm);
775789}
776790
777pub fn openat(dirfd: i32, path: *const u8, flags: usize, mode: usize) usize {
791// TODO https://github.com/ziglang/zig/issues/265
792pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {
778793 return syscall4(SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode);
779794}
780795
......@@ -801,7 +816,7 @@ pub fn exit(status: i32) noreturn {
801816 unreachable;
802817}
803818
804pub fn getrandom(buf: *u8, count: usize, flags: u32) usize {
819pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
805820 return syscall3(SYS_getrandom, @ptrToInt(buf), count, usize(flags));
806821}
807822
......@@ -809,7 +824,8 @@ pub fn kill(pid: i32, sig: i32) usize {
809824 return syscall2(SYS_kill, @bitCast(usize, isize(pid)), usize(sig));
810825}
811826
812pub fn unlink(path: *const u8) usize {
827// TODO https://github.com/ziglang/zig/issues/265
828pub fn unlink(path: [*]const u8) usize {
813829 return syscall1(SYS_unlink, @ptrToInt(path));
814830}
815831
......@@ -942,8 +958,8 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
942958 .restorer = @ptrCast(extern fn () void, restore_rt),
943959 };
944960 var ksa_old: k_sigaction = undefined;
945 @memcpy(@ptrCast(*u8, *ksa.mask), @ptrCast(*const u8, *act.mask), 8);
946 const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(*ksa), @ptrToInt(*ksa_old), @sizeOf(@typeOf(ksa.mask)));
961 @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), 8);
962 const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask)));
947963 const err = getErrno(result);
948964 if (err != 0) {
949965 return result;
......@@ -951,7 +967,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
951967 if (oact) |old| {
952968 old.handler = ksa_old.handler;
953969 old.flags = @truncate(u32, ksa_old.flags);
954 @memcpy(@ptrCast(*u8, *old.mask), @ptrCast(*const u8, *ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask)));
970 @memcpy(@ptrCast([*]u8, &old.mask), @ptrCast([*]const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask)));
955971 }
956972 return 0;
957973}
......@@ -1036,7 +1052,7 @@ pub const sockaddr_in6 = extern struct {
10361052};
10371053
10381054pub const iovec = extern struct {
1039 iov_base: *u8,
1055 iov_base: [*]u8,
10401056 iov_len: usize,
10411057};
10421058
......@@ -1052,11 +1068,11 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
10521068 return syscall3(SYS_socket, domain, socket_type, protocol);
10531069}
10541070
1055pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: *const u8, optlen: socklen_t) usize {
1071pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
10561072 return syscall5(SYS_setsockopt, usize(fd), level, optname, usize(optval), @ptrToInt(optlen));
10571073}
10581074
1059pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: *u8, noalias optlen: *socklen_t) usize {
1075pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
10601076 return syscall5(SYS_getsockopt, usize(fd), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
10611077}
10621078
......@@ -1072,7 +1088,7 @@ pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
10721088 return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);
10731089}
10741090
1075pub fn recvfrom(fd: i32, noalias buf: *u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
1091pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
10761092 return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
10771093}
10781094
......@@ -1088,7 +1104,7 @@ pub fn listen(fd: i32, backlog: u32) usize {
10881104 return syscall2(SYS_listen, usize(fd), backlog);
10891105}
10901106
1091pub fn sendto(fd: i32, buf: *const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
1107pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
10921108 return syscall6(SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen));
10931109}
10941110
......@@ -1108,59 +1124,72 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize {
11081124 return syscall2(SYS_fstat, usize(fd), @ptrToInt(stat_buf));
11091125}
11101126
1111pub fn stat(pathname: *const u8, statbuf: *Stat) usize {
1127// TODO https://github.com/ziglang/zig/issues/265
1128pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize {
11121129 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
11131130}
11141131
1115pub fn lstat(pathname: *const u8, statbuf: *Stat) usize {
1132// TODO https://github.com/ziglang/zig/issues/265
1133pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
11161134 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
11171135}
11181136
1119pub fn listxattr(path: *const u8, list: *u8, size: usize) usize {
1137// TODO https://github.com/ziglang/zig/issues/265
1138pub fn listxattr(path: [*]const u8, list: [*]u8, size: usize) usize {
11201139 return syscall3(SYS_listxattr, @ptrToInt(path), @ptrToInt(list), size);
11211140}
11221141
1123pub fn llistxattr(path: *const u8, list: *u8, size: usize) usize {
1142// TODO https://github.com/ziglang/zig/issues/265
1143pub fn llistxattr(path: [*]const u8, list: [*]u8, size: usize) usize {
11241144 return syscall3(SYS_llistxattr, @ptrToInt(path), @ptrToInt(list), size);
11251145}
11261146
1127pub fn flistxattr(fd: usize, list: *u8, size: usize) usize {
1147pub fn flistxattr(fd: usize, list: [*]u8, size: usize) usize {
11281148 return syscall3(SYS_flistxattr, fd, @ptrToInt(list), size);
11291149}
11301150
1131pub fn getxattr(path: *const u8, name: *const u8, value: *void, size: usize) usize {
1151// TODO https://github.com/ziglang/zig/issues/265
1152pub fn getxattr(path: [*]const u8, name: [*]const u8, value: [*]u8, size: usize) usize {
11321153 return syscall4(SYS_getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
11331154}
11341155
1135pub fn lgetxattr(path: *const u8, name: *const u8, value: *void, size: usize) usize {
1156// TODO https://github.com/ziglang/zig/issues/265
1157pub fn lgetxattr(path: [*]const u8, name: [*]const u8, value: [*]u8, size: usize) usize {
11361158 return syscall4(SYS_lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
11371159}
11381160
1139pub fn fgetxattr(fd: usize, name: *const u8, value: *void, size: usize) usize {
1161// TODO https://github.com/ziglang/zig/issues/265
1162pub fn fgetxattr(fd: usize, name: [*]const u8, value: [*]u8, size: usize) usize {
11401163 return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);
11411164}
11421165
1143pub fn setxattr(path: *const u8, name: *const u8, value: *const void, size: usize, flags: usize) usize {
1166// TODO https://github.com/ziglang/zig/issues/265
1167pub fn setxattr(path: [*]const u8, name: [*]const u8, value: *const void, size: usize, flags: usize) usize {
11441168 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
11451169}
11461170
1147pub fn lsetxattr(path: *const u8, name: *const u8, value: *const void, size: usize, flags: usize) usize {
1171// TODO https://github.com/ziglang/zig/issues/265
1172pub fn lsetxattr(path: [*]const u8, name: [*]const u8, value: *const void, size: usize, flags: usize) usize {
11481173 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
11491174}
11501175
1151pub fn fsetxattr(fd: usize, name: *const u8, value: *const void, size: usize, flags: usize) usize {
1176// TODO https://github.com/ziglang/zig/issues/265
1177pub fn fsetxattr(fd: usize, name: [*]const u8, value: *const void, size: usize, flags: usize) usize {
11521178 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);
11531179}
11541180
1155pub fn removexattr(path: *const u8, name: *const u8) usize {
1181// TODO https://github.com/ziglang/zig/issues/265
1182pub fn removexattr(path: [*]const u8, name: [*]const u8) usize {
11561183 return syscall2(SYS_removexattr, @ptrToInt(path), @ptrToInt(name));
11571184}
11581185
1159pub fn lremovexattr(path: *const u8, name: *const u8) usize {
1186// TODO https://github.com/ziglang/zig/issues/265
1187pub fn lremovexattr(path: [*]const u8, name: [*]const u8) usize {
11601188 return syscall2(SYS_lremovexattr, @ptrToInt(path), @ptrToInt(name));
11611189}
11621190
1163pub fn fremovexattr(fd: usize, name: *const u8) usize {
1191// TODO https://github.com/ziglang/zig/issues/265
1192pub fn fremovexattr(fd: usize, name: [*]const u8) usize {
11641193 return syscall2(SYS_fremovexattr, fd, @ptrToInt(name));
11651194}
11661195
......@@ -1188,7 +1217,7 @@ pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize {
11881217 return syscall4(SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev));
11891218}
11901219
1191pub fn epoll_wait(epoll_fd: i32, events: *epoll_event, maxevents: u32, timeout: i32) usize {
1220pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {
11921221 return syscall4(SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout));
11931222}
11941223
std/os/linux/test.zig+2-1
......@@ -35,5 +35,6 @@ test "timer" {
3535 const events_one: linux.epoll_event = undefined;
3636 var events = []linux.epoll_event{events_one} ** 8;
3737
38 err = linux.epoll_wait(i32(epoll_fd), &events[0], 8, -1);
38 // TODO implicit cast from *[N]T to [*]T
39 err = linux.epoll_wait(i32(epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);
3940}
std/os/linux/vdso.zig+13-13
......@@ -12,7 +12,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
1212 var ph_addr: usize = vdso_addr + eh.e_phoff;
1313 const ph = @intToPtr(*elf.Phdr, ph_addr);
1414
15 var maybe_dynv: ?*usize = null;
15 var maybe_dynv: ?[*]usize = null;
1616 var base: usize = @maxValue(usize);
1717 {
1818 var i: usize = 0;
......@@ -23,7 +23,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
2323 const this_ph = @intToPtr(*elf.Phdr, ph_addr);
2424 switch (this_ph.p_type) {
2525 elf.PT_LOAD => base = vdso_addr + this_ph.p_offset - this_ph.p_vaddr,
26 elf.PT_DYNAMIC => maybe_dynv = @intToPtr(*usize, vdso_addr + this_ph.p_offset),
26 elf.PT_DYNAMIC => maybe_dynv = @intToPtr([*]usize, vdso_addr + this_ph.p_offset),
2727 else => {},
2828 }
2929 }
......@@ -31,10 +31,10 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
3131 const dynv = maybe_dynv ?? return 0;
3232 if (base == @maxValue(usize)) return 0;
3333
34 var maybe_strings: ?*u8 = null;
35 var maybe_syms: ?*elf.Sym = null;
36 var maybe_hashtab: ?*linux.Elf_Symndx = null;
37 var maybe_versym: ?*u16 = null;
34 var maybe_strings: ?[*]u8 = null;
35 var maybe_syms: ?[*]elf.Sym = null;
36 var maybe_hashtab: ?[*]linux.Elf_Symndx = null;
37 var maybe_versym: ?[*]u16 = null;
3838 var maybe_verdef: ?*elf.Verdef = null;
3939
4040 {
......@@ -42,10 +42,10 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
4242 while (dynv[i] != 0) : (i += 2) {
4343 const p = base + dynv[i + 1];
4444 switch (dynv[i]) {
45 elf.DT_STRTAB => maybe_strings = @intToPtr(*u8, p),
46 elf.DT_SYMTAB => maybe_syms = @intToPtr(*elf.Sym, p),
47 elf.DT_HASH => maybe_hashtab = @intToPtr(*linux.Elf_Symndx, p),
48 elf.DT_VERSYM => maybe_versym = @intToPtr(*u16, p),
45 elf.DT_STRTAB => maybe_strings = @intToPtr([*]u8, p),
46 elf.DT_SYMTAB => maybe_syms = @intToPtr([*]elf.Sym, p),
47 elf.DT_HASH => maybe_hashtab = @intToPtr([*]linux.Elf_Symndx, p),
48 elf.DT_VERSYM => maybe_versym = @intToPtr([*]u16, p),
4949 elf.DT_VERDEF => maybe_verdef = @intToPtr(*elf.Verdef, p),
5050 else => {},
5151 }
......@@ -65,7 +65,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6565 if (0 == (u32(1) << u5(syms[i].st_info & 0xf) & OK_TYPES)) continue;
6666 if (0 == (u32(1) << u5(syms[i].st_info >> 4) & OK_BINDS)) continue;
6767 if (0 == syms[i].st_shndx) continue;
68 if (!mem.eql(u8, name, cstr.toSliceConst(&strings[syms[i].st_name]))) continue;
68 if (!mem.eql(u8, name, cstr.toSliceConst(strings + syms[i].st_name))) continue;
6969 if (maybe_versym) |versym| {
7070 if (!checkver(??maybe_verdef, versym[i], vername, strings))
7171 continue;
......@@ -76,7 +76,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
7676 return 0;
7777}
7878
79fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: *u8) bool {
79fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*]u8) bool {
8080 var def = def_arg;
8181 const vsym = @bitCast(u32, vsym_arg) & 0x7fff;
8282 while (true) {
......@@ -87,5 +87,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: *
8787 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
8888 }
8989 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
90 return mem.eql(u8, vername, cstr.toSliceConst(&strings[aux.vda_name]));
90 return mem.eql(u8, vername, cstr.toSliceConst(strings + aux.vda_name));
9191}
std/os/windows/index.zig+15-15
......@@ -10,7 +10,7 @@ pub extern "advapi32" stdcallcc fn CryptAcquireContextA(
1010
1111pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) BOOL;
1212
13pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: *BYTE) BOOL;
13pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: [*]BYTE) BOOL;
1414
1515pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL;
1616
......@@ -61,7 +61,7 @@ pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) BOOL;
6161
6262pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) noreturn;
6363
64pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) BOOL;
64pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: [*]u8) BOOL;
6565
6666pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR;
6767
......@@ -69,7 +69,7 @@ pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out
6969
7070pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) DWORD;
7171
72pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() ?LPCH;
72pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() ?[*]u8;
7373
7474pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuffer: LPSTR, nSize: DWORD) DWORD;
7575
......@@ -101,17 +101,17 @@ pub extern "kernel32" stdcallcc fn GetSystemTimeAsFileTime(?*FILETIME) void;
101101
102102pub extern "kernel32" stdcallcc fn HeapCreate(flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T) ?HANDLE;
103103pub extern "kernel32" stdcallcc fn HeapDestroy(hHeap: HANDLE) BOOL;
104pub extern "kernel32" stdcallcc fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void, dwBytes: SIZE_T) ?*c_void;
105pub extern "kernel32" stdcallcc fn HeapSize(hHeap: HANDLE, dwFlags: DWORD, lpMem: *const c_void) SIZE_T;
106pub extern "kernel32" stdcallcc fn HeapValidate(hHeap: HANDLE, dwFlags: DWORD, lpMem: *const c_void) BOOL;
104pub extern "kernel32" stdcallcc fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: [*]c_void, dwBytes: SIZE_T) ?[*]c_void;
105pub extern "kernel32" stdcallcc fn HeapSize(hHeap: HANDLE, dwFlags: DWORD, lpMem: [*]const c_void) SIZE_T;
106pub extern "kernel32" stdcallcc fn HeapValidate(hHeap: HANDLE, dwFlags: DWORD, lpMem: [*]const c_void) BOOL;
107107pub extern "kernel32" stdcallcc fn HeapCompact(hHeap: HANDLE, dwFlags: DWORD) SIZE_T;
108108pub extern "kernel32" stdcallcc fn HeapSummary(hHeap: HANDLE, dwFlags: DWORD, lpSummary: LPHEAP_SUMMARY) BOOL;
109109
110110pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) ?HANDLE;
111111
112pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) ?*c_void;
112pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) ?[*]c_void;
113113
114pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void) BOOL;
114pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: [*]c_void) BOOL;
115115
116116pub extern "kernel32" stdcallcc fn MoveFileExA(
117117 lpExistingFileName: LPCSTR,
......@@ -127,7 +127,7 @@ pub extern "kernel32" stdcallcc fn PathFileExists(pszPath: ?LPCTSTR) BOOL;
127127
128128pub extern "kernel32" stdcallcc fn ReadFile(
129129 in_hFile: HANDLE,
130 out_lpBuffer: *c_void,
130 out_lpBuffer: [*]c_void,
131131 in_nNumberOfBytesToRead: DWORD,
132132 out_lpNumberOfBytesRead: *DWORD,
133133 in_out_lpOverlapped: ?*OVERLAPPED,
......@@ -150,7 +150,7 @@ pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMillis
150150
151151pub extern "kernel32" stdcallcc fn WriteFile(
152152 in_hFile: HANDLE,
153 in_lpBuffer: *const c_void,
153 in_lpBuffer: [*]const c_void,
154154 in_nNumberOfBytesToWrite: DWORD,
155155 out_lpNumberOfBytesWritten: ?*DWORD,
156156 in_out_lpOverlapped: ?*OVERLAPPED,
......@@ -178,16 +178,16 @@ pub const HMODULE = *@OpaqueType();
178178pub const INT = c_int;
179179pub const LPBYTE = *BYTE;
180180pub const LPCH = *CHAR;
181pub const LPCSTR = *const CHAR;
182pub const LPCTSTR = *const TCHAR;
181pub const LPCSTR = [*]const CHAR;
182pub const LPCTSTR = [*]const TCHAR;
183183pub const LPCVOID = *const c_void;
184184pub const LPDWORD = *DWORD;
185pub const LPSTR = *CHAR;
185pub const LPSTR = [*]CHAR;
186186pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
187187pub const LPVOID = *c_void;
188pub const LPWSTR = *WCHAR;
188pub const LPWSTR = [*]WCHAR;
189189pub const PVOID = *c_void;
190pub const PWSTR = *WCHAR;
190pub const PWSTR = [*]WCHAR;
191191pub const SIZE_T = usize;
192192pub const TCHAR = if (UNICODE) WCHAR else u8;
193193pub const UINT = c_uint;
std/os/windows/util.zig+1-1
......@@ -42,7 +42,7 @@ pub const WriteError = error{
4242};
4343
4444pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) WriteError!void {
45 if (windows.WriteFile(handle, @ptrCast(*const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) {
45 if (windows.WriteFile(handle, @ptrCast([*]const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) {
4646 const err = windows.GetLastError();
4747 return switch (err) {
4848 windows.ERROR.INVALID_USER_BUFFER => WriteError.SystemResources,
std/segmented_list.zig+6-6
......@@ -87,7 +87,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
8787 const ShelfIndex = std.math.Log2Int(usize);
8888
8989 prealloc_segment: [prealloc_item_count]T,
90 dynamic_segments: []*T,
90 dynamic_segments: [][*]T,
9191 allocator: *Allocator,
9292 len: usize,
9393
......@@ -99,7 +99,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
9999 .allocator = allocator,
100100 .len = 0,
101101 .prealloc_segment = undefined,
102 .dynamic_segments = []*T{},
102 .dynamic_segments = [][*]T{},
103103 };
104104 }
105105
......@@ -160,11 +160,11 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
160160 const new_cap_shelf_count = shelfCount(new_capacity);
161161 const old_shelf_count = ShelfIndex(self.dynamic_segments.len);
162162 if (new_cap_shelf_count > old_shelf_count) {
163 self.dynamic_segments = try self.allocator.realloc(*T, self.dynamic_segments, new_cap_shelf_count);
163 self.dynamic_segments = try self.allocator.realloc([*]T, self.dynamic_segments, new_cap_shelf_count);
164164 var i = old_shelf_count;
165165 errdefer {
166166 self.freeShelves(i, old_shelf_count);
167 self.dynamic_segments = self.allocator.shrink(*T, self.dynamic_segments, old_shelf_count);
167 self.dynamic_segments = self.allocator.shrink([*]T, self.dynamic_segments, old_shelf_count);
168168 }
169169 while (i < new_cap_shelf_count) : (i += 1) {
170170 self.dynamic_segments[i] = (try self.allocator.alloc(T, shelfSize(i))).ptr;
......@@ -178,7 +178,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
178178 const len = ShelfIndex(self.dynamic_segments.len);
179179 self.freeShelves(len, 0);
180180 self.allocator.free(self.dynamic_segments);
181 self.dynamic_segments = []*T{};
181 self.dynamic_segments = [][*]T{};
182182 return;
183183 }
184184
......@@ -190,7 +190,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
190190 }
191191
192192 self.freeShelves(old_shelf_count, new_cap_shelf_count);
193 self.dynamic_segments = self.allocator.shrink(*T, self.dynamic_segments, new_cap_shelf_count);
193 self.dynamic_segments = self.allocator.shrink([*]T, self.dynamic_segments, new_cap_shelf_count);
194194 }
195195
196196 pub fn uncheckedAt(self: *Self, index: usize) *T {
std/special/bootstrap.zig+12-10
......@@ -5,7 +5,7 @@ const root = @import("@root");
55const std = @import("std");
66const builtin = @import("builtin");
77
8var argc_ptr: *usize = undefined;
8var argc_ptr: [*]usize = undefined;
99
1010comptime {
1111 const strong_linkage = builtin.GlobalLinkage.Strong;
......@@ -28,12 +28,12 @@ nakedcc fn _start() noreturn {
2828 switch (builtin.arch) {
2929 builtin.Arch.x86_64 => {
3030 argc_ptr = asm ("lea (%%rsp), %[argc]"
31 : [argc] "=r" (-> *usize)
31 : [argc] "=r" (-> [*]usize)
3232 );
3333 },
3434 builtin.Arch.i386 => {
3535 argc_ptr = asm ("lea (%%esp), %[argc]"
36 : [argc] "=r" (-> *usize)
36 : [argc] "=r" (-> [*]usize)
3737 );
3838 },
3939 else => @compileError("unsupported arch"),
......@@ -49,15 +49,17 @@ extern fn WinMainCRTStartup() noreturn {
4949 std.os.windows.ExitProcess(callMain());
5050}
5151
52// TODO https://github.com/ziglang/zig/issues/265
5253fn posixCallMainAndExit() noreturn {
5354 const argc = argc_ptr.*;
54 const argv = @ptrCast(**u8, &argc_ptr[1]);
55 const envp_nullable = @ptrCast(*?*u8, &argv[argc + 1]);
55 const argv = @ptrCast([*][*]u8, argc_ptr + 1);
56
57 const envp_nullable = @ptrCast([*]?[*]u8, argv + argc + 1);
5658 var envp_count: usize = 0;
5759 while (envp_nullable[envp_count]) |_| : (envp_count += 1) {}
58 const envp = @ptrCast(**u8, envp_nullable)[0..envp_count];
60 const envp = @ptrCast([*][*]u8, envp_nullable)[0..envp_count];
5961 if (builtin.os == builtin.Os.linux) {
60 const auxv = &@ptrCast(*usize, envp.ptr)[envp_count + 1];
62 const auxv = @ptrCast([*]usize, envp.ptr + envp_count + 1);
6163 var i: usize = 0;
6264 while (auxv[i] != 0) : (i += 2) {
6365 if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i + 1];
......@@ -68,16 +70,16 @@ fn posixCallMainAndExit() noreturn {
6870 std.os.posix.exit(callMainWithArgs(argc, argv, envp));
6971}
7072
71fn callMainWithArgs(argc: usize, argv: **u8, envp: []*u8) u8 {
73fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {
7274 std.os.ArgIteratorPosix.raw = argv[0..argc];
7375 std.os.posix_environ_raw = envp;
7476 return callMain();
7577}
7678
77extern fn main(c_argc: i32, c_argv: **u8, c_envp: *?*u8) i32 {
79extern fn main(c_argc: i32, c_argv: [*][*]u8, c_envp: [*]?[*]u8) i32 {
7880 var env_count: usize = 0;
7981 while (c_envp[env_count] != null) : (env_count += 1) {}
80 const envp = @ptrCast(**u8, c_envp)[0..env_count];
82 const envp = @ptrCast([*][*]u8, c_envp)[0..env_count];
8183 return callMainWithArgs(usize(c_argc), c_argv, envp);
8284}
8385
std/special/builtin.zig+3-3
......@@ -14,7 +14,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
1414 }
1515}
1616
17export fn memset(dest: ?*u8, c: u8, n: usize) ?*u8 {
17export fn memset(dest: ?[*]u8, c: u8, n: usize) ?[*]u8 {
1818 @setRuntimeSafety(false);
1919
2020 var index: usize = 0;
......@@ -24,7 +24,7 @@ export fn memset(dest: ?*u8, c: u8, n: usize) ?*u8 {
2424 return dest;
2525}
2626
27export fn memcpy(noalias dest: ?*u8, noalias src: ?*const u8, n: usize) ?*u8 {
27export fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) ?[*]u8 {
2828 @setRuntimeSafety(false);
2929
3030 var index: usize = 0;
......@@ -34,7 +34,7 @@ export fn memcpy(noalias dest: ?*u8, noalias src: ?*const u8, n: usize) ?*u8 {
3434 return dest;
3535}
3636
37export fn memmove(dest: ?*u8, src: ?*const u8, n: usize) ?*u8 {
37export fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) ?[*]u8 {
3838 @setRuntimeSafety(false);
3939
4040 if (@ptrToInt(dest) < @ptrToInt(src)) {
test/cases/align.zig+18-31
......@@ -167,54 +167,41 @@ test "@ptrCast preserves alignment of bigger source" {
167167 assert(@typeOf(ptr) == *align(16) u8);
168168}
169169
170test "compile-time known array index has best alignment possible" {
170test "runtime known array index has best alignment possible" {
171171 // take full advantage of over-alignment
172 var array align(4) = []u8{
173 1,
174 2,
175 3,
176 4,
177 };
172 var array align(4) = []u8{ 1, 2, 3, 4 };
178173 assert(@typeOf(&array[0]) == *align(4) u8);
179174 assert(@typeOf(&array[1]) == *u8);
180175 assert(@typeOf(&array[2]) == *align(2) u8);
181176 assert(@typeOf(&array[3]) == *u8);
182177
183178 // because align is too small but we still figure out to use 2
184 var bigger align(2) = []u64{
185 1,
186 2,
187 3,
188 4,
189 };
179 var bigger align(2) = []u64{ 1, 2, 3, 4 };
190180 assert(@typeOf(&bigger[0]) == *align(2) u64);
191181 assert(@typeOf(&bigger[1]) == *align(2) u64);
192182 assert(@typeOf(&bigger[2]) == *align(2) u64);
193183 assert(@typeOf(&bigger[3]) == *align(2) u64);
194184
195185 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
196 var smaller align(2) = []u32{
197 1,
198 2,
199 3,
200 4,
201 };
202 testIndex(&smaller[0], 0, *align(2) u32);
203 testIndex(&smaller[0], 1, *align(2) u32);
204 testIndex(&smaller[0], 2, *align(2) u32);
205 testIndex(&smaller[0], 3, *align(2) u32);
186 var smaller align(2) = []u32{ 1, 2, 3, 4 };
187 comptime assert(@typeOf(smaller[0..]) == []align(2) u32);
188 comptime assert(@typeOf(smaller[0..].ptr) == [*]align(2) u32);
189 testIndex(smaller[0..].ptr, 0, *align(2) u32);
190 testIndex(smaller[0..].ptr, 1, *align(2) u32);
191 testIndex(smaller[0..].ptr, 2, *align(2) u32);
192 testIndex(smaller[0..].ptr, 3, *align(2) u32);
206193
207194 // has to use ABI alignment because index known at runtime only
208 testIndex2(&array[0], 0, *u8);
209 testIndex2(&array[0], 1, *u8);
210 testIndex2(&array[0], 2, *u8);
211 testIndex2(&array[0], 3, *u8);
195 testIndex2(array[0..].ptr, 0, *u8);
196 testIndex2(array[0..].ptr, 1, *u8);
197 testIndex2(array[0..].ptr, 2, *u8);
198 testIndex2(array[0..].ptr, 3, *u8);
212199}
213fn testIndex(smaller: *align(2) u32, index: usize, comptime T: type) void {
214 assert(@typeOf(&smaller[index]) == T);
200fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void {
201 comptime assert(@typeOf(&smaller[index]) == T);
215202}
216fn testIndex2(ptr: *align(4) u8, index: usize, comptime T: type) void {
217 assert(@typeOf(&ptr[index]) == T);
203fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void {
204 comptime assert(@typeOf(&ptr[index]) == T);
218205}
219206
220207test "alignstack" {
test/cases/const_slice_child.zig+5-4
......@@ -1,15 +1,16 @@
11const debug = @import("std").debug;
22const assert = debug.assert;
33
4var argv: *const *const u8 = undefined;
4var argv: [*]const [*]const u8 = undefined;
55
66test "const slice child" {
7 const strs = ([]*const u8){
7 const strs = ([][*]const u8){
88 c"one",
99 c"two",
1010 c"three",
1111 };
12 argv = &strs[0];
12 // TODO this should implicitly cast
13 argv = @ptrCast([*]const [*]const u8, &strs);
1314 bar(strs.len);
1415}
1516
......@@ -29,7 +30,7 @@ fn bar(argc: usize) void {
2930 foo(args);
3031}
3132
32fn strlen(ptr: *const u8) usize {
33fn strlen(ptr: [*]const u8) usize {
3334 var count: usize = 0;
3435 while (ptr[count] != 0) : (count += 1) {}
3536 return count;
test/cases/for.zig+2-24
......@@ -35,34 +35,12 @@ fn mangleString(s: []u8) void {
3535}
3636
3737test "basic for loop" {
38 const expected_result = []u8{
39 9,
40 8,
41 7,
42 6,
43 0,
44 1,
45 2,
46 3,
47 9,
48 8,
49 7,
50 6,
51 0,
52 1,
53 2,
54 3,
55 };
38 const expected_result = []u8{ 9, 8, 7, 6, 0, 1, 2, 3, 9, 8, 7, 6, 0, 1, 2, 3 };
5639
5740 var buffer: [expected_result.len]u8 = undefined;
5841 var buf_index: usize = 0;
5942
60 const array = []u8{
61 9,
62 8,
63 7,
64 6,
65 };
43 const array = []u8{ 9, 8, 7, 6 };
6644 for (array) |item| {
6745 buffer[buf_index] = item;
6846 buf_index += 1;
test/cases/misc.zig+6-5
......@@ -171,8 +171,8 @@ test "memcpy and memset intrinsics" {
171171 var foo: [20]u8 = undefined;
172172 var bar: [20]u8 = undefined;
173173
174 @memset(&foo[0], 'A', foo.len);
175 @memcpy(&bar[0], &foo[0], bar.len);
174 @memset(foo[0..].ptr, 'A', foo.len);
175 @memcpy(bar[0..].ptr, foo[0..].ptr, bar.len);
176176
177177 if (bar[11] != 'A') unreachable;
178178}
......@@ -194,7 +194,7 @@ test "slicing" {
194194 if (slice.len != 5) unreachable;
195195
196196 const ptr = &slice[0];
197 if (ptr[0] != 1234) unreachable;
197 if (ptr.* != 1234) unreachable;
198198
199199 var slice_rest = array[10..];
200200 if (slice_rest.len != 10) unreachable;
......@@ -464,8 +464,9 @@ test "array 2D const double ptr" {
464464}
465465
466466fn testArray2DConstDoublePtr(ptr: *const f32) void {
467 assert(ptr[0] == 1.0);
468 assert(ptr[1] == 2.0);
467 const ptr2 = @ptrCast([*]const f32, ptr);
468 assert(ptr2[0] == 1.0);
469 assert(ptr2[1] == 2.0);
469470}
470471
471472const Tid = builtin.TypeId;
test/cases/pointers.zig+30
......@@ -12,3 +12,33 @@ fn testDerefPtr() void {
1212 y.* += 1;
1313 assert(x == 1235);
1414}
15
16test "pointer arithmetic" {
17 var ptr = c"abcd";
18
19 assert(ptr[0] == 'a');
20 ptr += 1;
21 assert(ptr[0] == 'b');
22 ptr += 1;
23 assert(ptr[0] == 'c');
24 ptr += 1;
25 assert(ptr[0] == 'd');
26 ptr += 1;
27 assert(ptr[0] == 0);
28 ptr -= 1;
29 assert(ptr[0] == 'd');
30 ptr -= 1;
31 assert(ptr[0] == 'c');
32 ptr -= 1;
33 assert(ptr[0] == 'b');
34 ptr -= 1;
35 assert(ptr[0] == 'a');
36}
37
38test "double pointer parsing" {
39 comptime assert(PtrOf(PtrOf(i32)) == **i32);
40}
41
42fn PtrOf(comptime T: type) type {
43 return *T;
44}
test/cases/struct.zig+3-3
......@@ -43,7 +43,7 @@ const VoidStructFieldsFoo = struct {
4343
4444test "structs" {
4545 var foo: StructFoo = undefined;
46 @memset(@ptrCast(*u8, &foo), 0, @sizeOf(StructFoo));
46 @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
4747 foo.a += 1;
4848 foo.b = foo.a == 1;
4949 testFoo(foo);
......@@ -396,8 +396,8 @@ const Bitfields = packed struct {
396396test "native bit field understands endianness" {
397397 var all: u64 = 0x7765443322221111;
398398 var bytes: [8]u8 = undefined;
399 @memcpy(&bytes[0], @ptrCast(*u8, &all), 8);
400 var bitfields = @ptrCast(*Bitfields, &bytes[0]).*;
399 @memcpy(bytes[0..].ptr, @ptrCast([*]u8, &all), 8);
400 var bitfields = @ptrCast(*Bitfields, bytes[0..].ptr).*;
401401
402402 assert(bitfields.f1 == 0x1111);
403403 assert(bitfields.f2 == 0x2222);
test/compare_output.zig+8-8
......@@ -6,7 +6,7 @@ const tests = @import("tests.zig");
66pub fn addCases(cases: *tests.CompareOutputContext) void {
77 cases.addC("hello world with libc",
88 \\const c = @cImport(@cInclude("stdio.h"));
9 \\export fn main(argc: c_int, argv: **u8) c_int {
9 \\export fn main(argc: c_int, argv: [*][*]u8) c_int {
1010 \\ _ = c.puts(c"Hello, world!");
1111 \\ return 0;
1212 \\}
......@@ -139,7 +139,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
139139 \\ @cInclude("stdio.h");
140140 \\});
141141 \\
142 \\export fn main(argc: c_int, argv: **u8) c_int {
142 \\export fn main(argc: c_int, argv: [*][*]u8) c_int {
143143 \\ if (is_windows) {
144144 \\ // we want actual \n, not \r\n
145145 \\ _ = c._setmode(1, c._O_BINARY);
......@@ -284,9 +284,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
284284 cases.addC("expose function pointer to C land",
285285 \\const c = @cImport(@cInclude("stdlib.h"));
286286 \\
287 \\export fn compare_fn(a: ?*const c_void, b: ?*const c_void) c_int {
288 \\ const a_int = @ptrCast(*align(1) const i32, a ?? unreachable);
289 \\ const b_int = @ptrCast(*align(1) const i32, b ?? unreachable);
287 \\export fn compare_fn(a: ?[*]const c_void, b: ?[*]const c_void) c_int {
288 \\ const a_int = @ptrCast(*const i32, @alignCast(@alignOf(i32), a));
289 \\ const b_int = @ptrCast(*const i32, @alignCast(@alignOf(i32), b));
290290 \\ if (a_int.* < b_int.*) {
291291 \\ return -1;
292292 \\ } else if (a_int.* > b_int.*) {
......@@ -297,9 +297,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
297297 \\}
298298 \\
299299 \\export fn main() c_int {
300 \\ var array = []u32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
300 \\ var array = []u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
301301 \\
302 \\ c.qsort(@ptrCast(*c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn);
302 \\ c.qsort(@ptrCast(?[*]c_void, array[0..].ptr), c_ulong(array.len), @sizeOf(i32), compare_fn);
303303 \\
304304 \\ for (array) |item, i| {
305305 \\ if (item != i) {
......@@ -324,7 +324,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
324324 \\ @cInclude("stdio.h");
325325 \\});
326326 \\
327 \\export fn main(argc: c_int, argv: **u8) c_int {
327 \\export fn main(argc: c_int, argv: [*][*]u8) c_int {
328328 \\ if (is_windows) {
329329 \\ // we want actual \n, not \r\n
330330 \\ _ = c._setmode(1, c._O_BINARY);
test/compile_errors.zig+12-3
......@@ -1,6 +1,15 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "indexing single-item pointer",
6 \\export fn entry(ptr: *i32) i32 {
7 \\ return ptr[1];
8 \\}
9 ,
10 ".tmp_source.zig:2:15: error: indexing not allowed on pointer to single item",
11 );
12
413 cases.add(
514 "invalid deref on switch target",
615 \\const NextError = error{NextError};
......@@ -1002,7 +1011,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
10021011 \\ return a;
10031012 \\}
10041013 ,
1005 ".tmp_source.zig:3:12: error: expected type 'i32', found '*const u8'",
1014 ".tmp_source.zig:3:12: error: expected type 'i32', found '[*]const u8'",
10061015 );
10071016
10081017 cases.add(
......@@ -2442,13 +2451,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
24422451 \\var s_buffer: [10]u8 = undefined;
24432452 \\pub fn pass(in: []u8) []u8 {
24442453 \\ var out = &s_buffer;
2445 \\ out[0].* = in[0];
2454 \\ out.*.* = in[0];
24462455 \\ return out.*[0..1];
24472456 \\}
24482457 \\
24492458 \\export fn entry() usize { return @sizeOf(@typeOf(pass)); }
24502459 ,
2451 ".tmp_source.zig:4:11: error: attempt to dereference non pointer type '[10]u8'",
2460 ".tmp_source.zig:4:10: error: attempt to dereference non pointer type '[10]u8'",
24522461 );
24532462
24542463 cases.add(
test/translate_c.zig+28-28
......@@ -14,11 +14,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1414 \\};
1515 ,
1616 \\pub const struct_Foo = extern struct {
17 \\ a: ?*Foo,
17 \\ a: ?[*]Foo,
1818 \\};
1919 \\pub const Foo = struct_Foo;
2020 \\pub const struct_Bar = extern struct {
21 \\ a: ?*Foo,
21 \\ a: ?[*]Foo,
2222 \\};
2323 );
2424
......@@ -99,7 +99,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
9999 cases.add("restrict -> noalias",
100100 \\void foo(void *restrict bar, void *restrict);
101101 ,
102 \\pub extern fn foo(noalias bar: ?*c_void, noalias arg1: ?*c_void) void;
102 \\pub extern fn foo(noalias bar: ?[*]c_void, noalias arg1: ?[*]c_void) void;
103103 );
104104
105105 cases.add("simple struct",
......@@ -110,7 +110,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
110110 ,
111111 \\const struct_Foo = extern struct {
112112 \\ x: c_int,
113 \\ y: ?*u8,
113 \\ y: ?[*]u8,
114114 \\};
115115 ,
116116 \\pub const Foo = struct_Foo;
......@@ -141,7 +141,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
141141 ,
142142 \\pub const BarB = enum_Bar.B;
143143 ,
144 \\pub extern fn func(a: ?*struct_Foo, b: ?*(?*enum_Bar)) void;
144 \\pub extern fn func(a: ?[*]struct_Foo, b: ?[*](?[*]enum_Bar)) void;
145145 ,
146146 \\pub const Foo = struct_Foo;
147147 ,
......@@ -151,7 +151,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
151151 cases.add("constant size array",
152152 \\void func(int array[20]);
153153 ,
154 \\pub extern fn func(array: ?*c_int) void;
154 \\pub extern fn func(array: ?[*]c_int) void;
155155 );
156156
157157 cases.add("self referential struct with function pointer",
......@@ -160,7 +160,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
160160 \\};
161161 ,
162162 \\pub const struct_Foo = extern struct {
163 \\ derp: ?extern fn(?*struct_Foo) void,
163 \\ derp: ?extern fn(?[*]struct_Foo) void,
164164 \\};
165165 ,
166166 \\pub const Foo = struct_Foo;
......@@ -172,7 +172,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
172172 ,
173173 \\pub const struct_Foo = @OpaqueType();
174174 ,
175 \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo;
175 \\pub extern fn some_func(foo: ?[*]struct_Foo, x: c_int) ?[*]struct_Foo;
176176 ,
177177 \\pub const Foo = struct_Foo;
178178 );
......@@ -219,11 +219,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
219219 \\};
220220 ,
221221 \\pub const struct_Bar = extern struct {
222 \\ next: ?*struct_Foo,
222 \\ next: ?[*]struct_Foo,
223223 \\};
224224 ,
225225 \\pub const struct_Foo = extern struct {
226 \\ next: ?*struct_Bar,
226 \\ next: ?[*]struct_Bar,
227227 \\};
228228 );
229229
......@@ -233,7 +233,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
233233 ,
234234 \\pub const Foo = c_void;
235235 ,
236 \\pub extern fn fun(a: ?*Foo) Foo;
236 \\pub extern fn fun(a: ?[*]Foo) Foo;
237237 );
238238
239239 cases.add("generate inline func for #define global extern fn",
......@@ -505,7 +505,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
505505 \\ return 6;
506506 \\}
507507 ,
508 \\pub export fn and_or_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
508 \\pub export fn and_or_none_bool(a: c_int, b: f32, c: ?[*]c_void) c_int {
509509 \\ if ((a != 0) and (b != 0)) return 0;
510510 \\ if ((b != 0) and (c != null)) return 1;
511511 \\ if ((a != 0) and (c != null)) return 2;
......@@ -607,7 +607,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
607607 \\pub const struct_Foo = extern struct {
608608 \\ field: c_int,
609609 \\};
610 \\pub export fn read_field(foo: ?*struct_Foo) c_int {
610 \\pub export fn read_field(foo: ?[*]struct_Foo) c_int {
611611 \\ return (??foo).field;
612612 \\}
613613 );
......@@ -653,8 +653,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
653653 \\ return x;
654654 \\}
655655 ,
656 \\pub export fn foo(x: ?*c_ushort) ?*c_void {
657 \\ return @ptrCast(?*c_void, x);
656 \\pub export fn foo(x: ?[*]c_ushort) ?[*]c_void {
657 \\ return @ptrCast(?[*]c_void, x);
658658 \\}
659659 );
660660
......@@ -674,7 +674,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
674674 \\ return 0;
675675 \\}
676676 ,
677 \\pub export fn foo() ?*c_int {
677 \\pub export fn foo() ?[*]c_int {
678678 \\ return null;
679679 \\}
680680 );
......@@ -983,7 +983,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
983983 \\ *x = 1;
984984 \\}
985985 ,
986 \\pub export fn foo(x: ?*c_int) void {
986 \\pub export fn foo(x: ?[*]c_int) void {
987987 \\ (??x).* = 1;
988988 \\}
989989 );
......@@ -1011,7 +1011,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10111011 ,
10121012 \\pub fn foo() c_int {
10131013 \\ var x: c_int = 1234;
1014 \\ var ptr: ?*c_int = &x;
1014 \\ var ptr: ?[*]c_int = &x;
10151015 \\ return (??ptr).*;
10161016 \\}
10171017 );
......@@ -1021,7 +1021,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10211021 \\ return "bar";
10221022 \\}
10231023 ,
1024 \\pub fn foo() ?*const u8 {
1024 \\pub fn foo() ?[*]const u8 {
10251025 \\ return c"bar";
10261026 \\}
10271027 );
......@@ -1150,8 +1150,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11501150 \\ return (float *)a;
11511151 \\}
11521152 ,
1153 \\fn ptrcast(a: ?*c_int) ?*f32 {
1154 \\ return @ptrCast(?*f32, a);
1153 \\fn ptrcast(a: ?[*]c_int) ?[*]f32 {
1154 \\ return @ptrCast(?[*]f32, a);
11551155 \\}
11561156 );
11571157
......@@ -1173,7 +1173,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11731173 \\ return !c;
11741174 \\}
11751175 ,
1176 \\pub fn foo(a: c_int, b: f32, c: ?*c_void) c_int {
1176 \\pub fn foo(a: c_int, b: f32, c: ?[*]c_void) c_int {
11771177 \\ return !(a == 0);
11781178 \\ return !(a != 0);
11791179 \\ return !(b != 0);
......@@ -1194,7 +1194,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11941194 cases.add("const ptr initializer",
11951195 \\static const char *v0 = "0.0.0";
11961196 ,
1197 \\pub var v0: ?*const u8 = c"0.0.0";
1197 \\pub var v0: ?[*]const u8 = c"0.0.0";
11981198 );
11991199
12001200 cases.add("static incomplete array inside function",
......@@ -1203,14 +1203,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12031203 \\}
12041204 ,
12051205 \\pub fn foo() void {
1206 \\ const v2: *const u8 = c"2.2.2";
1206 \\ const v2: [*]const u8 = c"2.2.2";
12071207 \\}
12081208 );
12091209
12101210 cases.add("macro pointer cast",
12111211 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
12121212 ,
1213 \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast(*NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr(*NRF_GPIO_Type, NRF_GPIO_BASE) else (*NRF_GPIO_Type)(NRF_GPIO_BASE);
1213 \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*]NRF_GPIO_Type, NRF_GPIO_BASE) else ([*]NRF_GPIO_Type)(NRF_GPIO_BASE);
12141214 );
12151215
12161216 cases.add("if on none bool",
......@@ -1231,7 +1231,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12311231 \\ B,
12321232 \\ C,
12331233 \\};
1234 \\pub fn if_none_bool(a: c_int, b: f32, c: ?*c_void, d: enum_SomeEnum) c_int {
1234 \\pub fn if_none_bool(a: c_int, b: f32, c: ?[*]c_void, d: enum_SomeEnum) c_int {
12351235 \\ if (a != 0) return 0;
12361236 \\ if (b != 0) return 1;
12371237 \\ if (c != null) return 2;
......@@ -1248,7 +1248,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12481248 \\ return 3;
12491249 \\}
12501250 ,
1251 \\pub fn while_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
1251 \\pub fn while_none_bool(a: c_int, b: f32, c: ?[*]c_void) c_int {
12521252 \\ while (a != 0) return 0;
12531253 \\ while (b != 0) return 1;
12541254 \\ while (c != null) return 2;
......@@ -1264,7 +1264,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12641264 \\ return 3;
12651265 \\}
12661266 ,
1267 \\pub fn for_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
1267 \\pub fn for_none_bool(a: c_int, b: f32, c: ?[*]c_void) c_int {
12681268 \\ while (a != 0) return 0;
12691269 \\ while (b != 0) return 1;
12701270 \\ while (c != null) return 2;