| author | |
| committer | |
| log | a665872e881920e8020a513340d2427b88a55bd6 |
| tree | ff81a6b509584d737d0df15d293dc01ae1390469 |
| parent | 3b40aaa01fb15799cf27d662229597ac98e2ab77 |
also introduce the _ identifier which you can assign to
to discard a return value
closes #21910 files changed, 102 insertions(+), 53 deletions(-)
src/all_types.hpp+3| ... | @@ -117,6 +117,9 @@ enum ConstPtrSpecial { | ... | @@ -117,6 +117,9 @@ enum ConstPtrSpecial { |
| 117 | // emit a binary with a compile time known address. | 117 | // emit a binary with a compile time known address. |
| 118 | // In this case index is the numeric address value. | 118 | // In this case index is the numeric address value. |
| 119 | ConstPtrSpecialHardCodedAddr, | 119 | ConstPtrSpecialHardCodedAddr, |
| 120 | // This means that the pointer represents memory of assigning to _. | ||
| 121 | // That is, storing discards the data, and loading is invalid. | ||
| 122 | ConstPtrSpecialDiscard, | ||
| 120 | }; | 123 | }; |
| 121 | 124 | ||
| 122 | enum ConstPtrMut { | 125 | enum ConstPtrMut { |
src/analyze.cpp+8| ... | @@ -3091,6 +3091,9 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { | ... | @@ -3091,6 +3091,9 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { |
| 3091 | hash_val += 4048518294; | 3091 | hash_val += 4048518294; |
| 3092 | hash_val += hash_size(const_val->data.x_ptr.data.hard_coded_addr.addr); | 3092 | hash_val += hash_size(const_val->data.x_ptr.data.hard_coded_addr.addr); |
| 3093 | return hash_val; | 3093 | return hash_val; |
| 3094 | case ConstPtrSpecialDiscard: | ||
| 3095 | hash_val += 2010123162; | ||
| 3096 | return hash_val; | ||
| 3094 | } | 3097 | } |
| 3095 | zig_unreachable(); | 3098 | zig_unreachable(); |
| 3096 | } | 3099 | } |
| ... | @@ -3601,6 +3604,8 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { | ... | @@ -3601,6 +3604,8 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { |
| 3601 | if (a->data.x_ptr.data.hard_coded_addr.addr != b->data.x_ptr.data.hard_coded_addr.addr) | 3604 | if (a->data.x_ptr.data.hard_coded_addr.addr != b->data.x_ptr.data.hard_coded_addr.addr) |
| 3602 | return false; | 3605 | return false; |
| 3603 | return true; | 3606 | return true; |
| 3607 | case ConstPtrSpecialDiscard: | ||
| 3608 | return true; | ||
| 3604 | } | 3609 | } |
| 3605 | zig_unreachable(); | 3610 | zig_unreachable(); |
| 3606 | case TypeTableEntryIdArray: | 3611 | case TypeTableEntryIdArray: |
| ... | @@ -3785,6 +3790,9 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { | ... | @@ -3785,6 +3790,9 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { |
| 3785 | buf_appendf(buf, "(&%s)(%" PRIx64 ")", buf_ptr(&canon_type->data.pointer.child_type->name), | 3790 | buf_appendf(buf, "(&%s)(%" PRIx64 ")", buf_ptr(&canon_type->data.pointer.child_type->name), |
| 3786 | const_val->data.x_ptr.data.hard_coded_addr.addr); | 3791 | const_val->data.x_ptr.data.hard_coded_addr.addr); |
| 3787 | return; | 3792 | return; |
| 3793 | case ConstPtrSpecialDiscard: | ||
| 3794 | buf_append_str(buf, "&_"); | ||
| 3795 | return; | ||
| 3788 | } | 3796 | } |
| 3789 | zig_unreachable(); | 3797 | zig_unreachable(); |
| 3790 | case TypeTableEntryIdFn: | 3798 | case TypeTableEntryIdFn: |
src/codegen.cpp+1| ... | @@ -2928,6 +2928,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { | ... | @@ -2928,6 +2928,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 2928 | render_const_val_global(g, const_val, ""); | 2928 | render_const_val_global(g, const_val, ""); |
| 2929 | switch (const_val->data.x_ptr.special) { | 2929 | switch (const_val->data.x_ptr.special) { |
| 2930 | case ConstPtrSpecialInvalid: | 2930 | case ConstPtrSpecialInvalid: |
| 2931 | case ConstPtrSpecialDiscard: | ||
| 2931 | zig_unreachable(); | 2932 | zig_unreachable(); |
| 2932 | case ConstPtrSpecialRef: | 2933 | case ConstPtrSpecialRef: |
| 2933 | { | 2934 | { |
src/ir.cpp+31| ... | @@ -77,6 +77,8 @@ ConstExprValue *const_ptr_pointee(ConstExprValue *const_val) { | ... | @@ -77,6 +77,8 @@ ConstExprValue *const_ptr_pointee(ConstExprValue *const_val) { |
| 77 | const_val->data.x_ptr.data.base_struct.field_index]; | 77 | const_val->data.x_ptr.data.base_struct.field_index]; |
| 78 | case ConstPtrSpecialHardCodedAddr: | 78 | case ConstPtrSpecialHardCodedAddr: |
| 79 | zig_unreachable(); | 79 | zig_unreachable(); |
| 80 | case ConstPtrSpecialDiscard: | ||
| 81 | zig_unreachable(); | ||
| 80 | } | 82 | } |
| 81 | zig_unreachable(); | 83 | zig_unreachable(); |
| 82 | } | 84 | } |
| ... | @@ -3656,6 +3658,15 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3656,6 +3658,15 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3656 | 3658 | ||
| 3657 | Buf *variable_name = node->data.symbol_expr.symbol; | 3659 | Buf *variable_name = node->data.symbol_expr.symbol; |
| 3658 | 3660 | ||
| 3661 | if (buf_eql_str(variable_name, "_") && lval.is_ptr) { | ||
| 3662 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node); | ||
| 3663 | const_instruction->base.value.type = get_pointer_to_type(irb->codegen, | ||
| 3664 | irb->codegen->builtin_types.entry_void, false); | ||
| 3665 | const_instruction->base.value.special = ConstValSpecialStatic; | ||
| 3666 | const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialDiscard; | ||
| 3667 | return &const_instruction->base; | ||
| 3668 | } | ||
| 3669 | |||
| 3659 | auto primitive_table_entry = irb->codegen->primitive_type_table.maybe_get(variable_name); | 3670 | auto primitive_table_entry = irb->codegen->primitive_type_table.maybe_get(variable_name); |
| 3660 | if (primitive_table_entry) { | 3671 | if (primitive_table_entry) { |
| 3661 | IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_table_entry->value); | 3672 | IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_table_entry->value); |
| ... | @@ -8927,6 +8938,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -8927,6 +8938,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 8927 | size_t old_size; | 8938 | size_t old_size; |
| 8928 | switch (array_ptr_val->data.x_ptr.special) { | 8939 | switch (array_ptr_val->data.x_ptr.special) { |
| 8929 | case ConstPtrSpecialInvalid: | 8940 | case ConstPtrSpecialInvalid: |
| 8941 | case ConstPtrSpecialDiscard: | ||
| 8930 | zig_unreachable(); | 8942 | zig_unreachable(); |
| 8931 | case ConstPtrSpecialRef: | 8943 | case ConstPtrSpecialRef: |
| 8932 | mem_size = 1; | 8944 | mem_size = 1; |
| ... | @@ -8977,6 +8989,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -8977,6 +8989,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 8977 | out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut; | 8989 | out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut; |
| 8978 | switch (ptr_field->data.x_ptr.special) { | 8990 | switch (ptr_field->data.x_ptr.special) { |
| 8979 | case ConstPtrSpecialInvalid: | 8991 | case ConstPtrSpecialInvalid: |
| 8992 | case ConstPtrSpecialDiscard: | ||
| 8980 | zig_unreachable(); | 8993 | zig_unreachable(); |
| 8981 | case ConstPtrSpecialRef: | 8994 | case ConstPtrSpecialRef: |
| 8982 | out_val->data.x_ptr.special = ConstPtrSpecialRef; | 8995 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| ... | @@ -9384,6 +9397,10 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru | ... | @@ -9384,6 +9397,10 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 9384 | return value->value.type; | 9397 | return value->value.type; |
| 9385 | 9398 | ||
| 9386 | assert(ptr->value.type->id == TypeTableEntryIdPointer); | 9399 | assert(ptr->value.type->id == TypeTableEntryIdPointer); |
| 9400 | if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { | ||
| 9401 | return ir_analyze_void(ira, &store_ptr_instruction->base); | ||
| 9402 | } | ||
| 9403 | |||
| 9387 | if (ptr->value.type->data.pointer.is_const && !store_ptr_instruction->base.is_gen) { | 9404 | if (ptr->value.type->data.pointer.is_const && !store_ptr_instruction->base.is_gen) { |
| 9388 | ir_add_error(ira, &store_ptr_instruction->base, buf_sprintf("cannot assign to constant")); | 9405 | ir_add_error(ira, &store_ptr_instruction->base, buf_sprintf("cannot assign to constant")); |
| 9389 | return ira->codegen->builtin_types.entry_invalid; | 9406 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -11365,6 +11382,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi | ... | @@ -11365,6 +11382,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi |
| 11365 | size_t bound_end; | 11382 | size_t bound_end; |
| 11366 | switch (dest_ptr_val->data.x_ptr.special) { | 11383 | switch (dest_ptr_val->data.x_ptr.special) { |
| 11367 | case ConstPtrSpecialInvalid: | 11384 | case ConstPtrSpecialInvalid: |
| 11385 | case ConstPtrSpecialDiscard: | ||
| 11368 | zig_unreachable(); | 11386 | zig_unreachable(); |
| 11369 | case ConstPtrSpecialRef: | 11387 | case ConstPtrSpecialRef: |
| 11370 | dest_elements = dest_ptr_val->data.x_ptr.data.ref.pointee; | 11388 | dest_elements = dest_ptr_val->data.x_ptr.data.ref.pointee; |
| ... | @@ -11455,6 +11473,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi | ... | @@ -11455,6 +11473,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi |
| 11455 | size_t dest_end; | 11473 | size_t dest_end; |
| 11456 | switch (dest_ptr_val->data.x_ptr.special) { | 11474 | switch (dest_ptr_val->data.x_ptr.special) { |
| 11457 | case ConstPtrSpecialInvalid: | 11475 | case ConstPtrSpecialInvalid: |
| 11476 | case ConstPtrSpecialDiscard: | ||
| 11458 | zig_unreachable(); | 11477 | zig_unreachable(); |
| 11459 | case ConstPtrSpecialRef: | 11478 | case ConstPtrSpecialRef: |
| 11460 | dest_elements = dest_ptr_val->data.x_ptr.data.ref.pointee; | 11479 | dest_elements = dest_ptr_val->data.x_ptr.data.ref.pointee; |
| ... | @@ -11487,6 +11506,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi | ... | @@ -11487,6 +11506,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi |
| 11487 | 11506 | ||
| 11488 | switch (src_ptr_val->data.x_ptr.special) { | 11507 | switch (src_ptr_val->data.x_ptr.special) { |
| 11489 | case ConstPtrSpecialInvalid: | 11508 | case ConstPtrSpecialInvalid: |
| 11509 | case ConstPtrSpecialDiscard: | ||
| 11490 | zig_unreachable(); | 11510 | zig_unreachable(); |
| 11491 | case ConstPtrSpecialRef: | 11511 | case ConstPtrSpecialRef: |
| 11492 | src_elements = src_ptr_val->data.x_ptr.data.ref.pointee; | 11512 | src_elements = src_ptr_val->data.x_ptr.data.ref.pointee; |
| ... | @@ -11595,6 +11615,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio | ... | @@ -11595,6 +11615,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 11595 | parent_ptr = const_ptr_pointee(&ptr_ptr->value); | 11615 | parent_ptr = const_ptr_pointee(&ptr_ptr->value); |
| 11596 | switch (parent_ptr->data.x_ptr.special) { | 11616 | switch (parent_ptr->data.x_ptr.special) { |
| 11597 | case ConstPtrSpecialInvalid: | 11617 | case ConstPtrSpecialInvalid: |
| 11618 | case ConstPtrSpecialDiscard: | ||
| 11598 | zig_unreachable(); | 11619 | zig_unreachable(); |
| 11599 | case ConstPtrSpecialRef: | 11620 | case ConstPtrSpecialRef: |
| 11600 | array_val = nullptr; | 11621 | array_val = nullptr; |
| ... | @@ -11619,6 +11640,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio | ... | @@ -11619,6 +11640,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 11619 | 11640 | ||
| 11620 | switch (parent_ptr->data.x_ptr.special) { | 11641 | switch (parent_ptr->data.x_ptr.special) { |
| 11621 | case ConstPtrSpecialInvalid: | 11642 | case ConstPtrSpecialInvalid: |
| 11643 | case ConstPtrSpecialDiscard: | ||
| 11622 | zig_unreachable(); | 11644 | zig_unreachable(); |
| 11623 | case ConstPtrSpecialRef: | 11645 | case ConstPtrSpecialRef: |
| 11624 | array_val = nullptr; | 11646 | array_val = nullptr; |
| ... | @@ -11676,6 +11698,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio | ... | @@ -11676,6 +11698,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 11676 | } else { | 11698 | } else { |
| 11677 | switch (parent_ptr->data.x_ptr.special) { | 11699 | switch (parent_ptr->data.x_ptr.special) { |
| 11678 | case ConstPtrSpecialInvalid: | 11700 | case ConstPtrSpecialInvalid: |
| 11701 | case ConstPtrSpecialDiscard: | ||
| 11679 | zig_unreachable(); | 11702 | zig_unreachable(); |
| 11680 | case ConstPtrSpecialRef: | 11703 | case ConstPtrSpecialRef: |
| 11681 | init_const_ptr_ref(ira->codegen, ptr_val, | 11704 | init_const_ptr_ref(ira->codegen, ptr_val, |
| ... | @@ -12302,6 +12325,14 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins | ... | @@ -12302,6 +12325,14 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins |
| 12302 | instruction_type->id == TypeTableEntryIdUnreachable); | 12325 | instruction_type->id == TypeTableEntryIdUnreachable); |
| 12303 | instruction->other = instruction; | 12326 | instruction->other = instruction; |
| 12304 | } | 12327 | } |
| 12328 | if (instruction_type->id != TypeTableEntryIdInvalid && | ||
| 12329 | instruction_type->id != TypeTableEntryIdVoid && | ||
| 12330 | instruction_type->id != TypeTableEntryIdUnreachable && | ||
| 12331 | instruction->ref_count == 0) | ||
| 12332 | { | ||
| 12333 | ir_add_error(ira, instruction, buf_sprintf("return value ignored")); | ||
| 12334 | } | ||
| 12335 | |||
| 12305 | return instruction_type; | 12336 | return instruction_type; |
| 12306 | } | 12337 | } |
| 12307 | 12338 |
std/compiler_rt.zig+1-1| ... | @@ -218,7 +218,7 @@ export fn __umoddi3(a: du_int, b: du_int) -> du_int { | ... | @@ -218,7 +218,7 @@ export fn __umoddi3(a: du_int, b: du_int) -> du_int { |
| 218 | @setDebugSafety(this, false); | 218 | @setDebugSafety(this, false); |
| 219 | 219 | ||
| 220 | var r: du_int = undefined; | 220 | var r: du_int = undefined; |
| 221 | __udivmoddi4(a, b, &r); | 221 | _ = __udivmoddi4(a, b, &r); |
| 222 | return r; | 222 | return r; |
| 223 | } | 223 | } |
| 224 | 224 |
std/io.zig+3-3| ... | @@ -170,7 +170,7 @@ pub const OutStream = struct { | ... | @@ -170,7 +170,7 @@ pub const OutStream = struct { |
| 170 | }, | 170 | }, |
| 171 | State.Integer => switch (c) { | 171 | State.Integer => switch (c) { |
| 172 | '}' => { | 172 | '}' => { |
| 173 | self.printInt(args[next_arg], radix, uppercase, width); | 173 | %return self.printInt(args[next_arg], radix, uppercase, width); |
| 174 | next_arg += 1; | 174 | next_arg += 1; |
| 175 | state = State.Start; | 175 | state = State.Start; |
| 176 | start_index = i + 1; | 176 | start_index = i + 1; |
| ... | @@ -184,7 +184,7 @@ pub const OutStream = struct { | ... | @@ -184,7 +184,7 @@ pub const OutStream = struct { |
| 184 | State.IntegerWidth => switch (c) { | 184 | State.IntegerWidth => switch (c) { |
| 185 | '}' => { | 185 | '}' => { |
| 186 | width = comptime %%parseUnsigned(usize, format[width_start...i], 10); | 186 | width = comptime %%parseUnsigned(usize, format[width_start...i], 10); |
| 187 | self.printInt(args[next_arg], radix, uppercase, width); | 187 | %return self.printInt(args[next_arg], radix, uppercase, width); |
| 188 | next_arg += 1; | 188 | next_arg += 1; |
| 189 | state = State.Start; | 189 | state = State.Start; |
| 190 | start_index = i + 1; | 190 | start_index = i + 1; |
| ... | @@ -194,7 +194,7 @@ pub const OutStream = struct { | ... | @@ -194,7 +194,7 @@ pub const OutStream = struct { |
| 194 | }, | 194 | }, |
| 195 | State.Character => switch (c) { | 195 | State.Character => switch (c) { |
| 196 | '}' => { | 196 | '}' => { |
| 197 | self.printAsciiChar(args[next_arg]); | 197 | %return self.printAsciiChar(args[next_arg]); |
| 198 | next_arg += 1; | 198 | next_arg += 1; |
| 199 | state = State.Start; | 199 | state = State.Start; |
| 200 | start_index = i + 1; | 200 | start_index = i + 1; |
std/linux.zig+6-6| ... | @@ -298,7 +298,7 @@ pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize { | ... | @@ -298,7 +298,7 @@ pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize { |
| 298 | } | 298 | } |
| 299 | 299 | ||
| 300 | pub fn exit(status: i32) -> unreachable { | 300 | pub fn exit(status: i32) -> unreachable { |
| 301 | arch.syscall1(arch.SYS_exit, usize(status)); | 301 | _ = arch.syscall1(arch.SYS_exit, usize(status)); |
| 302 | @unreachable() | 302 | @unreachable() |
| 303 | } | 303 | } |
| 304 | 304 | ||
| ... | @@ -325,15 +325,15 @@ pub fn raise(sig: i32) -> i32 { | ... | @@ -325,15 +325,15 @@ pub fn raise(sig: i32) -> i32 { |
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | fn blockAllSignals(set: &sigset_t) { | 327 | fn blockAllSignals(set: &sigset_t) { |
| 328 | arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&all_mask), usize(set), NSIG/8); | 328 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&all_mask), usize(set), NSIG/8); |
| 329 | } | 329 | } |
| 330 | 330 | ||
| 331 | fn blockAppSignals(set: &sigset_t) { | 331 | fn blockAppSignals(set: &sigset_t) { |
| 332 | arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&app_mask), usize(set), NSIG/8); | 332 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&app_mask), usize(set), NSIG/8); |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | fn restoreSignals(set: &sigset_t) { | 335 | fn restoreSignals(set: &sigset_t) { |
| 336 | arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, usize(set), 0, NSIG/8); | 336 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, usize(set), 0, NSIG/8); |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | 339 | ||
| ... | @@ -432,8 +432,8 @@ pub fn shutdown(fd: i32, how: i32) -> usize { | ... | @@ -432,8 +432,8 @@ pub fn shutdown(fd: i32, how: i32) -> usize { |
| 432 | arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)) | 432 | arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)) |
| 433 | } | 433 | } |
| 434 | 434 | ||
| 435 | pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) { | 435 | pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { |
| 436 | arch.syscall3(arch.SYS_bind, usize(fd), usize(addr), usize(len)); | 436 | arch.syscall3(arch.SYS_bind, usize(fd), usize(addr), usize(len)) |
| 437 | } | 437 | } |
| 438 | 438 | ||
| 439 | pub fn listen(fd: i32, backlog: i32) -> usize { | 439 | pub fn listen(fd: i32, backlog: i32) -> usize { |
std/os.zig+2-2| ... | @@ -30,8 +30,8 @@ pub fn getRandomBytes(buf: []u8) -> %void { | ... | @@ -30,8 +30,8 @@ pub fn getRandomBytes(buf: []u8) -> %void { |
| 30 | pub coldcc fn abort() -> unreachable { | 30 | pub coldcc fn abort() -> unreachable { |
| 31 | switch (@compileVar("os")) { | 31 | switch (@compileVar("os")) { |
| 32 | Os.linux, Os.darwin => { | 32 | Os.linux, Os.darwin => { |
| 33 | system.raise(system.SIGABRT); | 33 | _ = system.raise(system.SIGABRT); |
| 34 | system.raise(system.SIGKILL); | 34 | _ = system.raise(system.SIGKILL); |
| 35 | while (true) {} | 35 | while (true) {} |
| 36 | }, | 36 | }, |
| 37 | else => @compileError("unsupported os"), | 37 | else => @compileError("unsupported os"), |
test/cases/struct.zig+1-1| ... | @@ -193,7 +193,7 @@ const EmptyStruct = struct { | ... | @@ -193,7 +193,7 @@ const EmptyStruct = struct { |
| 193 | fn returnEmptyStructFromFn() { | 193 | fn returnEmptyStructFromFn() { |
| 194 | @setFnTest(this); | 194 | @setFnTest(this); |
| 195 | 195 | ||
| 196 | testReturnEmptyStructFromFn(); | 196 | _ = testReturnEmptyStructFromFn(); |
| 197 | } | 197 | } |
| 198 | const EmptyStruct2 = struct {}; | 198 | const EmptyStruct2 = struct {}; |
| 199 | fn testReturnEmptyStructFromFn() -> EmptyStruct2 { | 199 | fn testReturnEmptyStructFromFn() -> EmptyStruct2 { |
test/run_tests.cpp+46-40| ... | @@ -230,7 +230,7 @@ static void add_compiling_test_cases(void) { | ... | @@ -230,7 +230,7 @@ static void add_compiling_test_cases(void) { |
| 230 | add_simple_case_libc("hello world with libc", R"SOURCE( | 230 | add_simple_case_libc("hello world with libc", R"SOURCE( |
| 231 | const c = @cImport(@cInclude("stdio.h")); | 231 | const c = @cImport(@cInclude("stdio.h")); |
| 232 | export fn main(argc: c_int, argv: &&u8) -> c_int { | 232 | export fn main(argc: c_int, argv: &&u8) -> c_int { |
| 233 | c.puts(c"Hello, world!"); | 233 | _ = c.puts(c"Hello, world!"); |
| 234 | return 0; | 234 | return 0; |
| 235 | } | 235 | } |
| 236 | )SOURCE", "Hello, world!" NL); | 236 | )SOURCE", "Hello, world!" NL); |
| ... | @@ -344,84 +344,84 @@ pub fn main(args: [][]u8) -> %void { | ... | @@ -344,84 +344,84 @@ pub fn main(args: [][]u8) -> %void { |
| 344 | const c = @cImport(@cInclude("stdio.h")); | 344 | const c = @cImport(@cInclude("stdio.h")); |
| 345 | 345 | ||
| 346 | export fn main(argc: c_int, argv: &&u8) -> c_int { | 346 | export fn main(argc: c_int, argv: &&u8) -> c_int { |
| 347 | c.printf(c"\n"); | 347 | _ = c.printf(c"\n"); |
| 348 | 348 | ||
| 349 | c.printf(c"0: %llu\n", | 349 | _ = c.printf(c"0: %llu\n", |
| 350 | u64(0)); | 350 | u64(0)); |
| 351 | c.printf(c"320402575052271: %llu\n", | 351 | _ = c.printf(c"320402575052271: %llu\n", |
| 352 | u64(320402575052271)); | 352 | u64(320402575052271)); |
| 353 | c.printf(c"0x01236789abcdef: %llu\n", | 353 | _ = c.printf(c"0x01236789abcdef: %llu\n", |
| 354 | u64(0x01236789abcdef)); | 354 | u64(0x01236789abcdef)); |
| 355 | c.printf(c"0xffffffffffffffff: %llu\n", | 355 | _ = c.printf(c"0xffffffffffffffff: %llu\n", |
| 356 | u64(0xffffffffffffffff)); | 356 | u64(0xffffffffffffffff)); |
| 357 | c.printf(c"0x000000ffffffffffffffff: %llu\n", | 357 | _ = c.printf(c"0x000000ffffffffffffffff: %llu\n", |
| 358 | u64(0x000000ffffffffffffffff)); | 358 | u64(0x000000ffffffffffffffff)); |
| 359 | c.printf(c"0o1777777777777777777777: %llu\n", | 359 | _ = c.printf(c"0o1777777777777777777777: %llu\n", |
| 360 | u64(0o1777777777777777777777)); | 360 | u64(0o1777777777777777777777)); |
| 361 | c.printf(c"0o0000001777777777777777777777: %llu\n", | 361 | _ = c.printf(c"0o0000001777777777777777777777: %llu\n", |
| 362 | u64(0o0000001777777777777777777777)); | 362 | u64(0o0000001777777777777777777777)); |
| 363 | c.printf(c"0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n", | 363 | _ = c.printf(c"0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n", |
| 364 | u64(0b1111111111111111111111111111111111111111111111111111111111111111)); | 364 | u64(0b1111111111111111111111111111111111111111111111111111111111111111)); |
| 365 | c.printf(c"0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n", | 365 | _ = c.printf(c"0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n", |
| 366 | u64(0b0000001111111111111111111111111111111111111111111111111111111111111111)); | 366 | u64(0b0000001111111111111111111111111111111111111111111111111111111111111111)); |
| 367 | 367 | ||
| 368 | c.printf(c"\n"); | 368 | _ = c.printf(c"\n"); |
| 369 | 369 | ||
| 370 | c.printf(c"0.0: %a\n", | 370 | _ = c.printf(c"0.0: %a\n", |
| 371 | f64(0.0)); | 371 | f64(0.0)); |
| 372 | c.printf(c"0e0: %a\n", | 372 | _ = c.printf(c"0e0: %a\n", |
| 373 | f64(0e0)); | 373 | f64(0e0)); |
| 374 | c.printf(c"0.0e0: %a\n", | 374 | _ = c.printf(c"0.0e0: %a\n", |
| 375 | f64(0.0e0)); | 375 | f64(0.0e0)); |
| 376 | c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %a\n", | 376 | _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %a\n", |
| 377 | f64(000000000000000000000000000000000000000000000000000000000.0e0)); | 377 | f64(000000000000000000000000000000000000000000000000000000000.0e0)); |
| 378 | c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %a\n", | 378 | _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %a\n", |
| 379 | f64(0.000000000000000000000000000000000000000000000000000000000e0)); | 379 | f64(0.000000000000000000000000000000000000000000000000000000000e0)); |
| 380 | c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %a\n", | 380 | _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %a\n", |
| 381 | f64(0.0e000000000000000000000000000000000000000000000000000000000)); | 381 | f64(0.0e000000000000000000000000000000000000000000000000000000000)); |
| 382 | c.printf(c"1.0: %a\n", | 382 | _ = c.printf(c"1.0: %a\n", |
| 383 | f64(1.0)); | 383 | f64(1.0)); |
| 384 | c.printf(c"10.0: %a\n", | 384 | _ = c.printf(c"10.0: %a\n", |
| 385 | f64(10.0)); | 385 | f64(10.0)); |
| 386 | c.printf(c"10.5: %a\n", | 386 | _ = c.printf(c"10.5: %a\n", |
| 387 | f64(10.5)); | 387 | f64(10.5)); |
| 388 | c.printf(c"10.5e5: %a\n", | 388 | _ = c.printf(c"10.5e5: %a\n", |
| 389 | f64(10.5e5)); | 389 | f64(10.5e5)); |
| 390 | c.printf(c"10.5e+5: %a\n", | 390 | _ = c.printf(c"10.5e+5: %a\n", |
| 391 | f64(10.5e+5)); | 391 | f64(10.5e+5)); |
| 392 | c.printf(c"50.0e-2: %a\n", | 392 | _ = c.printf(c"50.0e-2: %a\n", |
| 393 | f64(50.0e-2)); | 393 | f64(50.0e-2)); |
| 394 | c.printf(c"50e-2: %a\n", | 394 | _ = c.printf(c"50e-2: %a\n", |
| 395 | f64(50e-2)); | 395 | f64(50e-2)); |
| 396 | 396 | ||
| 397 | c.printf(c"\n"); | 397 | _ = c.printf(c"\n"); |
| 398 | 398 | ||
| 399 | c.printf(c"0x1.0: %a\n", | 399 | _ = c.printf(c"0x1.0: %a\n", |
| 400 | f64(0x1.0)); | 400 | f64(0x1.0)); |
| 401 | c.printf(c"0x10.0: %a\n", | 401 | _ = c.printf(c"0x10.0: %a\n", |
| 402 | f64(0x10.0)); | 402 | f64(0x10.0)); |
| 403 | c.printf(c"0x100.0: %a\n", | 403 | _ = c.printf(c"0x100.0: %a\n", |
| 404 | f64(0x100.0)); | 404 | f64(0x100.0)); |
| 405 | c.printf(c"0x103.0: %a\n", | 405 | _ = c.printf(c"0x103.0: %a\n", |
| 406 | f64(0x103.0)); | 406 | f64(0x103.0)); |
| 407 | c.printf(c"0x103.7: %a\n", | 407 | _ = c.printf(c"0x103.7: %a\n", |
| 408 | f64(0x103.7)); | 408 | f64(0x103.7)); |
| 409 | c.printf(c"0x103.70: %a\n", | 409 | _ = c.printf(c"0x103.70: %a\n", |
| 410 | f64(0x103.70)); | 410 | f64(0x103.70)); |
| 411 | c.printf(c"0x103.70p4: %a\n", | 411 | _ = c.printf(c"0x103.70p4: %a\n", |
| 412 | f64(0x103.70p4)); | 412 | f64(0x103.70p4)); |
| 413 | c.printf(c"0x103.70p5: %a\n", | 413 | _ = c.printf(c"0x103.70p5: %a\n", |
| 414 | f64(0x103.70p5)); | 414 | f64(0x103.70p5)); |
| 415 | c.printf(c"0x103.70p+5: %a\n", | 415 | _ = c.printf(c"0x103.70p+5: %a\n", |
| 416 | f64(0x103.70p+5)); | 416 | f64(0x103.70p+5)); |
| 417 | c.printf(c"0x103.70p-5: %a\n", | 417 | _ = c.printf(c"0x103.70p-5: %a\n", |
| 418 | f64(0x103.70p-5)); | 418 | f64(0x103.70p-5)); |
| 419 | 419 | ||
| 420 | c.printf(c"\n"); | 420 | _ = c.printf(c"\n"); |
| 421 | 421 | ||
| 422 | c.printf(c"0b10100.00010e0: %a\n", | 422 | _ = c.printf(c"0b10100.00010e0: %a\n", |
| 423 | f64(0b10100.00010e0)); | 423 | f64(0b10100.00010e0)); |
| 424 | c.printf(c"0o10700.00010e0: %a\n", | 424 | _ = c.printf(c"0o10700.00010e0: %a\n", |
| 425 | f64(0o10700.00010e0)); | 425 | f64(0o10700.00010e0)); |
| 426 | 426 | ||
| 427 | return 0; | 427 | return 0; |
| ... | @@ -520,7 +520,7 @@ export fn main(argc: c_int, argv: &&u8) -> c_int { | ... | @@ -520,7 +520,7 @@ export fn main(argc: c_int, argv: &&u8) -> c_int { |
| 520 | const x: f64 = small; | 520 | const x: f64 = small; |
| 521 | const y = i32(x); | 521 | const y = i32(x); |
| 522 | const z = f64(y); | 522 | const z = f64(y); |
| 523 | c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, f64(-0.4)); | 523 | _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, f64(-0.4)); |
| 524 | return 0; | 524 | return 0; |
| 525 | } | 525 | } |
| 526 | )SOURCE", "3.25\n3\n3.00\n-0.40\n"); | 526 | )SOURCE", "3.25\n3\n3.00\n-0.40\n"); |
| ... | @@ -1691,6 +1691,12 @@ fn bar() { } | ... | @@ -1691,6 +1691,12 @@ fn bar() { } |
| 1691 | ".tmp_source.zig:4:5: error: control flow attempts to use compile-time variable at runtime", | 1691 | ".tmp_source.zig:4:5: error: control flow attempts to use compile-time variable at runtime", |
| 1692 | ".tmp_source.zig:4:21: note: compile-time variable assigned here"); | 1692 | ".tmp_source.zig:4:21: note: compile-time variable assigned here"); |
| 1693 | 1693 | ||
| 1694 | add_compile_fail_case("ignored return value", R"SOURCE( | ||
| 1695 | fn foo() { | ||
| 1696 | bar(); | ||
| 1697 | } | ||
| 1698 | fn bar() -> i32 { 0 } | ||
| 1699 | )SOURCE", 1, ".tmp_source.zig:3:8: error: return value ignored"); | ||
| 1694 | } | 1700 | } |
| 1695 | 1701 | ||
| 1696 | ////////////////////////////////////////////////////////////////////////////// | 1702 | ////////////////////////////////////////////////////////////////////////////// |