authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-11-25 16:34:08-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-11-25 16:34:08-05:00
log48ebb65cc7a976599c0a2b9e6647ea057727cf21
treef820426af0b9f2962e3522a7aecdd75d1f1d12fe
parentb390929826062f81b9f796d4cf46a72aa23d291a

add an assert to catch corrupted memory


1 files changed, 31 insertions(+), 21 deletions(-)

src/ir.cpp+31-21
...@@ -10351,30 +10351,40 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -10351,30 +10351,40 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1035110351
10352 bool is_const = (var->value->type->id == TypeTableEntryIdMetaType) ? is_const_ptr : var->src_is_const;10352 bool is_const = (var->value->type->id == TypeTableEntryIdMetaType) ? is_const_ptr : var->src_is_const;
10353 bool is_volatile = (var->value->type->id == TypeTableEntryIdMetaType) ? is_volatile_ptr : false;10353 bool is_volatile = (var->value->type->id == TypeTableEntryIdMetaType) ? is_volatile_ptr : false;
10354 if (mem_slot && mem_slot->special != ConstValSpecialRuntime) {10354 if (mem_slot != nullptr) {
10355 ConstPtrMut ptr_mut;10355 switch (mem_slot->special) {
10356 if (comptime_var_mem) {10356 case ConstValSpecialRuntime:
10357 ptr_mut = ConstPtrMutComptimeVar;10357 goto no_mem_slot;
10358 } else if (var->gen_is_const) {10358 case ConstValSpecialStatic: // fallthrough
10359 ptr_mut = ConstPtrMutComptimeConst;10359 case ConstValSpecialUndef: {
10360 } else {10360 ConstPtrMut ptr_mut;
10361 assert(!comptime_var_mem);10361 if (comptime_var_mem) {
10362 ptr_mut = ConstPtrMutRuntimeVar;10362 ptr_mut = ConstPtrMutComptimeVar;
10363 } else if (var->gen_is_const) {
10364 ptr_mut = ConstPtrMutComptimeConst;
10365 } else {
10366 assert(!comptime_var_mem);
10367 ptr_mut = ConstPtrMutRuntimeVar;
10368 }
10369 return ir_get_const_ptr(ira, instruction, mem_slot, var->value->type,
10370 ptr_mut, is_const, is_volatile, var->align_bytes);
10371 }
10363 }10372 }
10364 return ir_get_const_ptr(ira, instruction, mem_slot, var->value->type,10373 zig_unreachable();
10365 ptr_mut, is_const, is_volatile, var->align_bytes);10374 }
10366 } else {
10367 IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb,
10368 instruction->scope, instruction->source_node, var, is_const, is_volatile);
10369 var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type,
10370 var->src_is_const, is_volatile, var->align_bytes, 0, 0);
10371 type_ensure_zero_bits_known(ira->codegen, var->value->type);
1037210375
10373 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);10376no_mem_slot:
10374 var_ptr_instruction->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack;
1037510377
10376 return var_ptr_instruction;10378 IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb,
10377 }10379 instruction->scope, instruction->source_node, var, is_const, is_volatile);
10380 var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type,
10381 var->src_is_const, is_volatile, var->align_bytes, 0, 0);
10382 type_ensure_zero_bits_known(ira->codegen, var->value->type);
10383
10384 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);
10385 var_ptr_instruction->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack;
10386
10387 return var_ptr_instruction;
10378}10388}
1037910389
10380static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction,10390static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction,