| ... | @@ -71,6 +71,7 @@ enum ConstCastResultId { | ... | @@ -71,6 +71,7 @@ enum ConstCastResultId { |
| 71 | ConstCastResultIdPtrLens, | 71 | ConstCastResultIdPtrLens, |
| 72 | ConstCastResultIdCV, | 72 | ConstCastResultIdCV, |
| 73 | ConstCastResultIdPtrSentinel, | 73 | ConstCastResultIdPtrSentinel, |
| | 74 | ConstCastResultIdIntShorten, |
| 74 | }; | 75 | }; |
| 75 | | 76 | |
| 76 | struct ConstCastOnly; | 77 | struct ConstCastOnly; |
| ... | @@ -97,6 +98,7 @@ struct ConstCastBadAllowsZero; | ... | @@ -97,6 +98,7 @@ struct ConstCastBadAllowsZero; |
| 97 | struct ConstCastBadNullTermArrays; | 98 | struct ConstCastBadNullTermArrays; |
| 98 | struct ConstCastBadCV; | 99 | struct ConstCastBadCV; |
| 99 | struct ConstCastPtrSentinel; | 100 | struct ConstCastPtrSentinel; |
| | 101 | struct ConstCastIntShorten; |
| 100 | | 102 | |
| 101 | struct ConstCastOnly { | 103 | struct ConstCastOnly { |
| 102 | ConstCastResultId id; | 104 | ConstCastResultId id; |
| ... | @@ -117,6 +119,7 @@ struct ConstCastOnly { | ... | @@ -117,6 +119,7 @@ struct ConstCastOnly { |
| 117 | ConstCastBadNullTermArrays *sentinel_arrays; | 119 | ConstCastBadNullTermArrays *sentinel_arrays; |
| 118 | ConstCastBadCV *bad_cv; | 120 | ConstCastBadCV *bad_cv; |
| 119 | ConstCastPtrSentinel *bad_ptr_sentinel; | 121 | ConstCastPtrSentinel *bad_ptr_sentinel; |
| | 122 | ConstCastIntShorten *int_shorten; |
| 120 | } data; | 123 | } data; |
| 121 | }; | 124 | }; |
| 122 | | 125 | |
| ... | @@ -186,6 +189,11 @@ struct ConstCastPtrSentinel { | ... | @@ -186,6 +189,11 @@ struct ConstCastPtrSentinel { |
| 186 | ZigType *actual_type; | 189 | ZigType *actual_type; |
| 187 | }; | 190 | }; |
| 188 | | 191 | |
| | 192 | struct ConstCastIntShorten { |
| | 193 | ZigType *wanted_type; |
| | 194 | ZigType *actual_type; |
| | 195 | }; |
| | 196 | |
| 189 | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); | 197 | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); |
| 190 | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval, | 198 | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval, |
| 191 | ResultLoc *result_loc); | 199 | ResultLoc *result_loc); |
| ... | @@ -10213,6 +10221,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted | ... | @@ -10213,6 +10221,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 10213 | return result; | 10221 | return result; |
| 10214 | } | 10222 | } |
| 10215 | | 10223 | |
| | 10224 | if (wanted_type->id == ZigTypeIdInt && actual_type->id == ZigTypeIdInt) { |
| | 10225 | result.id = ConstCastResultIdIntShorten; |
| | 10226 | result.data.int_shorten = allocate_nonzero<ConstCastIntShorten>(1); |
| | 10227 | result.data.int_shorten->wanted_type = wanted_type; |
| | 10228 | result.data.int_shorten->actual_type = actual_type; |
| | 10229 | return result; |
| | 10230 | } |
| | 10231 | |
| 10216 | result.id = ConstCastResultIdType; | 10232 | result.id = ConstCastResultIdType; |
| 10217 | result.data.type_mismatch = allocate_nonzero<ConstCastTypeMismatch>(1); | 10233 | result.data.type_mismatch = allocate_nonzero<ConstCastTypeMismatch>(1); |
| 10218 | result.data.type_mismatch->wanted_type = wanted_type; | 10234 | result.data.type_mismatch->wanted_type = wanted_type; |
| ... | @@ -12733,6 +12749,17 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa | ... | @@ -12733,6 +12749,17 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 12733 | add_error_note(ira->codegen, parent_msg, source_node, | 12749 | add_error_note(ira->codegen, parent_msg, source_node, |
| 12734 | buf_sprintf("calling convention mismatch")); | 12750 | buf_sprintf("calling convention mismatch")); |
| 12735 | break; | 12751 | break; |
| | 12752 | case ConstCastResultIdIntShorten: { |
| | 12753 | ZigType *wanted_type = cast_result->data.int_shorten->wanted_type; |
| | 12754 | ZigType *actual_type = cast_result->data.int_shorten->actual_type; |
| | 12755 | const char *wanted_signed = wanted_type->data.integral.is_signed ? "signed" : "unsigned"; |
| | 12756 | const char *actual_signed = wanted_type->data.integral.is_signed ? "signed" : "unsigned"; |
| | 12757 | add_error_note(ira->codegen, parent_msg, source_node, |
| | 12758 | buf_sprintf("%s %" PRIu32 "-bit int cannot represent all possible %s %" PRIu32 "-bit values", |
| | 12759 | wanted_signed, wanted_type->data.integral.bit_count, |
| | 12760 | actual_signed, actual_type->data.integral.bit_count)); |
| | 12761 | break; |
| | 12762 | } |
| 12736 | case ConstCastResultIdFnAlign: // TODO | 12763 | case ConstCastResultIdFnAlign: // TODO |
| 12737 | case ConstCastResultIdFnVarArgs: // TODO | 12764 | case ConstCastResultIdFnVarArgs: // TODO |
| 12738 | case ConstCastResultIdFnReturnType: // TODO | 12765 | case ConstCastResultIdFnReturnType: // TODO |