aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-04-30 12:21:24 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-04-30 12:21:24 -0400
commit43e7ac8418172e16def3ed8abf12e303738d7569 (patch)
tree6b86526c71d127b09b44d010681e07ba1d64e367 /src/ir.cpp
parent29defd705dcaf25d4a080f7db8f76e8787fca146 (diff)
downloadzig-43e7ac8418172e16def3ed8abf12e303738d7569.tar.gz
zig-43e7ac8418172e16def3ed8abf12e303738d7569.zip
add peer type resolution `[]T` and `[0]T`
closes #349 also fix slicing const array to be []const T instead of []T
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 6c072a7b90..0ad643a4af 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -6218,16 +6218,18 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
convert_to_const_slice = true;
continue;
} else if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) &&
- prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const &&
- types_match_const_cast_only(prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
- cur_type->data.array.child_type))
+ (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
+ cur_type->data.array.len == 0) &&
+ types_match_const_cast_only(prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
+ cur_type->data.array.child_type))
{
convert_to_const_slice = false;
continue;
} else if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) &&
- cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const &&
- types_match_const_cast_only(cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
- prev_type->data.array.child_type))
+ (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
+ prev_type->data.array.len == 0) &&
+ types_match_const_cast_only(cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
+ prev_type->data.array.child_type))
{
prev_inst = cur_inst;
convert_to_const_slice = false;
@@ -6796,8 +6798,9 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
if (!val)
return ira->codegen->invalid_instruction;
+ bool final_is_const = (value->value.type->id == TypeTableEntryIdMetaType) ? is_const : true;
return ir_get_const_ptr(ira, source_instruction, val, value->value.type,
- ConstPtrMutComptimeConst, is_const, is_volatile);
+ ConstPtrMutComptimeConst, final_is_const, is_volatile);
}
TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, is_const, is_volatile, 0, 0);
@@ -6806,6 +6809,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope,
source_instruction->source_node, value, is_const, is_volatile);
new_instruction->value.type = ptr_type;
+ new_instruction->value.data.rh_ptr = RuntimeHintPtrStack;
fn_entry->alloca_list.append(new_instruction);
return new_instruction;
}