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...@@ -155,18 +155,22 @@ static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type
155ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {155ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
156 assert(get_codegen_ptr_type(const_val->type) != nullptr);156 assert(get_codegen_ptr_type(const_val->type) != nullptr);
157 assert(const_val->special == ConstValSpecialStatic);157 assert(const_val->special == ConstValSpecialStatic);
158 ConstExprValue *result;
158 switch (const_val->data.x_ptr.special) {159 switch (const_val->data.x_ptr.special) {
159 case ConstPtrSpecialInvalid:160 case ConstPtrSpecialInvalid:
160 zig_unreachable();161 zig_unreachable();
161 case ConstPtrSpecialRef:162 case ConstPtrSpecialRef:
162 return const_val->data.x_ptr.data.ref.pointee;163 result = const_val->data.x_ptr.data.ref.pointee;
164 break;
163 case ConstPtrSpecialBaseArray:165 case ConstPtrSpecialBaseArray:
164 expand_undef_array(g, const_val->data.x_ptr.data.base_array.array_val);166 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[
166 const_val->data.x_ptr.data.base_array.elem_index];168 const_val->data.x_ptr.data.base_array.elem_index];
169 break;
167 case ConstPtrSpecialBaseStruct:170 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[
169 const_val->data.x_ptr.data.base_struct.field_index];172 const_val->data.x_ptr.data.base_struct.field_index];
173 break;
170 case ConstPtrSpecialHardCodedAddr:174 case ConstPtrSpecialHardCodedAddr:
171 zig_unreachable();175 zig_unreachable();
172 case ConstPtrSpecialDiscard:176 case ConstPtrSpecialDiscard:
...@@ -174,7 +178,8 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {...@@ -174,7 +178,8 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
174 case ConstPtrSpecialFunction:178 case ConstPtrSpecialFunction:
175 zig_unreachable();179 zig_unreachable();
176 }180 }
177 zig_unreachable();181 assert(result != nullptr);
182 return result;
178}183}
179184
180static bool ir_should_inline(IrExecutable *exec, Scope *scope) {185static bool ir_should_inline(IrExecutable *exec, Scope *scope) {