aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-05-10 00:21:27 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-05-10 00:21:27 -0400
commit63f6676fee83883736af794eaddb4d0ccb890c06 (patch)
treef01f8a01902267451d7c8e57de75157e475f1141 /src
parent623741171629055a22a35bb8278d81a81dcffbde (diff)
downloadzig-63f6676fee83883736af794eaddb4d0ccb890c06.tar.gz
zig-63f6676fee83883736af794eaddb4d0ccb890c06.zip
add compile error for casting negative value to...
...unsigned integer at compile-time
Diffstat (limited to 'src')
-rw-r--r--src/ir.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 61e296c360..6a63597ed8 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -7053,6 +7053,13 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
if (!val)
return ira->codegen->invalid_instruction;
+ if (val->data.x_bignum.is_negative && wanted_type->id == TypeTableEntryIdInt &&
+ !wanted_type->data.integral.is_signed)
+ {
+ ir_add_error(ira, source_instr,
+ buf_sprintf("attempt to cast negative value to unsigned integer"));
+ return ira->codegen->invalid_instruction;
+ }
IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
source_instr->source_node, wanted_type);
result->value = *val;