From 8cef85e5de451c4e00c298c5e9d64f16fe248288 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 9 Jun 2019 20:12:50 +0900 Subject: [PATCH] Cast scalar types when necessary on assignment This fixes type promotion errors that broke some tests. --- tools/qfcc/source/expr_assign.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/qfcc/source/expr_assign.c b/tools/qfcc/source/expr_assign.c index 7cf1d8b4d..1662d6b10 100644 --- a/tools/qfcc/source/expr_assign.c +++ b/tools/qfcc/source/expr_assign.c @@ -142,7 +142,15 @@ check_types_compatible (expr_t *dst, expr_t *src) type_t *dst_type = get_type (dst); type_t *src_type = get_type (src); + if (dst_type == src_type) { + return 0; + } + if (type_assignable (dst_type, src_type)) { + if (is_scalar (dst_type) && is_scalar (src_type)) { + // the types are different but cast-compatible + return assign_expr (dst, cast_expr (dst_type, src)); + } return 0; } // traditional qcc is a little sloppy