| ... | @@ -7053,6 +7053,13 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction | ... | @@ -7053,6 +7053,13 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 7053 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 7053 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 7054 | if (!val) | 7054 | if (!val) |
| 7055 | return ira->codegen->invalid_instruction; | 7055 | return ira->codegen->invalid_instruction; |
| | 7056 | if (val->data.x_bignum.is_negative && wanted_type->id == TypeTableEntryIdInt && |
| | 7057 | !wanted_type->data.integral.is_signed) |
| | 7058 | { |
| | 7059 | ir_add_error(ira, source_instr, |
| | 7060 | buf_sprintf("attempt to cast negative value to unsigned integer")); |
| | 7061 | return ira->codegen->invalid_instruction; |
| | 7062 | } |
| 7056 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, | 7063 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 7057 | source_instr->source_node, wanted_type); | 7064 | source_instr->source_node, wanted_type); |
| 7058 | result->value = *val; | 7065 | result->value = *val; |