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 {...@@ -691,15 +691,17 @@ struct AstNodePointerType {
691 AstNode *align_expr;691 AstNode *align_expr;
692 BigInt *bit_offset_start;692 BigInt *bit_offset_start;
693 BigInt *host_int_bytes;693 BigInt *host_int_bytes;
694 AstNode *op_expr;
695 Token *allow_zero_token;
694 bool is_const;696 bool is_const;
695 bool is_volatile;697 bool is_volatile;
696 AstNode *op_expr;
697};698};
698699
699struct AstNodeArrayType {700struct AstNodeArrayType {
700 AstNode *size;701 AstNode *size;
701 AstNode *child_type;702 AstNode *child_type;
702 AstNode *align_expr;703 AstNode *align_expr;
704 Token *allow_zero_token;
703 bool is_const;705 bool is_const;
704 bool is_volatile;706 bool is_volatile;
705};707};
...@@ -1050,6 +1052,7 @@ struct ZigTypePointer {...@@ -1050,6 +1052,7 @@ struct ZigTypePointer {
1050 uint32_t host_int_bytes; // size of host integer. 0 means no host integer; this field is aligned1052 uint32_t host_int_bytes; // size of host integer. 0 means no host integer; this field is aligned
1051 bool is_const;1053 bool is_const;
1052 bool is_volatile;1054 bool is_volatile;
1055 bool allow_zero;
1053};1056};
10541057
1055struct ZigTypeInt {1058struct ZigTypeInt {
...@@ -1499,11 +1502,12 @@ struct TypeId {...@@ -1499,11 +1502,12 @@ struct TypeId {
1499 struct {1502 struct {
1500 ZigType *child_type;1503 ZigType *child_type;
1501 PtrLen ptr_len;1504 PtrLen ptr_len;
1502 bool is_const;
1503 bool is_volatile;
1504 uint32_t alignment;1505 uint32_t alignment;
1505 uint32_t bit_offset_in_host;1506 uint32_t bit_offset_in_host;
1506 uint32_t host_int_bytes;1507 uint32_t host_int_bytes;
1508 bool is_const;
1509 bool is_volatile;
1510 bool allow_zero;
1507 } pointer;1511 } pointer;
1508 struct {1512 struct {
1509 ZigType *child_type;1513 ZigType *child_type;
...@@ -2592,6 +2596,7 @@ struct IrInstructionPtrType {...@@ -2592,6 +2596,7 @@ struct IrInstructionPtrType {
2592 PtrLen ptr_len;2596 PtrLen ptr_len;
2593 bool is_const;2597 bool is_const;
2594 bool is_volatile;2598 bool is_volatile;
2599 bool allow_zero;
2595};2600};
25962601
2597struct IrInstructionPromiseType {2602struct IrInstructionPromiseType {
...@@ -2607,6 +2612,7 @@ struct IrInstructionSliceType {...@@ -2607,6 +2612,7 @@ struct IrInstructionSliceType {
2607 IrInstruction *child_type;2612 IrInstruction *child_type;
2608 bool is_const;2613 bool is_const;
2609 bool is_volatile;2614 bool is_volatile;
2615 bool allow_zero;
2610};2616};
26112617
2612struct IrInstructionAsm {2618struct IrInstructionAsm {
src/analyze.cpp+33-12
...@@ -433,6 +433,9 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons...@@ -433,6 +433,9 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
433 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment,433 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment,
434 uint32_t bit_offset_in_host, uint32_t host_int_bytes)434 uint32_t bit_offset_in_host, uint32_t host_int_bytes)
435{435{
436 // TODO when implementing https://github.com/ziglang/zig/issues/1953
437 // move this to a parameter
438 bool allow_zero = (ptr_len == PtrLenC);
436 assert(!type_is_invalid(child_type));439 assert(!type_is_invalid(child_type));
437 assert(ptr_len != PtrLenUnknown || child_type->id != ZigTypeIdOpaque);440 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...@@ -452,7 +455,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
452455
453 TypeId type_id = {};456 TypeId type_id = {};
454 ZigType **parent_pointer = nullptr;457 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) {
456 type_id.id = ZigTypeIdPointer;459 type_id.id = ZigTypeIdPointer;
457 type_id.data.pointer.child_type = child_type;460 type_id.data.pointer.child_type = child_type;
458 type_id.data.pointer.is_const = is_const;461 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...@@ -461,6 +464,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
461 type_id.data.pointer.bit_offset_in_host = bit_offset_in_host;464 type_id.data.pointer.bit_offset_in_host = bit_offset_in_host;
462 type_id.data.pointer.host_int_bytes = host_int_bytes;465 type_id.data.pointer.host_int_bytes = host_int_bytes;
463 type_id.data.pointer.ptr_len = ptr_len;466 type_id.data.pointer.ptr_len = ptr_len;
467 type_id.data.pointer.allow_zero = allow_zero;
464468
465 auto existing_entry = g->type_table.maybe_get(type_id);469 auto existing_entry = g->type_table.maybe_get(type_id);
466 if (existing_entry)470 if (existing_entry)
...@@ -481,18 +485,28 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons...@@ -481,18 +485,28 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
481 const char *star_str = ptr_len_to_star_str(ptr_len);485 const char *star_str = ptr_len_to_star_str(ptr_len);
482 const char *const_str = is_const ? "const " : "";486 const char *const_str = is_const ? "const " : "";
483 const char *volatile_str = is_volatile ? "volatile " : "";487 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 }
484 buf_resize(&entry->name, 0);495 buf_resize(&entry->name, 0);
485 if (host_int_bytes == 0 && byte_alignment == 0) {496 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));
487 } else if (host_int_bytes == 0) {499 } else if (host_int_bytes == 0) {
488 buf_appendf(&entry->name, "%salign(%" PRIu32 ") %s%s%s", star_str, byte_alignment,500 buf_appendf(&entry->name, "%salign(%" PRIu32 ") %s%s%s%s", star_str, byte_alignment,
489 const_str, volatile_str, buf_ptr(&child_type->name));501 const_str, volatile_str, allow_zero_str, buf_ptr(&child_type->name));
490 } else if (byte_alignment == 0) {502 } else if (byte_alignment == 0) {
491 buf_appendf(&entry->name, "%salign(:%" PRIu32 ":%" PRIu32 ") %s%s%s", star_str,503 buf_appendf(&entry->name, "%salign(:%" PRIu32 ":%" PRIu32 ") %s%s%s%s", star_str,
492 bit_offset_in_host, host_int_bytes, const_str, volatile_str, buf_ptr(&child_type->name));504 bit_offset_in_host, host_int_bytes, const_str, volatile_str, allow_zero_str,
505 buf_ptr(&child_type->name));
493 } else {506 } else {
494 buf_appendf(&entry->name, "%salign(%" PRIu32 ":%" PRIu32 ":%" PRIu32 ") %s%s%s", star_str, byte_alignment,507 buf_appendf(&entry->name, "%salign(%" PRIu32 ":%" PRIu32 ":%" PRIu32 ") %s%s%s%s", star_str, byte_alignment,
495 bit_offset_in_host, host_int_bytes, const_str, volatile_str, buf_ptr(&child_type->name));508 bit_offset_in_host, host_int_bytes, const_str, volatile_str, allow_zero_str,
509 buf_ptr(&child_type->name));
496 }510 }
497511
498 assert(child_type->id != ZigTypeIdInvalid);512 assert(child_type->id != ZigTypeIdInvalid);
...@@ -500,7 +514,9 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons...@@ -500,7 +514,9 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
500 entry->zero_bits = !type_has_bits(child_type);514 entry->zero_bits = !type_has_bits(child_type);
501515
502 if (!entry->zero_bits) {516 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 {
504 ZigType *peer_type = get_pointer_to_type_extra(g, child_type, false, false,520 ZigType *peer_type = get_pointer_to_type_extra(g, child_type, false, false,
505 PtrLenSingle, 0, 0, host_int_bytes);521 PtrLenSingle, 0, 0, host_int_bytes);
506 entry->type_ref = peer_type->type_ref;522 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...@@ -534,6 +550,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
534 entry->data.pointer.explicit_alignment = byte_alignment;550 entry->data.pointer.explicit_alignment = byte_alignment;
535 entry->data.pointer.bit_offset_in_host = bit_offset_in_host;551 entry->data.pointer.bit_offset_in_host = bit_offset_in_host;
536 entry->data.pointer.host_int_bytes = host_int_bytes;552 entry->data.pointer.host_int_bytes = host_int_bytes;
553 entry->data.pointer.allow_zero = allow_zero;
537554
538 if (parent_pointer) {555 if (parent_pointer) {
539 *parent_pointer = entry;556 *parent_pointer = entry;
...@@ -850,7 +867,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {...@@ -850,7 +867,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
850867
851 ZigType *child_type = ptr_type->data.pointer.child_type;868 ZigType *child_type = ptr_type->data.pointer.child_type;
852 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||869 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)
854 {871 {
855 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,872 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,
856 PtrLenUnknown, 0, 0, 0);873 PtrLenUnknown, 0, 0, 0);
...@@ -873,7 +890,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {...@@ -873,7 +890,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
873 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;890 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;
874 assert(child_ptr_type->id == ZigTypeIdPointer);891 assert(child_ptr_type->id == ZigTypeIdPointer);
875 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||892 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)
877 {894 {
878 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;895 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;
879 ZigType *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,896 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) {...@@ -4053,7 +4070,9 @@ ZigType *get_src_ptr_type(ZigType *type) {
4053 if (type->id == ZigTypeIdFn) return type;4070 if (type->id == ZigTypeIdFn) return type;
4054 if (type->id == ZigTypeIdPromise) return type;4071 if (type->id == ZigTypeIdPromise) return type;
4055 if (type->id == ZigTypeIdOptional) {4072 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 }
4057 if (type->data.maybe.child_type->id == ZigTypeIdFn) return type->data.maybe.child_type;4076 if (type->data.maybe.child_type->id == ZigTypeIdFn) return type->data.maybe.child_type;
4058 if (type->data.maybe.child_type->id == ZigTypeIdPromise) return type->data.maybe.child_type;4077 if (type->data.maybe.child_type->id == ZigTypeIdPromise) return type->data.maybe.child_type;
4059 }4078 }
...@@ -6289,6 +6308,7 @@ uint32_t type_id_hash(TypeId x) {...@@ -6289,6 +6308,7 @@ uint32_t type_id_hash(TypeId x) {
6289 ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +6308 ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +
6290 (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +6309 (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +
6291 (x.data.pointer.is_volatile ? (uint32_t)536730450 : (uint32_t)1685612214) +6310 (x.data.pointer.is_volatile ? (uint32_t)536730450 : (uint32_t)1685612214) +
6311 (x.data.pointer.allow_zero ? (uint32_t)3324284834 : (uint32_t)3584904923) +
6292 (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +6312 (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +
6293 (((uint32_t)x.data.pointer.bit_offset_in_host) ^ (uint32_t)2639019452) +6313 (((uint32_t)x.data.pointer.bit_offset_in_host) ^ (uint32_t)2639019452) +
6294 (((uint32_t)x.data.pointer.host_int_bytes) ^ (uint32_t)529908881);6314 (((uint32_t)x.data.pointer.host_int_bytes) ^ (uint32_t)529908881);
...@@ -6339,6 +6359,7 @@ bool type_id_eql(TypeId a, TypeId b) {...@@ -6339,6 +6359,7 @@ bool type_id_eql(TypeId a, TypeId b) {
6339 a.data.pointer.ptr_len == b.data.pointer.ptr_len &&6359 a.data.pointer.ptr_len == b.data.pointer.ptr_len &&
6340 a.data.pointer.is_const == b.data.pointer.is_const &&6360 a.data.pointer.is_const == b.data.pointer.is_const &&
6341 a.data.pointer.is_volatile == b.data.pointer.is_volatile &&6361 a.data.pointer.is_volatile == b.data.pointer.is_volatile &&
6362 a.data.pointer.allow_zero == b.data.pointer.allow_zero &&
6342 a.data.pointer.alignment == b.data.pointer.alignment &&6363 a.data.pointer.alignment == b.data.pointer.alignment &&
6343 a.data.pointer.bit_offset_in_host == b.data.pointer.bit_offset_in_host &&6364 a.data.pointer.bit_offset_in_host == b.data.pointer.bit_offset_in_host &&
6344 a.data.pointer.host_int_bytes == b.data.pointer.host_int_bytes;6365 a.data.pointer.host_int_bytes == b.data.pointer.host_int_bytes;
src/ir.cpp+70-29
...@@ -61,7 +61,7 @@ enum ConstCastResultId {...@@ -61,7 +61,7 @@ enum ConstCastResultId {
61 ConstCastResultIdType,61 ConstCastResultIdType,
62 ConstCastResultIdUnresolvedInferredErrSet,62 ConstCastResultIdUnresolvedInferredErrSet,
63 ConstCastResultIdAsyncAllocatorType,63 ConstCastResultIdAsyncAllocatorType,
64 ConstCastResultIdNullWrapPtr64 ConstCastResultIdBadAllowsZero,
65};65};
6666
67struct ConstCastOnly;67struct ConstCastOnly;
...@@ -83,6 +83,7 @@ struct ConstCastErrUnionErrSetMismatch;...@@ -83,6 +83,7 @@ struct ConstCastErrUnionErrSetMismatch;
83struct ConstCastErrUnionPayloadMismatch;83struct ConstCastErrUnionPayloadMismatch;
84struct ConstCastErrSetMismatch;84struct ConstCastErrSetMismatch;
85struct ConstCastTypeMismatch;85struct ConstCastTypeMismatch;
86struct ConstCastBadAllowsZero;
8687
87struct ConstCastOnly {88struct ConstCastOnly {
88 ConstCastResultId id;89 ConstCastResultId id;
...@@ -99,6 +100,7 @@ struct ConstCastOnly {...@@ -99,6 +100,7 @@ struct ConstCastOnly {
99 ConstCastOnly *null_wrap_ptr_child;100 ConstCastOnly *null_wrap_ptr_child;
100 ConstCastArg fn_arg;101 ConstCastArg fn_arg;
101 ConstCastArgNoAlias arg_no_alias;102 ConstCastArgNoAlias arg_no_alias;
103 ConstCastBadAllowsZero *bad_allows_zero;
102 } data;104 } data;
103};105};
104106
...@@ -141,6 +143,12 @@ struct ConstCastErrSetMismatch {...@@ -141,6 +143,12 @@ struct ConstCastErrSetMismatch {
141 ZigList<ErrorTableEntry *> missing_errors;143 ZigList<ErrorTableEntry *> missing_errors;
142};144};
143145
146struct ConstCastBadAllowsZero {
147 ZigType *wanted_type;
148 ZigType *actual_type;
149};
150
151
144enum UndefAllowed {152enum UndefAllowed {
145 UndefOk,153 UndefOk,
146 UndefBad,154 UndefBad,
...@@ -8636,6 +8644,14 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp...@@ -8636,6 +8644,14 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
8636 return err_set_type;8644 return err_set_type;
8637}8645}
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
8640static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted_type,8656static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted_type,
8641 ZigType *actual_type, AstNode *source_node, bool wanted_is_mutable)8657 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...@@ -8649,34 +8665,35 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
8649 if (wanted_type == actual_type)8665 if (wanted_type == actual_type)
8650 return result;8666 return result;
86518667
8652 // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively8668 // If pointers have the same representation in memory, they can be "const-casted".
8653 // but not if we want a mutable pointer8669 // `const` attribute can be gained
8654 // and not if the actual pointer has zero bits8670 // `volatile` attribute can be gained
8655 if (!wanted_is_mutable && wanted_type->id == ZigTypeIdOptional &&8671 // `allowzero` attribute can be gained (whether from explicit attribute, C pointer, or optional pointer)
8656 wanted_type->data.maybe.child_type->id == ZigTypeIdPointer &&8672 // but only if !wanted_is_mutable
8657 actual_type->id == ZigTypeIdPointer && type_has_bits(actual_type))8673 // alignment can be decreased
8658 {8674 // bit offset attributes must match exactly
8659 ConstCastOnly child = types_match_const_cast_only(ira,8675 // PtrLenSingle/PtrLenUnknown must match exactly, but PtrLenC matches either one
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
8672 ZigType *wanted_ptr_type = get_src_ptr_type(wanted_type);8676 ZigType *wanted_ptr_type = get_src_ptr_type(wanted_type);
8673 ZigType *actual_ptr_type = get_src_ptr_type(actual_type);8677 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);
8674 bool wanted_is_c_ptr = wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC;8680 bool wanted_is_c_ptr = wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC;
8675 bool actual_is_c_ptr = actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenC;8681 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) ||8682 bool wanted_opt_or_ptr = wanted_ptr_type != nullptr &&
8677 (wanted_ptr_type != nullptr && actual_is_c_ptr) ||8683 (wanted_type->id == ZigTypeIdPointer || wanted_type->id == ZigTypeIdOptional);
8678 (actual_ptr_type != nullptr && wanted_is_c_ptr))8684 bool actual_opt_or_ptr = actual_ptr_type != nullptr &&
8679 {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 }
8680 ConstCastOnly child = types_match_const_cast_only(ira, wanted_ptr_type->data.pointer.child_type,8697 ConstCastOnly child = types_match_const_cast_only(ira, wanted_ptr_type->data.pointer.child_type,
8681 actual_ptr_type->data.pointer.child_type, source_node, !wanted_ptr_type->data.pointer.is_const);8698 actual_ptr_type->data.pointer.child_type, source_node, !wanted_ptr_type->data.pointer.is_const);
8682 if (child.id == ConstCastResultIdInvalid)8699 if (child.id == ConstCastResultIdInvalid)
...@@ -8699,6 +8716,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -8699,6 +8716,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
8699 }8716 }
8700 bool ptr_lens_equal = actual_ptr_type->data.pointer.ptr_len == wanted_ptr_type->data.pointer.ptr_len;8717 bool ptr_lens_equal = actual_ptr_type->data.pointer.ptr_len == wanted_ptr_type->data.pointer.ptr_len;
8701 if ((ptr_lens_equal || wanted_is_c_ptr || actual_is_c_ptr) &&8718 if ((ptr_lens_equal || wanted_is_c_ptr || actual_is_c_ptr) &&
8719 type_has_bits(wanted_type) == type_has_bits(actual_type) &&
8702 (!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) &&8720 (!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) &&
8703 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) &&8721 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) &&
8704 actual_ptr_type->data.pointer.bit_offset_in_host == wanted_ptr_type->data.pointer.bit_offset_in_host &&8722 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...@@ -9922,7 +9940,7 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un
9922 if (undef_allowed == UndefOk) {9940 if (undef_allowed == UndefOk) {
9923 return &value->value;9941 return &value->value;
9924 } else {9942 } 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"));
9926 return nullptr;9944 return nullptr;
9927 }9945 }
9928 }9946 }
...@@ -10828,6 +10846,26 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa...@@ -10828,6 +10846,26 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
10828 report_recursive_error(ira, source_node, cast_result->data.fn_arg.child, msg);10846 report_recursive_error(ira, source_node, cast_result->data.fn_arg.child, msg);
10829 break;10847 break;
10830 }10848 }
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 }
10831 case ConstCastResultIdFnAlign: // TODO10869 case ConstCastResultIdFnAlign: // TODO
10832 case ConstCastResultIdFnCC: // TODO10870 case ConstCastResultIdFnCC: // TODO
10833 case ConstCastResultIdFnVarArgs: // TODO10871 case ConstCastResultIdFnVarArgs: // TODO
...@@ -10838,7 +10876,6 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa...@@ -10838,7 +10876,6 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
10838 case ConstCastResultIdFnArgNoAlias: // TODO10876 case ConstCastResultIdFnArgNoAlias: // TODO
10839 case ConstCastResultIdUnresolvedInferredErrSet: // TODO10877 case ConstCastResultIdUnresolvedInferredErrSet: // TODO
10840 case ConstCastResultIdAsyncAllocatorType: // TODO10878 case ConstCastResultIdAsyncAllocatorType: // TODO
10841 case ConstCastResultIdNullWrapPtr: // TODO
10842 break;10879 break;
10843 }10880 }
10844}10881}
...@@ -20589,12 +20626,14 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -20589,12 +20626,14 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
20589 // We have a check for zero bits later so we use get_src_ptr_type to20626 // We have a check for zero bits later so we use get_src_ptr_type to
20590 // validate src_type and dest_type.20627 // 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) {
20593 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));20631 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
20594 return ira->codegen->invalid_instruction;20632 return ira->codegen->invalid_instruction;
20595 }20633 }
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) {
20598 ir_add_error(ira, dest_type_src,20637 ir_add_error(ira, dest_type_src,
20599 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));20638 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
20600 return ira->codegen->invalid_instruction;20639 return ira->codegen->invalid_instruction;
...@@ -20606,6 +20645,8 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -20606,6 +20645,8 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
20606 }20645 }
2060720646
20608 if (instr_is_comptime(ptr)) {20647 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.
20609 ConstExprValue *val = ir_resolve_const(ira, ptr, UndefOk);20650 ConstExprValue *val = ir_resolve_const(ira, ptr, UndefOk);
20610 if (!val)20651 if (!val)
20611 return ira->codegen->invalid_instruction;20652 return ira->codegen->invalid_instruction;
test/compile_errors.zig+69-45
...@@ -1,6 +1,30 @@...@@ -1,6 +1,30 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub 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
4 cases.addTest(28 cases.addTest(
5 "implicit casting too big integers to C pointers",29 "implicit casting too big integers to C pointers",
6 \\export fn a() void {30 \\export fn a() void {
...@@ -31,7 +55,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -31,7 +55,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
31 \\ var z = @truncate(u8, u16(undefined));55 \\ var z = @truncate(u8, u16(undefined));
32 \\}56 \\}
33 ,57 ,
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",
35 );59 );
3660
37 cases.addTest(61 cases.addTest(
...@@ -392,7 +416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -392,7 +416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
392 \\ f(i32);416 \\ f(i32);
393 \\}417 \\}
394 ,418 ,
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",
396 );420 );
397421
398 cases.add(422 cases.add(
...@@ -792,7 +816,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -792,7 +816,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
792 \\ command.exec();816 \\ command.exec();
793 \\}817 \\}
794 ,818 ,
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",
796 );820 );
797821
798 cases.add(822 cases.add(
...@@ -805,7 +829,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -805,7 +829,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
805 \\ command.exec();829 \\ command.exec();
806 \\}830 \\}
807 ,831 ,
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",
809 );833 );
810834
811 cases.add(835 cases.add(
...@@ -2776,7 +2800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2776,7 +2800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2776 \\2800 \\
2777 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }2801 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
2778 ,2802 ,
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",
2780 );2804 );
27812805
2782 cases.add(2806 cases.add(
...@@ -2786,7 +2810,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2786,7 +2810,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2786 \\ _ = a / a;2810 \\ _ = a / a;
2787 \\}2811 \\}
2788 ,2812 ,
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",
2790 );2814 );
27912815
2792 cases.add(2816 cases.add(
...@@ -2796,7 +2820,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2796,7 +2820,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2796 \\ a /= a;2820 \\ a /= a;
2797 \\}2821 \\}
2798 ,2822 ,
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",
2800 );2824 );
28012825
2802 cases.add(2826 cases.add(
...@@ -2806,7 +2830,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2806,7 +2830,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2806 \\ _ = a % a;2830 \\ _ = a % a;
2807 \\}2831 \\}
2808 ,2832 ,
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",
2810 );2834 );
28112835
2812 cases.add(2836 cases.add(
...@@ -2816,7 +2840,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2816,7 +2840,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2816 \\ a %= a;2840 \\ a %= a;
2817 \\}2841 \\}
2818 ,2842 ,
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",
2820 );2844 );
28212845
2822 cases.add(2846 cases.add(
...@@ -2826,7 +2850,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2826,7 +2850,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2826 \\ _ = a + a;2850 \\ _ = a + a;
2827 \\}2851 \\}
2828 ,2852 ,
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",
2830 );2854 );
28312855
2832 cases.add(2856 cases.add(
...@@ -2836,7 +2860,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2836,7 +2860,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2836 \\ a += a;2860 \\ a += a;
2837 \\}2861 \\}
2838 ,2862 ,
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",
2840 );2864 );
28412865
2842 cases.add(2866 cases.add(
...@@ -2846,7 +2870,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2846,7 +2870,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2846 \\ _ = a +% a;2870 \\ _ = a +% a;
2847 \\}2871 \\}
2848 ,2872 ,
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",
2850 );2874 );
28512875
2852 cases.add(2876 cases.add(
...@@ -2856,7 +2880,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2856,7 +2880,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2856 \\ a +%= a;2880 \\ a +%= a;
2857 \\}2881 \\}
2858 ,2882 ,
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",
2860 );2884 );
28612885
2862 cases.add(2886 cases.add(
...@@ -2866,7 +2890,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2866,7 +2890,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2866 \\ _ = a - a;2890 \\ _ = a - a;
2867 \\}2891 \\}
2868 ,2892 ,
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",
2870 );2894 );
28712895
2872 cases.add(2896 cases.add(
...@@ -2876,7 +2900,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2876,7 +2900,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2876 \\ a -= a;2900 \\ a -= a;
2877 \\}2901 \\}
2878 ,2902 ,
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",
2880 );2904 );
28812905
2882 cases.add(2906 cases.add(
...@@ -2886,7 +2910,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2886,7 +2910,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2886 \\ _ = a -% a;2910 \\ _ = a -% a;
2887 \\}2911 \\}
2888 ,2912 ,
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",
2890 );2914 );
28912915
2892 cases.add(2916 cases.add(
...@@ -2896,7 +2920,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2896,7 +2920,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2896 \\ a -%= a;2920 \\ a -%= a;
2897 \\}2921 \\}
2898 ,2922 ,
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",
2900 );2924 );
29012925
2902 cases.add(2926 cases.add(
...@@ -2906,7 +2930,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2906,7 +2930,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2906 \\ _ = a * a;2930 \\ _ = a * a;
2907 \\}2931 \\}
2908 ,2932 ,
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",
2910 );2934 );
29112935
2912 cases.add(2936 cases.add(
...@@ -2916,7 +2940,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2916,7 +2940,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2916 \\ a *= a;2940 \\ a *= a;
2917 \\}2941 \\}
2918 ,2942 ,
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",
2920 );2944 );
29212945
2922 cases.add(2946 cases.add(
...@@ -2926,7 +2950,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2926,7 +2950,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2926 \\ _ = a *% a;2950 \\ _ = a *% a;
2927 \\}2951 \\}
2928 ,2952 ,
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",
2930 );2954 );
29312955
2932 cases.add(2956 cases.add(
...@@ -2936,7 +2960,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2936,7 +2960,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2936 \\ a *%= a;2960 \\ a *%= a;
2937 \\}2961 \\}
2938 ,2962 ,
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",
2940 );2964 );
29412965
2942 cases.add(2966 cases.add(
...@@ -2946,7 +2970,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2946,7 +2970,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2946 \\ _ = a << 2;2970 \\ _ = a << 2;
2947 \\}2971 \\}
2948 ,2972 ,
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",
2950 );2974 );
29512975
2952 cases.add(2976 cases.add(
...@@ -2956,7 +2980,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2956,7 +2980,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2956 \\ a <<= 2;2980 \\ a <<= 2;
2957 \\}2981 \\}
2958 ,2982 ,
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",
2960 );2984 );
29612985
2962 cases.add(2986 cases.add(
...@@ -2966,7 +2990,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2966,7 +2990,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2966 \\ _ = a >> 2;2990 \\ _ = a >> 2;
2967 \\}2991 \\}
2968 ,2992 ,
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",
2970 );2994 );
29712995
2972 cases.add(2996 cases.add(
...@@ -2976,7 +3000,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2976,7 +3000,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2976 \\ a >>= 2;3000 \\ a >>= 2;
2977 \\}3001 \\}
2978 ,3002 ,
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",
2980 );3004 );
29813005
2982 cases.add(3006 cases.add(
...@@ -2986,7 +3010,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2986,7 +3010,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2986 \\ _ = a & a;3010 \\ _ = a & a;
2987 \\}3011 \\}
2988 ,3012 ,
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",
2990 );3014 );
29913015
2992 cases.add(3016 cases.add(
...@@ -2996,7 +3020,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2996,7 +3020,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2996 \\ a &= a;3020 \\ a &= a;
2997 \\}3021 \\}
2998 ,3022 ,
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",
3000 );3024 );
30013025
3002 cases.add(3026 cases.add(
...@@ -3006,7 +3030,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3006,7 +3030,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3006 \\ _ = a | a;3030 \\ _ = a | a;
3007 \\}3031 \\}
3008 ,3032 ,
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",
3010 );3034 );
30113035
3012 cases.add(3036 cases.add(
...@@ -3016,7 +3040,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3016,7 +3040,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3016 \\ a |= a;3040 \\ a |= a;
3017 \\}3041 \\}
3018 ,3042 ,
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",
3020 );3044 );
30213045
3022 cases.add(3046 cases.add(
...@@ -3026,7 +3050,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3026,7 +3050,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3026 \\ _ = a ^ a;3050 \\ _ = a ^ a;
3027 \\}3051 \\}
3028 ,3052 ,
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",
3030 );3054 );
30313055
3032 cases.add(3056 cases.add(
...@@ -3036,7 +3060,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3036,7 +3060,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3036 \\ a ^= a;3060 \\ a ^= a;
3037 \\}3061 \\}
3038 ,3062 ,
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",
3040 );3064 );
30413065
3042 cases.add(3066 cases.add(
...@@ -3046,7 +3070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3046,7 +3070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3046 \\ _ = a == a;3070 \\ _ = a == a;
3047 \\}3071 \\}
3048 ,3072 ,
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",
3050 );3074 );
30513075
3052 cases.add(3076 cases.add(
...@@ -3056,7 +3080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3056,7 +3080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3056 \\ _ = a != a;3080 \\ _ = a != a;
3057 \\}3081 \\}
3058 ,3082 ,
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",
3060 );3084 );
30613085
3062 cases.add(3086 cases.add(
...@@ -3066,7 +3090,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3066,7 +3090,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3066 \\ _ = a > a;3090 \\ _ = a > a;
3067 \\}3091 \\}
3068 ,3092 ,
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",
3070 );3094 );
30713095
3072 cases.add(3096 cases.add(
...@@ -3076,7 +3100,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3076,7 +3100,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3076 \\ _ = a >= a;3100 \\ _ = a >= a;
3077 \\}3101 \\}
3078 ,3102 ,
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",
3080 );3104 );
30813105
3082 cases.add(3106 cases.add(
...@@ -3086,7 +3110,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3086,7 +3110,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3086 \\ _ = a < a;3110 \\ _ = a < a;
3087 \\}3111 \\}
3088 ,3112 ,
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",
3090 );3114 );
30913115
3092 cases.add(3116 cases.add(
...@@ -3096,7 +3120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3096,7 +3120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3096 \\ _ = a <= a;3120 \\ _ = a <= a;
3097 \\}3121 \\}
3098 ,3122 ,
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",
3100 );3124 );
31013125
3102 cases.add(3126 cases.add(
...@@ -3106,7 +3130,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3106,7 +3130,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3106 \\ _ = a and a;3130 \\ _ = a and a;
3107 \\}3131 \\}
3108 ,3132 ,
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",
3110 );3134 );
31113135
3112 cases.add(3136 cases.add(
...@@ -3116,7 +3140,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3116,7 +3140,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3116 \\ _ = a or a;3140 \\ _ = a or a;
3117 \\}3141 \\}
3118 ,3142 ,
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",
3120 );3144 );
31213145
3122 cases.add(3146 cases.add(
...@@ -3126,7 +3150,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3126,7 +3150,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3126 \\ _ = -a;3150 \\ _ = -a;
3127 \\}3151 \\}
3128 ,3152 ,
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",
3130 );3154 );
31313155
3132 cases.add(3156 cases.add(
...@@ -3136,7 +3160,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3136,7 +3160,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3136 \\ _ = -%a;3160 \\ _ = -%a;
3137 \\}3161 \\}
3138 ,3162 ,
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",
3140 );3164 );
31413165
3142 cases.add(3166 cases.add(
...@@ -3146,7 +3170,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3146,7 +3170,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3146 \\ _ = ~a;3170 \\ _ = ~a;
3147 \\}3171 \\}
3148 ,3172 ,
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",
3150 );3174 );
31513175
3152 cases.add(3176 cases.add(
...@@ -3156,7 +3180,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3156,7 +3180,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3156 \\ _ = !a;3180 \\ _ = !a;
3157 \\}3181 \\}
3158 ,3182 ,
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",
3160 );3184 );
31613185
3162 cases.add(3186 cases.add(
...@@ -3166,7 +3190,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3166,7 +3190,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3166 \\ _ = a orelse false;3190 \\ _ = a orelse false;
3167 \\}3191 \\}
3168 ,3192 ,
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",
3170 );3194 );
31713195
3172 cases.add(3196 cases.add(
...@@ -3176,7 +3200,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3176,7 +3200,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3176 \\ _ = a catch |err| false;3200 \\ _ = a catch |err| false;
3177 \\}3201 \\}
3178 ,3202 ,
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",
3180 );3204 );
31813205
3182 cases.add(3206 cases.add(