diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-01 14:06:51 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-02-01 14:06:51 -0500 |
| commit | ae1ebe09b7c1258bfa8de37244fd9b510b1447a4 (patch) | |
| tree | aa02aa86d4d916f55b7666f379df78c72fb13cea /src/ir.cpp | |
| parent | bbe857be96084bae6ca1e5f10e35f3631df50edc (diff) | |
| download | zig-ae1ebe09b7c1258bfa8de37244fd9b510b1447a4.tar.gz zig-ae1ebe09b7c1258bfa8de37244fd9b510b1447a4.zip | |
add compile errror for @bitCast when bit counts mismatch
fixes invalid LLVM IR from previous commit
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 14 |
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) |
