| ... | @@ -7053,12 +7053,20 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction | ... | @@ -7053,12 +7053,20 @@ 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 && | 7056 | if (wanted_type->id == TypeTableEntryIdInt) { |
| 7057 | !wanted_type->data.integral.is_signed) | 7057 | if (val->data.x_bignum.is_negative && !wanted_type->data.integral.is_signed) { |
| 7058 | { | 7058 | ir_add_error(ira, source_instr, |
| 7059 | ir_add_error(ira, source_instr, | 7059 | buf_sprintf("attempt to cast negative value to unsigned integer")); |
| 7060 | buf_sprintf("attempt to cast negative value to unsigned integer")); | 7060 | return ira->codegen->invalid_instruction; |
| 7061 | return ira->codegen->invalid_instruction; | 7061 | } |
| | 7062 | if (!bignum_fits_in_bits(&val->data.x_bignum, wanted_type->data.integral.bit_count, |
| | 7063 | wanted_type->data.integral.is_signed)) |
| | 7064 | { |
| | 7065 | ir_add_error(ira, source_instr, |
| | 7066 | buf_sprintf("cast from '%s' to '%s' truncates bits", |
| | 7067 | buf_ptr(&target->value.type->name), buf_ptr(&wanted_type->name))); |
| | 7068 | return ira->codegen->invalid_instruction; |
| | 7069 | } |
| 7062 | } | 7070 | } |
| 7063 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, | 7071 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 7064 | source_instr->source_node, wanted_type); | 7072 | source_instr->source_node, wanted_type); |