[qfcc] Ensure multi-vector objects have the correct type

Failing to promote ints to the algebra type results in a segfault in
assignment of a multi-vector due to the symbol pointer walking off the
end of the list of symbols.
This commit is contained in:
Bill Currie 2023-09-04 11:06:28 +09:00
parent 2b5b55f416
commit 8dd0410968

View file

@ -189,11 +189,29 @@ check_types (expr_t **e, algebra_t *algebra)
return true;
}
static expr_t *
promote_scalar (type_t *dst_type, expr_t *scalar)
{
auto scalar_type = get_type (scalar);
if (scalar_type != dst_type) {
if (!type_promotes (dst_type, scalar_type)) {
warning (scalar, "demoting %s to %s (use a cast)",
get_type_string (scalar_type),
get_type_string (dst_type));
}
scalar = cast_expr (dst_type, scalar);
}
return scalar;
}
static expr_t *
mvec_expr (expr_t *expr, algebra_t *algebra)
{
auto mvtype = get_type (expr);
if (expr->type == ex_multivec || is_scalar (mvtype)) {
if (!is_algebra (mvtype)) {
expr = promote_scalar (algebra->type, expr);
}
return expr;
}
if (!is_algebra (mvtype)) {
@ -303,21 +321,6 @@ mvec_gather (expr_t **components, algebra_t *algebra)
return mvec;
}
static expr_t *
promote_scalar (type_t *dst_type, expr_t *scalar)
{
auto scalar_type = get_type (scalar);
if (scalar_type != dst_type) {
if (!type_promotes (dst_type, scalar_type)) {
warning (scalar, "demoting %s to %s (use a cast)",
get_type_string (scalar_type),
get_type_string (dst_type));
}
scalar = cast_expr (dst_type, scalar);
}
return scalar;
}
static bool __attribute__((const))
ext_compat (const expr_t *a, const expr_t *b)
{