authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-10-25 12:52:12-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-10-25 12:52:12-04:00
logeb0b1d38ff91a144f0739dabbc24cb32776d8f2d
tree95ef442ed85ac113eba5182c5ce13c5e89a726ec
parent73ab0afaddb6fd71a800b11b3bf807c8ca37a9e8
signaturelock-open Commit is signed but in an unrecognized format.

remove 3 more implicit casts to const pointers

see #1465

2 files changed, 0 insertions(+), 67 deletions(-)

doc/langref.html.in-6
...@@ -4035,12 +4035,6 @@ test "float widening" {...@@ -4035,12 +4035,6 @@ test "float widening" {
4035 {#header_open|Implicit Cast: E to E!T#}4035 {#header_open|Implicit Cast: E to E!T#}
4036 <p>TODO</p>4036 <p>TODO</p>
4037 {#header_close#}4037 {#header_close#}
4038 {#header_open|Implicit Cast: comptime_int to *const integer#}
4039 <p>TODO</p>
4040 {#header_close#}
4041 {#header_open|Implicit Cast: comptime_float to *const float#}
4042 <p>TODO</p>
4043 {#header_close#}
4044 {#header_open|Implicit Cast: compile-time known numbers#}4038 {#header_open|Implicit Cast: compile-time known numbers#}
4045 <p>TODO</p>4039 <p>TODO</p>
4046 {#header_close#}4040 {#header_close#}
src/ir.cpp-61
...@@ -10483,31 +10483,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10483,31 +10483,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10483 }10483 }
10484 }10484 }
1048510485
10486 // cast from [N]T to *const []const T
10487 if (wanted_type->id == ZigTypeIdPointer &&
10488 wanted_type->data.pointer.is_const &&
10489 is_slice(wanted_type->data.pointer.child_type) &&
10490 actual_type->id == ZigTypeIdArray)
10491 {
10492 ZigType *ptr_type =
10493 wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;
10494 assert(ptr_type->id == ZigTypeIdPointer);
10495 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
10496 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
10497 source_node, false).id == ConstCastResultIdOk)
10498 {
10499 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);
10500 if (type_is_invalid(cast1->value.type))
10501 return ira->codegen->invalid_instruction;
10502
10503 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
10504 if (type_is_invalid(cast2->value.type))
10505 return ira->codegen->invalid_instruction;
10506
10507 return cast2;
10508 }
10509 }
10510
10511 // cast from [N]T to ?[]const T10486 // cast from [N]T to ?[]const T
10512 if (wanted_type->id == ZigTypeIdOptional &&10487 if (wanted_type->id == ZigTypeIdOptional &&
10513 is_slice(wanted_type->data.maybe.child_type) &&10488 is_slice(wanted_type->data.maybe.child_type) &&
...@@ -10705,7 +10680,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10705,7 +10680,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10705 }10680 }
1070610681
10707 // cast from number literal to another type10682 // cast from number literal to another type
10708 // cast from number literal to *const integer
10709 if (actual_type->id == ZigTypeIdComptimeFloat ||10683 if (actual_type->id == ZigTypeIdComptimeFloat ||
10710 actual_type->id == ZigTypeIdComptimeInt)10684 actual_type->id == ZigTypeIdComptimeInt)
10711 {10685 {
...@@ -10720,18 +10694,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10720,18 +10694,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10720 if (type_is_invalid(cast2->value.type))10694 if (type_is_invalid(cast2->value.type))
10721 return ira->codegen->invalid_instruction;10695 return ira->codegen->invalid_instruction;
1072210696
10723 return cast2;
10724 } else if (wanted_type->id == ZigTypeIdPointer &&
10725 wanted_type->data.pointer.is_const)
10726 {
10727 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);
10728 if (type_is_invalid(cast1->value.type))
10729 return ira->codegen->invalid_instruction;
10730
10731 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
10732 if (type_is_invalid(cast2->value.type))
10733 return ira->codegen->invalid_instruction;
10734
10735 return cast2;10697 return cast2;
10736 } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {10698 } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
10737 CastOp op;10699 CastOp op;
...@@ -10786,29 +10748,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10786,29 +10748,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10786 }10748 }
10787 }10749 }
1078810750
10789 // enum to *const union which has the enum as the tag type
10790 if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) {
10791 ZigType *union_type = wanted_type->data.pointer.child_type;
10792 if (union_type->data.unionation.decl_node->data.container_decl.auto_enum ||
10793 union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)
10794 {
10795 if ((err = type_resolve(ira->codegen, union_type, ResolveStatusZeroBitsKnown)))
10796 return ira->codegen->invalid_instruction;
10797
10798 if (union_type->data.unionation.tag_type == actual_type) {
10799 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, union_type, value);
10800 if (type_is_invalid(cast1->value.type))
10801 return ira->codegen->invalid_instruction;
10802
10803 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
10804 if (type_is_invalid(cast2->value.type))
10805 return ira->codegen->invalid_instruction;
10806
10807 return cast2;
10808 }
10809 }
10810 }
10811
10812 // cast from *T to *[1]T10751 // cast from *T to *[1]T
10813 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&10752 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
10814 actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)10753 actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)