X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ast.cpp;h=3a26dd9f37c225f6d6ac3402ffd1f72773874eb5;hp=acf4928e6beb25442230a0f811b68e0dfca0f378;hb=6d4539814e2796ffd1b09f39a10d9b456790acb5;hpb=45236a644fb45ac9f61c3ef38bcab17b5004b095 diff --git a/ast.cpp b/ast.cpp index acf4928..3a26dd9 100644 --- a/ast.cpp +++ b/ast.cpp @@ -24,9 +24,10 @@ ast_node::~ast_node() } /* weight and side effects */ -void ast_node::propagateSideEffects(ast_node *other) const +void ast_node::propagateSideEffects(const ast_node *other) { - other->m_side_effects = m_side_effects; + if (other->m_side_effects) + m_side_effects = true; } /* General expression initialization */ @@ -364,16 +365,20 @@ ast_binstore::~ast_binstore() ast_unary* ast_unary::make(lex_ctx_t ctx, int op, ast_expression *expr) { - if (ast_istype(expr, ast_unary) && OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) { - ast_unary *prev = (ast_unary*)((ast_unary*)expr)->m_operand; - - /* Handle for double negation */ - if (((ast_unary*)expr)->m_op == op) - prev = (ast_unary*)((ast_unary*)expr)->m_operand; - - if (ast_istype(prev, ast_unary)) { - ++opts_optimizationcount[OPTIM_PEEPHOLE]; - return prev; + // handle double negation, double bitwise or logical not + if (op == opid2('!','P') || + op == opid2('~','P') || + op == opid2('-','P')) + { + if (ast_istype(expr, ast_unary) && OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) { + ast_unary *unary = reinterpret_cast(expr); + if (unary->m_op == op) { + auto out = reinterpret_cast(unary->m_operand); + unary->m_operand = nullptr; + delete unary; + ++opts_optimizationcount[OPTIM_PEEPHOLE]; + return out; + } } } @@ -946,6 +951,10 @@ ast_function::~ast_function() ast_unref(m_fixedparams); if (m_return_value) ast_unref(m_return_value); + + // force this to be cleared before m_varargs/m_argc as blocks might + // try to access them via ast_unref() + m_blocks.clear(); } const char* ast_function::makeLabel(const char *prefix)