diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-11-25 16:34:08 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-11-25 16:34:08 -0500 |
| commit | 48ebb65cc7a976599c0a2b9e6647ea057727cf21 (patch) | |
| tree | f820426af0b9f2962e3522a7aecdd75d1f1d12fe /src/ir.cpp | |
| parent | b390929826062f81b9f796d4cf46a72aa23d291a (diff) | |
| download | zig-48ebb65cc7a976599c0a2b9e6647ea057727cf21.tar.gz zig-48ebb65cc7a976599c0a2b9e6647ea057727cf21.zip | |
add an assert to catch corrupted memory
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 35e6b3f8c6..a58374dc8c 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -10351,30 +10351,40 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, bool is_const = (var->value->type->id == TypeTableEntryIdMetaType) ? is_const_ptr : var->src_is_const; bool is_volatile = (var->value->type->id == TypeTableEntryIdMetaType) ? is_volatile_ptr : false; - if (mem_slot && mem_slot->special != ConstValSpecialRuntime) { - ConstPtrMut ptr_mut; - if (comptime_var_mem) { - ptr_mut = ConstPtrMutComptimeVar; - } else if (var->gen_is_const) { - ptr_mut = ConstPtrMutComptimeConst; - } else { - assert(!comptime_var_mem); - ptr_mut = ConstPtrMutRuntimeVar; + if (mem_slot != nullptr) { + switch (mem_slot->special) { + case ConstValSpecialRuntime: + goto no_mem_slot; + case ConstValSpecialStatic: // fallthrough + case ConstValSpecialUndef: { + ConstPtrMut ptr_mut; + if (comptime_var_mem) { + ptr_mut = ConstPtrMutComptimeVar; + } else if (var->gen_is_const) { + ptr_mut = ConstPtrMutComptimeConst; + } else { + assert(!comptime_var_mem); + ptr_mut = ConstPtrMutRuntimeVar; + } + return ir_get_const_ptr(ira, instruction, mem_slot, var->value->type, + ptr_mut, is_const, is_volatile, var->align_bytes); + } } - return ir_get_const_ptr(ira, instruction, mem_slot, var->value->type, - ptr_mut, is_const, is_volatile, var->align_bytes); - } else { - IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb, - instruction->scope, instruction->source_node, var, is_const, is_volatile); - var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type, - var->src_is_const, is_volatile, var->align_bytes, 0, 0); - type_ensure_zero_bits_known(ira->codegen, var->value->type); + zig_unreachable(); + } - bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); - var_ptr_instruction->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; +no_mem_slot: - return var_ptr_instruction; - } + IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb, + instruction->scope, instruction->source_node, var, is_const, is_volatile); + var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type, + var->src_is_const, is_volatile, var->align_bytes, 0, 0); + type_ensure_zero_bits_known(ira->codegen, var->value->type); + + bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); + var_ptr_instruction->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; + + return var_ptr_instruction; } static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction, |
