aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index d5152f3c85..dc700c4178 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -20580,10 +20580,10 @@ static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruct
if (type_is_invalid(src_type))
return ira->codegen->invalid_instruction;
- if ((err = ensure_complete_type(ira->codegen, dest_type)))
+ if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusSizeKnown)))
return ira->codegen->invalid_instruction;
- if ((err = ensure_complete_type(ira->codegen, src_type)))
+ if ((err = type_resolve(ira->codegen, src_type, ResolveStatusSizeKnown)))
return ira->codegen->invalid_instruction;
if (get_codegen_ptr_type(src_type) != nullptr) {
@@ -20646,6 +20646,16 @@ static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruct
return ira->codegen->invalid_instruction;
}
+ uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type);
+ uint64_t src_size_bits = type_size_bits(ira->codegen, src_type);
+ if (dest_size_bits != src_size_bits) {
+ ir_add_error(ira, &instruction->base,
+ buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits",
+ buf_ptr(&dest_type->name), dest_size_bits,
+ buf_ptr(&src_type->name), src_size_bits));
+ return ira->codegen->invalid_instruction;
+ }
+
if (instr_is_comptime(value)) {
ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
if (!val)