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.
This commit is contained in:
Jimmi HC 2019-04-24 15:04:58 +02:00
parent 3bc361178c
commit 1a2e02e267
3 changed files with 20 additions and 0 deletions

View File

@ -188,6 +188,19 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
assert(get_src_ptr_type(const_val->type) != nullptr);
assert(const_val->special == ConstValSpecialStatic);
ConstExprValue *result;
switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {
case OnePossibleValueInvalid:
zig_unreachable();
case OnePossibleValueYes:
result = create_const_vals(1);
result->type = const_val->type->data.pointer.child_type;
result->special = ConstValSpecialStatic;
return result;
case OnePossibleValueNo:
break;
}
switch (const_val->data.x_ptr.special) {
case ConstPtrSpecialInvalid:
zig_unreachable();

View File

@ -24,6 +24,7 @@ comptime {
_ = @import("behavior/bugs/1851.zig");
_ = @import("behavior/bugs/1914.zig");
_ = @import("behavior/bugs/2006.zig");
_ = @import("behavior/bugs/2346.zig");
_ = @import("behavior/bugs/394.zig");
_ = @import("behavior/bugs/421.zig");
_ = @import("behavior/bugs/529.zig");

View File

@ -0,0 +1,6 @@
test "" {
const a: *void = undefined;
const b: *[1]void = a;
const c: *[0]u8 = undefined;
const d: []u8 = c;
}