authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-09 10:43:29-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-09 10:44:06-04:00
log9eb51e20ed1a040a617541303db760f80ffd3aa1
treea85f682a1d27f889d1c106188c2e2406c1026f2a
parent42ba06133aec995feec3ea24ee7fbbc40d7ac2ca

fix crash on @ptrToInt of a *void

closes #1192

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

src/ir.cpp+6
...@@ -19796,6 +19796,12 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr...@@ -19796,6 +19796,12 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
19796 return ira->codegen->builtin_types.entry_invalid;19796 return ira->codegen->builtin_types.entry_invalid;
19797 }19797 }
1979819798
19799 if (!type_has_bits(target->value.type)) {
19800 ir_add_error(ira, target,
19801 buf_sprintf("pointer to size 0 type has no address"));
19802 return ira->codegen->builtin_types.entry_invalid;
19803 }
19804
19799 if (instr_is_comptime(target)) {19805 if (instr_is_comptime(target)) {
19800 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);19806 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
19801 if (!val)19807 if (!val)
test/compile_errors.zig+9
...@@ -1,6 +1,15 @@...@@ -1,6 +1,15 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "@ptrToInt on *void",
6 \\export fn entry() bool {
7 \\ return @ptrToInt(&{}) == @ptrToInt(&{});
8 \\}
9 ,
10 ".tmp_source.zig:2:23: error: pointer to size 0 type has no address",
11 );
12
4 cases.add(13 cases.add(
5 "@popCount - non-integer",14 "@popCount - non-integer",
6 \\export fn entry(x: f32) u32 {15 \\export fn entry(x: f32) u32 {