| author | |
| committer | |
| log | 2e0b114fdce1a10b8433438d8e2251cf708a72ec |
| tree | bde37363bf88c19995da326706fa0db191d523b2 |
| parent | 216e14891ea5fa1a88804d9781ef779d448d1220 |
See #3232 files changed, 14 insertions(+), 0 deletions(-)
src/ir.cpp+7| ... | ... | @@ -12473,6 +12473,13 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr |
| 12473 | 12473 | return ira->codegen->builtin_types.entry_invalid; |
| 12474 | 12474 | } |
| 12475 | 12475 | |
| 12476 | type_ensure_zero_bits_known(ira->codegen, dest_type); | |
| 12477 | if (!type_has_bits(dest_type)) { | |
| 12478 | ir_add_error(ira, dest_type_value, | |
| 12479 | buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name))); | |
| 12480 | return ira->codegen->builtin_types.entry_invalid; | |
| 12481 | } | |
| 12482 | ||
| 12476 | 12483 | IrInstruction *target = instruction->target->other; |
| 12477 | 12484 | if (type_is_invalid(target->value.type)) |
| 12478 | 12485 | return ira->codegen->builtin_types.entry_invalid; |
test/run_tests.cpp+7| ... | ... | @@ -1895,6 +1895,13 @@ export fn entry() { |
| 1895 | 1895 | const foo = Arch.x86; |
| 1896 | 1896 | } |
| 1897 | 1897 | )SOURCE", 1, ".tmp_source.zig:3:21: error: container 'Arch' has no member called 'x86'"); |
| 1898 | ||
| 1899 | add_compile_fail_case("int to ptr of 0 bits", R"SOURCE( | |
| 1900 | export fn foo() { | |
| 1901 | var x: usize = 0x1000; | |
| 1902 | var y: &void = @intToPtr(&void, x); | |
| 1903 | } | |
| 1904 | )SOURCE", 1, ".tmp_source.zig:4:31: error: type '&void' has 0 bits and cannot store information"); | |
| 1898 | 1905 | } |
| 1899 | 1906 | |
| 1900 | 1907 | ////////////////////////////////////////////////////////////////////////////// |