authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-26 13:13:26-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-26 13:13:26-04:00
log68e2794e1543f91ab8f984127018820897cc0521
tree394cd1a64b5900ce6dacb44839524e1e56ceeda7
parent6a3fad1d596a59846d072a005f77f6c59da09824

ir: const_ptr_pointee asserts that its return value is non-null


1 files changed, 9 insertions(+), 4 deletions(-)

src/ir.cpp+9-4
......@@ -155,18 +155,22 @@ static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type
155155ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
156156 assert(get_codegen_ptr_type(const_val->type) != nullptr);
157157 assert(const_val->special == ConstValSpecialStatic);
158 ConstExprValue *result;
158159 switch (const_val->data.x_ptr.special) {
159160 case ConstPtrSpecialInvalid:
160161 zig_unreachable();
161162 case ConstPtrSpecialRef:
162 return const_val->data.x_ptr.data.ref.pointee;
163 result = const_val->data.x_ptr.data.ref.pointee;
164 break;
163165 case ConstPtrSpecialBaseArray:
164166 expand_undef_array(g, const_val->data.x_ptr.data.base_array.array_val);
165 return &const_val->data.x_ptr.data.base_array.array_val->data.x_array.s_none.elements[
167 result = &const_val->data.x_ptr.data.base_array.array_val->data.x_array.s_none.elements[
166168 const_val->data.x_ptr.data.base_array.elem_index];
169 break;
167170 case ConstPtrSpecialBaseStruct:
168 return &const_val->data.x_ptr.data.base_struct.struct_val->data.x_struct.fields[
171 result = &const_val->data.x_ptr.data.base_struct.struct_val->data.x_struct.fields[
169172 const_val->data.x_ptr.data.base_struct.field_index];
173 break;
170174 case ConstPtrSpecialHardCodedAddr:
171175 zig_unreachable();
172176 case ConstPtrSpecialDiscard:
......@@ -174,7 +178,8 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
174178 case ConstPtrSpecialFunction:
175179 zig_unreachable();
176180 }
177 zig_unreachable();
181 assert(result != nullptr);
182 return result;
178183}
179184
180185static bool ir_should_inline(IrExecutable *exec, Scope *scope) {