aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 2863335747..254e9f4d23 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -292,10 +292,16 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
if (actual_type->data.integral.is_signed && wanted_type->data.integral.is_signed) {
return LLVMBuildSExt(g->builder, expr_val, wanted_type->type_ref, "");
} else {
- zig_panic("TODO gen_cast_expr sign mismatch");
+ zig_panic("TODO gen_cast_expr widen unsigned");
}
} else {
- zig_panic("TODO gen_cast_expr");
+ assert(actual_type->size_in_bits > wanted_type->size_in_bits);
+
+ if (actual_type->data.integral.is_signed && wanted_type->data.integral.is_signed) {
+ return LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");
+ } else {
+ zig_panic("TODO gen_cast_expr shorten unsigned");
+ }
}
case CastOpArrayToString:
{