diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-01-18 17:47:21 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-01-18 17:47:21 -0500 |
| commit | 4b64c777ee465abb1f4a6bf2d31ba39805d5fa54 (patch) | |
| tree | 2295fd5b511f1fe46b69905fa383c9389044572a /src/ir.cpp | |
| parent | 0fc645ab7084c1812d367583b37218359b21c02c (diff) | |
| download | zig-4b64c777ee465abb1f4a6bf2d31ba39805d5fa54.tar.gz zig-4b64c777ee465abb1f4a6bf2d31ba39805d5fa54.zip | |
add compile error for shifting by negative comptime integer
closes #698
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 4c107ce767..fae3b82481 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -8816,6 +8816,13 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * if (op_id == IrBinOpBitShiftLeftLossy) { op_id = IrBinOpBitShiftLeftExact; } + + if (casted_op2->value.data.x_bigint.is_negative) { + Buf *val_buf = buf_alloc(); + bigint_append_buf(val_buf, &casted_op2->value.data.x_bigint, 10); + ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf))); + return ira->codegen->builtin_types.entry_invalid; + } } else { TypeTableEntry *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, op1->value.type->data.integral.bit_count - 1); |
