Skip to content

Commit eb0b1d3

Browse files
committed
remove 3 more implicit casts to const pointers
see #1465
1 parent 73ab0af commit eb0b1d3

File tree

2 files changed

+0
-67
lines changed

2 files changed

+0
-67
lines changed

doc/langref.html.in

-6
Original file line numberDiff line numberDiff line change
@@ -4035,12 +4035,6 @@ test "float widening" {
40354035
{#header_open|Implicit Cast: E to E!T#}
40364036
<p>TODO</p>
40374037
{#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#}
40444038
{#header_open|Implicit Cast: compile-time known numbers#}
40454039
<p>TODO</p>
40464040
{#header_close#}

src/ir.cpp

-61
Original file line numberDiff line numberDiff line change
@@ -10483,31 +10483,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1048310483
}
1048410484
}
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-
1051110486
// cast from [N]T to ?[]const T
1051210487
if (wanted_type->id == ZigTypeIdOptional &&
1051310488
is_slice(wanted_type->data.maybe.child_type) &&
@@ -10705,7 +10680,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1070510680
}
1070610681

1070710682
// cast from number literal to another type
10708-
// cast from number literal to *const integer
1070910683
if (actual_type->id == ZigTypeIdComptimeFloat ||
1071010684
actual_type->id == ZigTypeIdComptimeInt)
1071110685
{
@@ -10720,18 +10694,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1072010694
if (type_is_invalid(cast2->value.type))
1072110695
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-
1073510697
return cast2;
1073610698
} else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
1073710699
CastOp op;
@@ -10786,29 +10748,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1078610748
}
1078710749
}
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-
1081210751
// cast from *T to *[1]T
1081310752
if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
1081410753
actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)

0 commit comments

Comments
 (0)