mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-12-11 21:11:09 +00:00
ast_unary::make: safer double-negation optimization check
This commit is contained in:
parent
896d4c53a3
commit
6d4539814e
1 changed files with 14 additions and 10 deletions
24
ast.cpp
24
ast.cpp
|
@ -365,16 +365,20 @@ ast_binstore::~ast_binstore()
|
||||||
|
|
||||||
ast_unary* ast_unary::make(lex_ctx_t ctx, int op, ast_expression *expr)
|
ast_unary* ast_unary::make(lex_ctx_t ctx, int op, ast_expression *expr)
|
||||||
{
|
{
|
||||||
if (ast_istype(expr, ast_unary) && OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) {
|
// handle double negation, double bitwise or logical not
|
||||||
ast_unary *prev = (ast_unary*)((ast_unary*)expr)->m_operand;
|
if (op == opid2('!','P') ||
|
||||||
|
op == opid2('~','P') ||
|
||||||
/* Handle for double negation */
|
op == opid2('-','P'))
|
||||||
if (((ast_unary*)expr)->m_op == op)
|
{
|
||||||
prev = (ast_unary*)((ast_unary*)expr)->m_operand;
|
if (ast_istype(expr, ast_unary) && OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) {
|
||||||
|
ast_unary *unary = reinterpret_cast<ast_unary*>(expr);
|
||||||
if (ast_istype(prev, ast_unary)) {
|
if (unary->m_op == op) {
|
||||||
++opts_optimizationcount[OPTIM_PEEPHOLE];
|
auto out = reinterpret_cast<ast_unary*>(unary->m_operand);
|
||||||
return prev;
|
unary->m_operand = nullptr;
|
||||||
|
delete unary;
|
||||||
|
++opts_optimizationcount[OPTIM_PEEPHOLE];
|
||||||
|
return out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue