diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-08-26 13:13:26 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-08-26 13:13:26 -0400 |
| commit | 68e2794e1543f91ab8f984127018820897cc0521 (patch) | |
| tree | 394cd1a64b5900ce6dacb44839524e1e56ceeda7 /src/ir.cpp | |
| parent | 6a3fad1d596a59846d072a005f77f6c59da09824 (diff) | |
| download | zig-68e2794e1543f91ab8f984127018820897cc0521.tar.gz zig-68e2794e1543f91ab8f984127018820897cc0521.zip | |
ir: const_ptr_pointee asserts that its return value is non-null
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 5bf39ee691..ae69f9c817 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -155,18 +155,22 @@ static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) { assert(get_codegen_ptr_type(const_val->type) != nullptr); assert(const_val->special == ConstValSpecialStatic); + ConstExprValue *result; switch (const_val->data.x_ptr.special) { case ConstPtrSpecialInvalid: zig_unreachable(); case ConstPtrSpecialRef: - return const_val->data.x_ptr.data.ref.pointee; + result = const_val->data.x_ptr.data.ref.pointee; + break; case ConstPtrSpecialBaseArray: expand_undef_array(g, const_val->data.x_ptr.data.base_array.array_val); - return &const_val->data.x_ptr.data.base_array.array_val->data.x_array.s_none.elements[ + result = &const_val->data.x_ptr.data.base_array.array_val->data.x_array.s_none.elements[ const_val->data.x_ptr.data.base_array.elem_index]; + break; case ConstPtrSpecialBaseStruct: - return &const_val->data.x_ptr.data.base_struct.struct_val->data.x_struct.fields[ + result = &const_val->data.x_ptr.data.base_struct.struct_val->data.x_struct.fields[ const_val->data.x_ptr.data.base_struct.field_index]; + break; case ConstPtrSpecialHardCodedAddr: zig_unreachable(); case ConstPtrSpecialDiscard: @@ -174,7 +178,8 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) { case ConstPtrSpecialFunction: zig_unreachable(); } - zig_unreachable(); + assert(result != nullptr); + return result; } static bool ir_should_inline(IrExecutable *exec, Scope *scope) { |
