authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-08 14:57:16-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-08 14:57:16-04:00
log39fa313ad881d242c4fbb6789bab26fed72449a2
tree148a63c25c7933f1978f167d682060925239b23c
parentbf3d1c1aab336c4a650bb67dcaca132d4a0f6164

disable some implicit casts for unknown length pointers

closes #770

1 files changed, 12 insertions(+), 2 deletions(-)

src/ir.cpp+12-2
...@@ -7994,6 +7994,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -7994,6 +7994,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
7994 // implicit &const [N]T to []const T7994 // implicit &const [N]T to []const T
7995 if (is_slice(expected_type) &&7995 if (is_slice(expected_type) &&
7996 actual_type->id == TypeTableEntryIdPointer &&7996 actual_type->id == TypeTableEntryIdPointer &&
7997 actual_type->data.pointer.ptr_len == PtrLenSingle &&
7997 actual_type->data.pointer.is_const &&7998 actual_type->data.pointer.is_const &&
7998 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)7999 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)
7999 {8000 {
...@@ -8012,6 +8013,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -8012,6 +8013,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
8012 // implicit [N]T to &const []const T8013 // implicit [N]T to &const []const T
8013 if (expected_type->id == TypeTableEntryIdPointer &&8014 if (expected_type->id == TypeTableEntryIdPointer &&
8014 expected_type->data.pointer.is_const &&8015 expected_type->data.pointer.is_const &&
8016 expected_type->data.pointer.ptr_len == PtrLenSingle &&
8015 is_slice(expected_type->data.pointer.child_type) &&8017 is_slice(expected_type->data.pointer.child_type) &&
8016 actual_type->id == TypeTableEntryIdArray)8018 actual_type->id == TypeTableEntryIdArray)
8017 {8019 {
...@@ -8074,6 +8076,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -8074,6 +8076,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
8074 actual_type->id == TypeTableEntryIdComptimeInt)8076 actual_type->id == TypeTableEntryIdComptimeInt)
8075 {8077 {
8076 if (expected_type->id == TypeTableEntryIdPointer &&8078 if (expected_type->id == TypeTableEntryIdPointer &&
8079 expected_type->data.pointer.ptr_len == PtrLenSingle &&
8077 expected_type->data.pointer.is_const)8080 expected_type->data.pointer.is_const)
8078 {8081 {
8079 if (ir_num_lit_fits_in_other_type(ira, value, expected_type->data.pointer.child_type, false)) {8082 if (ir_num_lit_fits_in_other_type(ira, value, expected_type->data.pointer.child_type, false)) {
...@@ -8121,7 +8124,10 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -8121,7 +8124,10 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
8121 }8124 }
81228125
8123 // implicit enum to &const union which has the enum as the tag type8126 // implicit enum to &const union which has the enum as the tag type
8124 if (actual_type->id == TypeTableEntryIdEnum && expected_type->id == TypeTableEntryIdPointer) {8127 if (actual_type->id == TypeTableEntryIdEnum &&
8128 expected_type->id == TypeTableEntryIdPointer &&
8129 expected_type->data.pointer.ptr_len == PtrLenSingle)
8130 {
8125 TypeTableEntry *union_type = expected_type->data.pointer.child_type;8131 TypeTableEntry *union_type = expected_type->data.pointer.child_type;
8126 if (union_type->data.unionation.decl_node->data.container_decl.auto_enum ||8132 if (union_type->data.unionation.decl_node->data.container_decl.auto_enum ||
8127 union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)8133 union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)
...@@ -8141,7 +8147,11 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -8141,7 +8147,11 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
8141 // implicitly take a const pointer to something8147 // implicitly take a const pointer to something
8142 if (!type_requires_comptime(actual_type)) {8148 if (!type_requires_comptime(actual_type)) {
8143 TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);8149 TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);
8144 if (types_match_const_cast_only(ira, expected_type, const_ptr_actual, source_node).id == ConstCastResultIdOk) {8150 if (expected_type->id == TypeTableEntryIdPointer &&
8151 expected_type->data.pointer.ptr_len == PtrLenSingle &&
8152 types_match_const_cast_only(ira, expected_type, const_ptr_actual,
8153 source_node).id == ConstCastResultIdOk)
8154 {
8145 return ImplicitCastMatchResultYes;8155 return ImplicitCastMatchResultYes;
8146 }8156 }
8147 }8157 }