authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-04-24 15:04:58+02:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-04-24 15:04:58+02:00
log1a2e02e267216bb35937d25598c773255d830b25
treee48d37cb4f083692dffb89b57ec75795d374991b
parent3bc361178c0f37ee9ffb67698401027a9f656664

fixed #2356

const_ptr_pointee_unchecked did not take into account that if the pointer is zero sized, then const_val->data.x_ptr.special would be ConstPtrSpecialInvalid. This commit fixes this by also checking that the child type of the pointer only have one possible value and just returns that value.

3 files changed, 20 insertions(+), 0 deletions(-)

src/ir.cpp+13
......@@ -188,6 +188,19 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
188188 assert(get_src_ptr_type(const_val->type) != nullptr);
189189 assert(const_val->special == ConstValSpecialStatic);
190190 ConstExprValue *result;
191
192 switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {
193 case OnePossibleValueInvalid:
194 zig_unreachable();
195 case OnePossibleValueYes:
196 result = create_const_vals(1);
197 result->type = const_val->type->data.pointer.child_type;
198 result->special = ConstValSpecialStatic;
199 return result;
200 case OnePossibleValueNo:
201 break;
202 }
203
191204 switch (const_val->data.x_ptr.special) {
192205 case ConstPtrSpecialInvalid:
193206 zig_unreachable();
test/stage1/behavior.zig+1
......@@ -24,6 +24,7 @@ comptime {
2424 _ = @import("behavior/bugs/1851.zig");
2525 _ = @import("behavior/bugs/1914.zig");
2626 _ = @import("behavior/bugs/2006.zig");
27 _ = @import("behavior/bugs/2346.zig");
2728 _ = @import("behavior/bugs/394.zig");
2829 _ = @import("behavior/bugs/421.zig");
2930 _ = @import("behavior/bugs/529.zig");
test/stage1/behavior/bugs/2346.zig created+6
......@@ -0,0 +1,6 @@
1test "" {
2 const a: *void = undefined;
3 const b: *[1]void = a;
4 const c: *[0]u8 = undefined;
5 const d: []u8 = c;
6}
\ No newline at end of file