aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-09-05 18:02:13 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-09-05 18:02:13 -0400
commitcc17b662e48e43d134549ae5e986abe2e7db2822 (patch)
tree64c287ecaa26f47b05f06fee0b234c9c18ab0eb9 /src/ir.cpp
parentffb3b1576b1c02942bce89ef05eaf05fe2f026ac (diff)
parentb517bea734c0141fcda6b267a8f0de34cddc65f8 (diff)
downloadzig-cc17b662e48e43d134549ae5e986abe2e7db2822.tar.gz
zig-cc17b662e48e43d134549ae5e986abe2e7db2822.zip
Merge branch 'hcff-floatToIntError'
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 3184561ebc..8c44363bbe 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -18497,6 +18497,20 @@ static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrIns
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
+ if (target->value.type->id == TypeTableEntryIdComptimeInt) {
+ IrInstruction *casted_value = ir_implicit_cast(ira, target, dest_type);
+ if (type_is_invalid(casted_value->value.type))
+ return ira->codegen->builtin_types.entry_invalid;
+ ir_link_new_instruction(casted_value, &instruction->base);
+ return casted_value->value.type;
+ }
+
+ if (target->value.type->id != TypeTableEntryIdFloat && target->value.type->id != TypeTableEntryIdComptimeFloat) {
+ ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
+ buf_ptr(&target->value.type->name)));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
+
IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false);
ir_link_new_instruction(result, &instruction->base);
return dest_type;