From 8021848b5b6f25f6c10244c1c719632f48a2a45a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 29 Apr 2022 20:52:57 +0900 Subject: [PATCH] [qfcc] Support promotions for struct initializers This allows the various vector types to be used to initialized structures and arrays. --- tools/qfcc/source/def.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/qfcc/source/def.c b/tools/qfcc/source/def.c index 9d9f04d84..8e009cb85 100644 --- a/tools/qfcc/source/def.c +++ b/tools/qfcc/source/def.c @@ -380,10 +380,17 @@ init_elements (struct def_s *def, expr_t *eles) reloc_def_op (c->e.labelref.label, &dummy); continue; } else if (c->type == ex_value) { - if (is_float (element->type) - && (is_int (get_type (c)) - || (is_double (get_type (c)) && c->implicit))) { - expr_t *n = cast_expr (&type_float, c); + type_t *ctype = get_type (c); + if (ctype != element->type + && type_assignable (element->type, ctype)) { + if (!c->implicit + && !type_promotes (element->type, ctype)) { + warning (c, "initialization of %s with %s" + " (use a cast)\n)", + get_type_string (element->type), + get_type_string (ctype)); + } + expr_t *n = cast_expr (element->type, c); n->line = c->line; n->file = c->line; c = n;