authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-12 18:20:00-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-12 18:20:00-05:00
log5699ab5e77f8d13cac1e34775e6e51358119965c
tree00d8d677c008a7c7248861cb87fc415dd34816a4
parent270933b1e997c91a9c2d28b6896d625c0ae1b163
signature Commit is signed but in an unrecognized format.

C pointers: errors for nested pointer casting regarding null

See #1059

4 files changed, 181 insertions(+), 89 deletions(-)

src/all_types.hpp+9-3
......@@ -691,15 +691,17 @@ struct AstNodePointerType {
691691 AstNode *align_expr;
692692 BigInt *bit_offset_start;
693693 BigInt *host_int_bytes;
694 AstNode *op_expr;
695 Token *allow_zero_token;
694696 bool is_const;
695697 bool is_volatile;
696 AstNode *op_expr;
697698};
698699
699700struct AstNodeArrayType {
700701 AstNode *size;
701702 AstNode *child_type;
702703 AstNode *align_expr;
704 Token *allow_zero_token;
703705 bool is_const;
704706 bool is_volatile;
705707};
......@@ -1050,6 +1052,7 @@ struct ZigTypePointer {
10501052 uint32_t host_int_bytes; // size of host integer. 0 means no host integer; this field is aligned
10511053 bool is_const;
10521054 bool is_volatile;
1055 bool allow_zero;
10531056};
10541057
10551058struct ZigTypeInt {
......@@ -1499,11 +1502,12 @@ struct TypeId {
14991502 struct {
15001503 ZigType *child_type;
15011504 PtrLen ptr_len;
1502 bool is_const;
1503 bool is_volatile;
15041505 uint32_t alignment;
15051506 uint32_t bit_offset_in_host;
15061507 uint32_t host_int_bytes;
1508 bool is_const;
1509 bool is_volatile;
1510 bool allow_zero;
15071511 } pointer;
15081512 struct {
15091513 ZigType *child_type;
......@@ -2592,6 +2596,7 @@ struct IrInstructionPtrType {
25922596 PtrLen ptr_len;
25932597 bool is_const;
25942598 bool is_volatile;
2599 bool allow_zero;
25952600};
25962601
25972602struct IrInstructionPromiseType {
......@@ -2607,6 +2612,7 @@ struct IrInstructionSliceType {
26072612 IrInstruction *child_type;
26082613 bool is_const;
26092614 bool is_volatile;
2615 bool allow_zero;
26102616};
26112617
26122618struct IrInstructionAsm {
src/analyze.cpp+33-12
......@@ -433,6 +433,9 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
433433 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment,
434434 uint32_t bit_offset_in_host, uint32_t host_int_bytes)
435435{
436 // TODO when implementing https://github.com/ziglang/zig/issues/1953
437 // move this to a parameter
438 bool allow_zero = (ptr_len == PtrLenC);
436439 assert(!type_is_invalid(child_type));
437440 assert(ptr_len != PtrLenUnknown || child_type->id != ZigTypeIdOpaque);
438441
......@@ -452,7 +455,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
452455
453456 TypeId type_id = {};
454457 ZigType **parent_pointer = nullptr;
455 if (host_int_bytes != 0 || is_volatile || byte_alignment != 0 || ptr_len != PtrLenSingle) {
458 if (host_int_bytes != 0 || is_volatile || byte_alignment != 0 || ptr_len != PtrLenSingle || allow_zero) {
456459 type_id.id = ZigTypeIdPointer;
457460 type_id.data.pointer.child_type = child_type;
458461 type_id.data.pointer.is_const = is_const;
......@@ -461,6 +464,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
461464 type_id.data.pointer.bit_offset_in_host = bit_offset_in_host;
462465 type_id.data.pointer.host_int_bytes = host_int_bytes;
463466 type_id.data.pointer.ptr_len = ptr_len;
467 type_id.data.pointer.allow_zero = allow_zero;
464468
465469 auto existing_entry = g->type_table.maybe_get(type_id);
466470 if (existing_entry)
......@@ -481,18 +485,28 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
481485 const char *star_str = ptr_len_to_star_str(ptr_len);
482486 const char *const_str = is_const ? "const " : "";
483487 const char *volatile_str = is_volatile ? "volatile " : "";
488 const char *allow_zero_str;
489 if (ptr_len == PtrLenC) {
490 assert(allow_zero);
491 allow_zero_str = "";
492 } else {
493 allow_zero_str = allow_zero ? "allowzero " : "";
494 }
484495 buf_resize(&entry->name, 0);
485496 if (host_int_bytes == 0 && byte_alignment == 0) {
486 buf_appendf(&entry->name, "%s%s%s%s", star_str, const_str, volatile_str, buf_ptr(&child_type->name));
497 buf_appendf(&entry->name, "%s%s%s%s%s",
498 star_str, const_str, volatile_str, allow_zero_str, buf_ptr(&child_type->name));
487499 } else if (host_int_bytes == 0) {
488 buf_appendf(&entry->name, "%salign(%" PRIu32 ") %s%s%s", star_str, byte_alignment,
489 const_str, volatile_str, buf_ptr(&child_type->name));
500 buf_appendf(&entry->name, "%salign(%" PRIu32 ") %s%s%s%s", star_str, byte_alignment,
501 const_str, volatile_str, allow_zero_str, buf_ptr(&child_type->name));
490502 } else if (byte_alignment == 0) {
491 buf_appendf(&entry->name, "%salign(:%" PRIu32 ":%" PRIu32 ") %s%s%s", star_str,
492 bit_offset_in_host, host_int_bytes, const_str, volatile_str, buf_ptr(&child_type->name));
503 buf_appendf(&entry->name, "%salign(:%" PRIu32 ":%" PRIu32 ") %s%s%s%s", star_str,
504 bit_offset_in_host, host_int_bytes, const_str, volatile_str, allow_zero_str,
505 buf_ptr(&child_type->name));
493506 } else {
494 buf_appendf(&entry->name, "%salign(%" PRIu32 ":%" PRIu32 ":%" PRIu32 ") %s%s%s", star_str, byte_alignment,
495 bit_offset_in_host, host_int_bytes, const_str, volatile_str, buf_ptr(&child_type->name));
507 buf_appendf(&entry->name, "%salign(%" PRIu32 ":%" PRIu32 ":%" PRIu32 ") %s%s%s%s", star_str, byte_alignment,
508 bit_offset_in_host, host_int_bytes, const_str, volatile_str, allow_zero_str,
509 buf_ptr(&child_type->name));
496510 }
497511
498512 assert(child_type->id != ZigTypeIdInvalid);
......@@ -500,7 +514,9 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
500514 entry->zero_bits = !type_has_bits(child_type);
501515
502516 if (!entry->zero_bits) {
503 if (is_const || is_volatile || byte_alignment != 0 || ptr_len != PtrLenSingle || bit_offset_in_host != 0) {
517 if (is_const || is_volatile || byte_alignment != 0 || ptr_len != PtrLenSingle ||
518 bit_offset_in_host != 0 || allow_zero)
519 {
504520 ZigType *peer_type = get_pointer_to_type_extra(g, child_type, false, false,
505521 PtrLenSingle, 0, 0, host_int_bytes);
506522 entry->type_ref = peer_type->type_ref;
......@@ -534,6 +550,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
534550 entry->data.pointer.explicit_alignment = byte_alignment;
535551 entry->data.pointer.bit_offset_in_host = bit_offset_in_host;
536552 entry->data.pointer.host_int_bytes = host_int_bytes;
553 entry->data.pointer.allow_zero = allow_zero;
537554
538555 if (parent_pointer) {
539556 *parent_pointer = entry;
......@@ -850,7 +867,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
850867
851868 ZigType *child_type = ptr_type->data.pointer.child_type;
852869 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||
853 ptr_type->data.pointer.explicit_alignment != 0)
870 ptr_type->data.pointer.explicit_alignment != 0 || ptr_type->data.pointer.allow_zero)
854871 {
855872 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,
856873 PtrLenUnknown, 0, 0, 0);
......@@ -873,7 +890,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
873890 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;
874891 assert(child_ptr_type->id == ZigTypeIdPointer);
875892 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
876 child_ptr_type->data.pointer.explicit_alignment != 0)
893 child_ptr_type->data.pointer.explicit_alignment != 0 || child_ptr_type->data.pointer.allow_zero)
877894 {
878895 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;
879896 ZigType *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,
......@@ -4053,7 +4070,9 @@ ZigType *get_src_ptr_type(ZigType *type) {
40534070 if (type->id == ZigTypeIdFn) return type;
40544071 if (type->id == ZigTypeIdPromise) return type;
40554072 if (type->id == ZigTypeIdOptional) {
4056 if (type->data.maybe.child_type->id == ZigTypeIdPointer) return type->data.maybe.child_type;
4073 if (type->data.maybe.child_type->id == ZigTypeIdPointer) {
4074 return type->data.maybe.child_type->data.pointer.allow_zero ? nullptr : type->data.maybe.child_type;
4075 }
40574076 if (type->data.maybe.child_type->id == ZigTypeIdFn) return type->data.maybe.child_type;
40584077 if (type->data.maybe.child_type->id == ZigTypeIdPromise) return type->data.maybe.child_type;
40594078 }
......@@ -6289,6 +6308,7 @@ uint32_t type_id_hash(TypeId x) {
62896308 ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +
62906309 (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +
62916310 (x.data.pointer.is_volatile ? (uint32_t)536730450 : (uint32_t)1685612214) +
6311 (x.data.pointer.allow_zero ? (uint32_t)3324284834 : (uint32_t)3584904923) +
62926312 (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +
62936313 (((uint32_t)x.data.pointer.bit_offset_in_host) ^ (uint32_t)2639019452) +
62946314 (((uint32_t)x.data.pointer.host_int_bytes) ^ (uint32_t)529908881);
......@@ -6339,6 +6359,7 @@ bool type_id_eql(TypeId a, TypeId b) {
63396359 a.data.pointer.ptr_len == b.data.pointer.ptr_len &&
63406360 a.data.pointer.is_const == b.data.pointer.is_const &&
63416361 a.data.pointer.is_volatile == b.data.pointer.is_volatile &&
6362 a.data.pointer.allow_zero == b.data.pointer.allow_zero &&
63426363 a.data.pointer.alignment == b.data.pointer.alignment &&
63436364 a.data.pointer.bit_offset_in_host == b.data.pointer.bit_offset_in_host &&
63446365 a.data.pointer.host_int_bytes == b.data.pointer.host_int_bytes;
src/ir.cpp+70-29
......@@ -61,7 +61,7 @@ enum ConstCastResultId {
6161 ConstCastResultIdType,
6262 ConstCastResultIdUnresolvedInferredErrSet,
6363 ConstCastResultIdAsyncAllocatorType,
64 ConstCastResultIdNullWrapPtr
64 ConstCastResultIdBadAllowsZero,
6565};
6666
6767struct ConstCastOnly;
......@@ -83,6 +83,7 @@ struct ConstCastErrUnionErrSetMismatch;
8383struct ConstCastErrUnionPayloadMismatch;
8484struct ConstCastErrSetMismatch;
8585struct ConstCastTypeMismatch;
86struct ConstCastBadAllowsZero;
8687
8788struct ConstCastOnly {
8889 ConstCastResultId id;
......@@ -99,6 +100,7 @@ struct ConstCastOnly {
99100 ConstCastOnly *null_wrap_ptr_child;
100101 ConstCastArg fn_arg;
101102 ConstCastArgNoAlias arg_no_alias;
103 ConstCastBadAllowsZero *bad_allows_zero;
102104 } data;
103105};
104106
......@@ -141,6 +143,12 @@ struct ConstCastErrSetMismatch {
141143 ZigList<ErrorTableEntry *> missing_errors;
142144};
143145
146struct ConstCastBadAllowsZero {
147 ZigType *wanted_type;
148 ZigType *actual_type;
149};
150
151
144152enum UndefAllowed {
145153 UndefOk,
146154 UndefBad,
......@@ -8636,6 +8644,14 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
86368644 return err_set_type;
86378645}
86388646
8647static bool ptr_allows_addr_zero(ZigType *ptr_type) {
8648 if (ptr_type->id == ZigTypeIdPointer) {
8649 return ptr_type->data.pointer.allow_zero;
8650 } else if (ptr_type->id == ZigTypeIdOptional) {
8651 return true;
8652 }
8653 return false;
8654}
86398655
86408656static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted_type,
86418657 ZigType *actual_type, AstNode *source_node, bool wanted_is_mutable)
......@@ -8649,34 +8665,35 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
86498665 if (wanted_type == actual_type)
86508666 return result;
86518667
8652 // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively
8653 // but not if we want a mutable pointer
8654 // and not if the actual pointer has zero bits
8655 if (!wanted_is_mutable && wanted_type->id == ZigTypeIdOptional &&
8656 wanted_type->data.maybe.child_type->id == ZigTypeIdPointer &&
8657 actual_type->id == ZigTypeIdPointer && type_has_bits(actual_type))
8658 {
8659 ConstCastOnly child = types_match_const_cast_only(ira,
8660 wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable);
8661 if (child.id == ConstCastResultIdInvalid)
8662 return child;
8663 if (child.id != ConstCastResultIdOk) {
8664 result.id = ConstCastResultIdNullWrapPtr;
8665 result.data.null_wrap_ptr_child = allocate_nonzero<ConstCastOnly>(1);
8666 *result.data.null_wrap_ptr_child = child;
8667 }
8668 return result;
8669 }
8670
8671 // pointer const
8668 // If pointers have the same representation in memory, they can be "const-casted".
8669 // `const` attribute can be gained
8670 // `volatile` attribute can be gained
8671 // `allowzero` attribute can be gained (whether from explicit attribute, C pointer, or optional pointer)
8672 // but only if !wanted_is_mutable
8673 // alignment can be decreased
8674 // bit offset attributes must match exactly
8675 // PtrLenSingle/PtrLenUnknown must match exactly, but PtrLenC matches either one
86728676 ZigType *wanted_ptr_type = get_src_ptr_type(wanted_type);
86738677 ZigType *actual_ptr_type = get_src_ptr_type(actual_type);
8678 bool wanted_allows_zero = ptr_allows_addr_zero(wanted_type);
8679 bool actual_allows_zero = ptr_allows_addr_zero(actual_type);
86748680 bool wanted_is_c_ptr = wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC;
86758681 bool actual_is_c_ptr = actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenC;
8676 if ((wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) ||
8677 (wanted_ptr_type != nullptr && actual_is_c_ptr) ||
8678 (actual_ptr_type != nullptr && wanted_is_c_ptr))
8679 {
8682 bool wanted_opt_or_ptr = wanted_ptr_type != nullptr &&
8683 (wanted_type->id == ZigTypeIdPointer || wanted_type->id == ZigTypeIdOptional);
8684 bool actual_opt_or_ptr = actual_ptr_type != nullptr &&
8685 (actual_type->id == ZigTypeIdPointer || actual_type->id == ZigTypeIdOptional);
8686 if (wanted_opt_or_ptr && actual_opt_or_ptr) {
8687 bool ok_allows_zero = (wanted_allows_zero &&
8688 (actual_allows_zero || wanted_ptr_type->data.pointer.is_const)) ||
8689 (!wanted_allows_zero && !actual_allows_zero);
8690 if (!ok_allows_zero) {
8691 result.id = ConstCastResultIdBadAllowsZero;
8692 result.data.bad_allows_zero = allocate_nonzero<ConstCastBadAllowsZero>(1);
8693 result.data.bad_allows_zero->wanted_type = wanted_type;
8694 result.data.bad_allows_zero->actual_type = actual_type;
8695 return result;
8696 }
86808697 ConstCastOnly child = types_match_const_cast_only(ira, wanted_ptr_type->data.pointer.child_type,
86818698 actual_ptr_type->data.pointer.child_type, source_node, !wanted_ptr_type->data.pointer.is_const);
86828699 if (child.id == ConstCastResultIdInvalid)
......@@ -8699,6 +8716,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
86998716 }
87008717 bool ptr_lens_equal = actual_ptr_type->data.pointer.ptr_len == wanted_ptr_type->data.pointer.ptr_len;
87018718 if ((ptr_lens_equal || wanted_is_c_ptr || actual_is_c_ptr) &&
8719 type_has_bits(wanted_type) == type_has_bits(actual_type) &&
87028720 (!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) &&
87038721 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) &&
87048722 actual_ptr_type->data.pointer.bit_offset_in_host == wanted_ptr_type->data.pointer.bit_offset_in_host &&
......@@ -9922,7 +9940,7 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un
99229940 if (undef_allowed == UndefOk) {
99239941 return &value->value;
99249942 } else {
9925 ir_add_error(ira, value, buf_sprintf("use of undefined value"));
9943 ir_add_error(ira, value, buf_sprintf("use of undefined value here causes undefined behavior"));
99269944 return nullptr;
99279945 }
99289946 }
......@@ -10828,6 +10846,26 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
1082810846 report_recursive_error(ira, source_node, cast_result->data.fn_arg.child, msg);
1082910847 break;
1083010848 }
10849 case ConstCastResultIdBadAllowsZero: {
10850 bool wanted_allows_zero = ptr_allows_addr_zero(cast_result->data.bad_allows_zero->wanted_type);
10851 bool actual_allows_zero = ptr_allows_addr_zero(cast_result->data.bad_allows_zero->actual_type);
10852 ZigType *wanted_ptr_type = get_src_ptr_type(cast_result->data.bad_allows_zero->wanted_type);
10853 ZigType *actual_ptr_type = get_src_ptr_type(cast_result->data.bad_allows_zero->actual_type);
10854 ZigType *wanted_elem_type = wanted_ptr_type->data.pointer.child_type;
10855 ZigType *actual_elem_type = actual_ptr_type->data.pointer.child_type;
10856 if (actual_allows_zero && !wanted_allows_zero) {
10857 add_error_note(ira->codegen, parent_msg, source_node,
10858 buf_sprintf("'%s' could have null values which are illegal in type '%s'",
10859 buf_ptr(&actual_elem_type->name),
10860 buf_ptr(&wanted_elem_type->name)));
10861 } else {
10862 add_error_note(ira->codegen, parent_msg, source_node,
10863 buf_sprintf("mutable '%s' allows illegal null values stored to type '%s'",
10864 buf_ptr(&cast_result->data.bad_allows_zero->wanted_type->name),
10865 buf_ptr(&cast_result->data.bad_allows_zero->actual_type->name)));
10866 }
10867 break;
10868 }
1083110869 case ConstCastResultIdFnAlign: // TODO
1083210870 case ConstCastResultIdFnCC: // TODO
1083310871 case ConstCastResultIdFnVarArgs: // TODO
......@@ -10838,7 +10876,6 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
1083810876 case ConstCastResultIdFnArgNoAlias: // TODO
1083910877 case ConstCastResultIdUnresolvedInferredErrSet: // TODO
1084010878 case ConstCastResultIdAsyncAllocatorType: // TODO
10841 case ConstCastResultIdNullWrapPtr: // TODO
1084210879 break;
1084310880 }
1084410881}
......@@ -20589,12 +20626,14 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2058920626 // We have a check for zero bits later so we use get_src_ptr_type to
2059020627 // validate src_type and dest_type.
2059120628
20592 if (get_src_ptr_type(src_type) == nullptr) {
20629 ZigType *src_ptr_type = get_src_ptr_type(src_type);
20630 if (src_ptr_type == nullptr) {
2059320631 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
2059420632 return ira->codegen->invalid_instruction;
2059520633 }
2059620634
20597 if (get_src_ptr_type(dest_type) == nullptr) {
20635 ZigType *dest_ptr_type = get_src_ptr_type(dest_type);
20636 if (dest_ptr_type == nullptr) {
2059820637 ir_add_error(ira, dest_type_src,
2059920638 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
2060020639 return ira->codegen->invalid_instruction;
......@@ -20606,6 +20645,8 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2060620645 }
2060720646
2060820647 if (instr_is_comptime(ptr)) {
20648 // Undefined is OK here; @ptrCast is defined to reinterpret the bit pattern
20649 // of the pointer as the new pointer type.
2060920650 ConstExprValue *val = ir_resolve_const(ira, ptr, UndefOk);
2061020651 if (!val)
2061120652 return ira->codegen->invalid_instruction;
test/compile_errors.zig+69-45
......@@ -1,6 +1,30 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.addTest(
5 "implicit casting C pointers which would mess up null semantics",
6 \\export fn entry() void {
7 \\ var slice: []const u8 = "aoeu";
8 \\ const opt_many_ptr: [*]const u8 = slice.ptr;
9 \\ var ptr_opt_many_ptr = &opt_many_ptr;
10 \\ var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
11 \\ ptr_opt_many_ptr = c_ptr;
12 \\}
13 \\export fn entry2() void {
14 \\ var buf: [4]u8 = "aoeu";
15 \\ var slice: []u8 = &buf;
16 \\ var opt_many_ptr: [*]u8 = slice.ptr;
17 \\ var ptr_opt_many_ptr = &opt_many_ptr;
18 \\ var c_ptr: [*c]const [*c]u8 = ptr_opt_many_ptr;
19 \\}
20 ,
21 ".tmp_source.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'",
22 ".tmp_source.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'",
23 ".tmp_source.zig:13:35: error: expected type '[*c]const [*c]u8', found '*[*]u8'",
24 ".tmp_source.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]u8'",
25 ".tmp_source.zig:13:35: note: mutable '[*c]u8' allows illegal null values stored to type '[*]u8'",
26 );
27
428 cases.addTest(
529 "implicit casting too big integers to C pointers",
630 \\export fn a() void {
......@@ -31,7 +55,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3155 \\ var z = @truncate(u8, u16(undefined));
3256 \\}
3357 ,
34 ".tmp_source.zig:2:30: error: use of undefined value",
58 ".tmp_source.zig:2:30: error: use of undefined value here causes undefined behavior",
3559 );
3660
3761 cases.addTest(
......@@ -392,7 +416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
392416 \\ f(i32);
393417 \\}
394418 ,
395 ".tmp_source.zig:4:5: error: use of undefined value",
419 ".tmp_source.zig:4:5: error: use of undefined value here causes undefined behavior",
396420 );
397421
398422 cases.add(
......@@ -792,7 +816,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
792816 \\ command.exec();
793817 \\}
794818 ,
795 ".tmp_source.zig:6:12: error: use of undefined value",
819 ".tmp_source.zig:6:12: error: use of undefined value here causes undefined behavior",
796820 );
797821
798822 cases.add(
......@@ -805,7 +829,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
805829 \\ command.exec();
806830 \\}
807831 ,
808 ".tmp_source.zig:6:12: error: use of undefined value",
832 ".tmp_source.zig:6:12: error: use of undefined value here causes undefined behavior",
809833 );
810834
811835 cases.add(
......@@ -2776,7 +2800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27762800 \\
27772801 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
27782802 ,
2779 ".tmp_source.zig:1:15: error: use of undefined value",
2803 ".tmp_source.zig:1:15: error: use of undefined value here causes undefined behavior",
27802804 );
27812805
27822806 cases.add(
......@@ -2786,7 +2810,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27862810 \\ _ = a / a;
27872811 \\}
27882812 ,
2789 ".tmp_source.zig:3:9: error: use of undefined value",
2813 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
27902814 );
27912815
27922816 cases.add(
......@@ -2796,7 +2820,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27962820 \\ a /= a;
27972821 \\}
27982822 ,
2799 ".tmp_source.zig:3:5: error: use of undefined value",
2823 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
28002824 );
28012825
28022826 cases.add(
......@@ -2806,7 +2830,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28062830 \\ _ = a % a;
28072831 \\}
28082832 ,
2809 ".tmp_source.zig:3:9: error: use of undefined value",
2833 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
28102834 );
28112835
28122836 cases.add(
......@@ -2816,7 +2840,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28162840 \\ a %= a;
28172841 \\}
28182842 ,
2819 ".tmp_source.zig:3:5: error: use of undefined value",
2843 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
28202844 );
28212845
28222846 cases.add(
......@@ -2826,7 +2850,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28262850 \\ _ = a + a;
28272851 \\}
28282852 ,
2829 ".tmp_source.zig:3:9: error: use of undefined value",
2853 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
28302854 );
28312855
28322856 cases.add(
......@@ -2836,7 +2860,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28362860 \\ a += a;
28372861 \\}
28382862 ,
2839 ".tmp_source.zig:3:5: error: use of undefined value",
2863 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
28402864 );
28412865
28422866 cases.add(
......@@ -2846,7 +2870,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28462870 \\ _ = a +% a;
28472871 \\}
28482872 ,
2849 ".tmp_source.zig:3:9: error: use of undefined value",
2873 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
28502874 );
28512875
28522876 cases.add(
......@@ -2856,7 +2880,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28562880 \\ a +%= a;
28572881 \\}
28582882 ,
2859 ".tmp_source.zig:3:5: error: use of undefined value",
2883 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
28602884 );
28612885
28622886 cases.add(
......@@ -2866,7 +2890,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28662890 \\ _ = a - a;
28672891 \\}
28682892 ,
2869 ".tmp_source.zig:3:9: error: use of undefined value",
2893 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
28702894 );
28712895
28722896 cases.add(
......@@ -2876,7 +2900,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28762900 \\ a -= a;
28772901 \\}
28782902 ,
2879 ".tmp_source.zig:3:5: error: use of undefined value",
2903 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
28802904 );
28812905
28822906 cases.add(
......@@ -2886,7 +2910,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28862910 \\ _ = a -% a;
28872911 \\}
28882912 ,
2889 ".tmp_source.zig:3:9: error: use of undefined value",
2913 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
28902914 );
28912915
28922916 cases.add(
......@@ -2896,7 +2920,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28962920 \\ a -%= a;
28972921 \\}
28982922 ,
2899 ".tmp_source.zig:3:5: error: use of undefined value",
2923 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
29002924 );
29012925
29022926 cases.add(
......@@ -2906,7 +2930,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29062930 \\ _ = a * a;
29072931 \\}
29082932 ,
2909 ".tmp_source.zig:3:9: error: use of undefined value",
2933 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
29102934 );
29112935
29122936 cases.add(
......@@ -2916,7 +2940,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29162940 \\ a *= a;
29172941 \\}
29182942 ,
2919 ".tmp_source.zig:3:5: error: use of undefined value",
2943 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
29202944 );
29212945
29222946 cases.add(
......@@ -2926,7 +2950,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29262950 \\ _ = a *% a;
29272951 \\}
29282952 ,
2929 ".tmp_source.zig:3:9: error: use of undefined value",
2953 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
29302954 );
29312955
29322956 cases.add(
......@@ -2936,7 +2960,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29362960 \\ a *%= a;
29372961 \\}
29382962 ,
2939 ".tmp_source.zig:3:5: error: use of undefined value",
2963 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
29402964 );
29412965
29422966 cases.add(
......@@ -2946,7 +2970,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29462970 \\ _ = a << 2;
29472971 \\}
29482972 ,
2949 ".tmp_source.zig:3:9: error: use of undefined value",
2973 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
29502974 );
29512975
29522976 cases.add(
......@@ -2956,7 +2980,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29562980 \\ a <<= 2;
29572981 \\}
29582982 ,
2959 ".tmp_source.zig:3:5: error: use of undefined value",
2983 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
29602984 );
29612985
29622986 cases.add(
......@@ -2966,7 +2990,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29662990 \\ _ = a >> 2;
29672991 \\}
29682992 ,
2969 ".tmp_source.zig:3:9: error: use of undefined value",
2993 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
29702994 );
29712995
29722996 cases.add(
......@@ -2976,7 +3000,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29763000 \\ a >>= 2;
29773001 \\}
29783002 ,
2979 ".tmp_source.zig:3:5: error: use of undefined value",
3003 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
29803004 );
29813005
29823006 cases.add(
......@@ -2986,7 +3010,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29863010 \\ _ = a & a;
29873011 \\}
29883012 ,
2989 ".tmp_source.zig:3:9: error: use of undefined value",
3013 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
29903014 );
29913015
29923016 cases.add(
......@@ -2996,7 +3020,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29963020 \\ a &= a;
29973021 \\}
29983022 ,
2999 ".tmp_source.zig:3:5: error: use of undefined value",
3023 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
30003024 );
30013025
30023026 cases.add(
......@@ -3006,7 +3030,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30063030 \\ _ = a | a;
30073031 \\}
30083032 ,
3009 ".tmp_source.zig:3:9: error: use of undefined value",
3033 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
30103034 );
30113035
30123036 cases.add(
......@@ -3016,7 +3040,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30163040 \\ a |= a;
30173041 \\}
30183042 ,
3019 ".tmp_source.zig:3:5: error: use of undefined value",
3043 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
30203044 );
30213045
30223046 cases.add(
......@@ -3026,7 +3050,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30263050 \\ _ = a ^ a;
30273051 \\}
30283052 ,
3029 ".tmp_source.zig:3:9: error: use of undefined value",
3053 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
30303054 );
30313055
30323056 cases.add(
......@@ -3036,7 +3060,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30363060 \\ a ^= a;
30373061 \\}
30383062 ,
3039 ".tmp_source.zig:3:5: error: use of undefined value",
3063 ".tmp_source.zig:3:5: error: use of undefined value here causes undefined behavior",
30403064 );
30413065
30423066 cases.add(
......@@ -3046,7 +3070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30463070 \\ _ = a == a;
30473071 \\}
30483072 ,
3049 ".tmp_source.zig:3:9: error: use of undefined value",
3073 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
30503074 );
30513075
30523076 cases.add(
......@@ -3056,7 +3080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30563080 \\ _ = a != a;
30573081 \\}
30583082 ,
3059 ".tmp_source.zig:3:9: error: use of undefined value",
3083 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
30603084 );
30613085
30623086 cases.add(
......@@ -3066,7 +3090,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30663090 \\ _ = a > a;
30673091 \\}
30683092 ,
3069 ".tmp_source.zig:3:9: error: use of undefined value",
3093 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
30703094 );
30713095
30723096 cases.add(
......@@ -3076,7 +3100,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30763100 \\ _ = a >= a;
30773101 \\}
30783102 ,
3079 ".tmp_source.zig:3:9: error: use of undefined value",
3103 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
30803104 );
30813105
30823106 cases.add(
......@@ -3086,7 +3110,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30863110 \\ _ = a < a;
30873111 \\}
30883112 ,
3089 ".tmp_source.zig:3:9: error: use of undefined value",
3113 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
30903114 );
30913115
30923116 cases.add(
......@@ -3096,7 +3120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30963120 \\ _ = a <= a;
30973121 \\}
30983122 ,
3099 ".tmp_source.zig:3:9: error: use of undefined value",
3123 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
31003124 );
31013125
31023126 cases.add(
......@@ -3106,7 +3130,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
31063130 \\ _ = a and a;
31073131 \\}
31083132 ,
3109 ".tmp_source.zig:3:9: error: use of undefined value",
3133 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
31103134 );
31113135
31123136 cases.add(
......@@ -3116,7 +3140,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
31163140 \\ _ = a or a;
31173141 \\}
31183142 ,
3119 ".tmp_source.zig:3:9: error: use of undefined value",
3143 ".tmp_source.zig:3:9: error: use of undefined value here causes undefined behavior",
31203144 );
31213145
31223146 cases.add(
......@@ -3126,7 +3150,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
31263150 \\ _ = -a;
31273151 \\}
31283152 ,
3129 ".tmp_source.zig:3:10: error: use of undefined value",
3153 ".tmp_source.zig:3:10: error: use of undefined value here causes undefined behavior",
31303154 );
31313155
31323156 cases.add(
......@@ -3136,7 +3160,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
31363160 \\ _ = -%a;
31373161 \\}
31383162 ,
3139 ".tmp_source.zig:3:11: error: use of undefined value",
3163 ".tmp_source.zig:3:11: error: use of undefined value here causes undefined behavior",
31403164 );
31413165
31423166 cases.add(
......@@ -3146,7 +3170,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
31463170 \\ _ = ~a;
31473171 \\}
31483172 ,
3149 ".tmp_source.zig:3:10: error: use of undefined value",
3173 ".tmp_source.zig:3:10: error: use of undefined value here causes undefined behavior",
31503174 );
31513175
31523176 cases.add(
......@@ -3156,7 +3180,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
31563180 \\ _ = !a;
31573181 \\}
31583182 ,
3159 ".tmp_source.zig:3:10: error: use of undefined value",
3183 ".tmp_source.zig:3:10: error: use of undefined value here causes undefined behavior",
31603184 );
31613185
31623186 cases.add(
......@@ -3166,7 +3190,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
31663190 \\ _ = a orelse false;
31673191 \\}
31683192 ,
3169 ".tmp_source.zig:3:11: error: use of undefined value",
3193 ".tmp_source.zig:3:11: error: use of undefined value here causes undefined behavior",
31703194 );
31713195
31723196 cases.add(
......@@ -3176,7 +3200,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
31763200 \\ _ = a catch |err| false;
31773201 \\}
31783202 ,
3179 ".tmp_source.zig:3:11: error: use of undefined value",
3203 ".tmp_source.zig:3:11: error: use of undefined value here causes undefined behavior",
31803204 );
31813205
31823206 cases.add(