[qfcc] Preserve symbol expressions when constexpr

This prevents them from getting folded out of existence and thus
impossible to specialize.
This commit is contained in:
Bill Currie 2024-10-01 14:42:30 +09:00
parent 491b612888
commit 3af078628e
3 changed files with 6 additions and 7 deletions

View file

@ -69,6 +69,7 @@ typedef struct symbol_s {
struct param_s *params; ///< the parameters if a function
bool no_auto_init:1; ///< skip for non-designated initializers
bool lvalue:1;
bool is_constexpr:1;
struct attribute_s *attributes;
union {
int offset; ///< sy_offset

View file

@ -74,7 +74,7 @@ convert_name (const expr_t *e)
{
symbol_t *sym;
if (!e || e->type != ex_symbol)
if (!e || e->type != ex_symbol || e->symbol->is_constexpr)
return e;
sym = e->symbol;
@ -993,6 +993,9 @@ is_constexpr (const expr_t *e)
if ((e->type == ex_expr || e->type == ex_uexpr) && e->expr.constant) {
return true;
}
if (e->type == ex_symbol) {
return e->symbol->is_constexpr;
}
return is_constant (e);
}

View file

@ -83,12 +83,7 @@ glsl_layout_constant_id (specifier_t spec, const expr_t *qual_name,
spec.sym->sy_type = sy_expr;
spec.sym->expr = expr;
}
if (spec.sym->sy_type == sy_expr && spec.sym->expr->type == ex_value) {
auto expr = new_unary_expr ('+', spec.sym->expr);
expr->expr.constant = true;
expr->expr.type = spec.sym->type;
spec.sym->expr = expr;
}
spec.sym->is_constexpr = true;
const char *name = expr_string (qual_name);
set_attribute (&spec.sym->attributes, name, val);
}