diff options
| author | Vexu <git@vexu.eu> | 2020-01-01 15:24:46 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-01-01 13:11:42 -0500 |
| commit | 1b64a5f5f0cece3cf0009410ddb13b5dd6f899e1 (patch) | |
| tree | af85941d89afe30f1a184b39f858ca12c12e1280 /src/ir.cpp | |
| parent | 0fb3e6608c160a0cd9db75fe1ba3d5bb7dac8fa8 (diff) | |
| download | zig-1b64a5f5f0cece3cf0009410ddb13b5dd6f899e1.tar.gz zig-1b64a5f5f0cece3cf0009410ddb13b5dd6f899e1.zip | |
fix segfault in bit shift safety check
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 7cc1829341..ddfed8229b 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -15621,11 +15621,15 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b op1->value->type->data.integral.bit_count - 1); if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy && op2->value->type->id == ZigTypeIdComptimeInt) { - if (!bigint_fits_in_bits(&op2->value->data.x_bigint, + + ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); + if (op2_val == nullptr) + return ira->codegen->invalid_instruction; + if (!bigint_fits_in_bits(&op2_val->data.x_bigint, shift_amt_type->data.integral.bit_count, - op2->value->data.x_bigint.is_negative)) { + op2_val->data.x_bigint.is_negative)) { Buf *val_buf = buf_alloc(); - bigint_append_buf(val_buf, &op2->value->data.x_bigint, 10); + bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10); ErrorMsg* msg = ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("RHS of shift is too large for LHS type")); |
