| author | |
| committer | |
| log | 1a2e02e267216bb35937d25598c773255d830b25 |
| tree | e48d37cb4f083692dffb89b57ec75795d374991b |
| parent | 3bc361178c0f37ee9ffb67698401027a9f656664 |
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 | ... | @@ -188,6 +188,19 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c |
| 188 | assert(get_src_ptr_type(const_val->type) != nullptr); | 188 | assert(get_src_ptr_type(const_val->type) != nullptr); |
| 189 | assert(const_val->special == ConstValSpecialStatic); | 189 | assert(const_val->special == ConstValSpecialStatic); |
| 190 | ConstExprValue *result; | 190 | 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 | |||
| 191 | switch (const_val->data.x_ptr.special) { | 204 | switch (const_val->data.x_ptr.special) { |
| 192 | case ConstPtrSpecialInvalid: | 205 | case ConstPtrSpecialInvalid: |
| 193 | zig_unreachable(); | 206 | zig_unreachable(); |
test/stage1/behavior.zig+1| ... | @@ -24,6 +24,7 @@ comptime { | ... | @@ -24,6 +24,7 @@ comptime { |
| 24 | _ = @import("behavior/bugs/1851.zig"); | 24 | _ = @import("behavior/bugs/1851.zig"); |
| 25 | _ = @import("behavior/bugs/1914.zig"); | 25 | _ = @import("behavior/bugs/1914.zig"); |
| 26 | _ = @import("behavior/bugs/2006.zig"); | 26 | _ = @import("behavior/bugs/2006.zig"); |
| 27 | _ = @import("behavior/bugs/2346.zig"); | ||
| 27 | _ = @import("behavior/bugs/394.zig"); | 28 | _ = @import("behavior/bugs/394.zig"); |
| 28 | _ = @import("behavior/bugs/421.zig"); | 29 | _ = @import("behavior/bugs/421.zig"); |
| 29 | _ = @import("behavior/bugs/529.zig"); | 30 | _ = @import("behavior/bugs/529.zig"); |
test/stage1/behavior/bugs/2346.zig created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | test "" { | ||
| 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 | |||