authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-31 02:30:10-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-31 02:30:10-05:00
logd8da34c64c0def6915cead3e16991ed97515ed71
tree010c2f67000a84b9061b5218ef4a95444d320c2e
parentd2b94afaf2383bbcb03ab201e544aa830c082e99

fix crash when assigning too large value to integer

closes #228

2 files changed, 11 insertions(+), 0 deletions(-)

src/ir.cpp+5
...@@ -7591,6 +7591,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -7591,6 +7591,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
7591 var->value.type = result_type;7591 var->value.type = result_type;
7592 assert(var->value.type);7592 assert(var->value.type);
75937593
7594 if (result_type->id == TypeTableEntryIdInvalid) {
7595 decl_var_instruction->base.other = &decl_var_instruction->base;
7596 return ira->codegen->builtin_types.entry_void;
7597 }
7598
7594 bool is_comptime = ir_get_var_is_comptime(var);7599 bool is_comptime = ir_get_var_is_comptime(var);
75957600
7596 if (casted_init_value->value.special != ConstValSpecialRuntime) {7601 if (casted_init_value->value.special != ConstValSpecialRuntime) {
test/run_tests.cpp+6
...@@ -1656,6 +1656,12 @@ fn bar() -> i32 {...@@ -1656,6 +1656,12 @@ fn bar() -> i32 {
1656}1656}
1657 )SOURCE", 1, ".tmp_source.zig:11:9: error: parameter of type '(integer literal)' requires comptime");1657 )SOURCE", 1, ".tmp_source.zig:11:9: error: parameter of type '(integer literal)' requires comptime");
16581658
1659 add_compile_fail_case("assign too big number to u16", R"SOURCE(
1660fn foo() {
1661 var vga_mem: u16 = 0xB8000;
1662}
1663 )SOURCE", 1, ".tmp_source.zig:3:24: error: integer value 753664 cannot be implicitly casted to type 'u16'");
1664
1659}1665}
16601666
1661//////////////////////////////////////////////////////////////////////////////1667//////////////////////////////////////////////////////////////////////////////