On 2/10/21 12:35 PM, Marek Polacek wrote:
Freeing the condition chain needs to use vec_free which does ->release,
or we leak memory.
OK, but if chain were an auto_vec, delete would work.
Can we merge auto_vec with vec now that we're compiling as C++11?
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
gcc/c/ChangeLog:
* c-parser.c (c_parser_if_statement): Use vec_free.
gcc/cp/ChangeLog:
* parser.c (cp_parser_selection_statement): Use vec_free.
---
gcc/c/c-parser.c | 18 ++++++------------
gcc/cp/parser.c | 27 +++++++++------------------
2 files changed, 15 insertions(+), 30 deletions(-)
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index a8df208493c..2a49d07bab4 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6499,12 +6499,9 @@ c_parser_if_statement (c_parser *parser, bool *if_p,
vec<tree> *chain)
chain->safe_push (cond);
}
else if (!c_parser_next_token_is_keyword (parser, RID_IF))
- {
- /* This is if-else without subsequent if. Zap the condition
- chain; we would have already warned at this point. */
- delete chain;
- chain = NULL;
- }
+ /* This is if-else without subsequent if. Zap the condition
+ chain; we would have already warned at this point. */
+ vec_free (chain);
}
second_body = c_parser_else_body (parser, else_tinfo, chain);
/* Set IF_P to true to indicate that this if statement has an
@@ -6524,12 +6521,9 @@ c_parser_if_statement (c_parser *parser, bool *if_p,
vec<tree> *chain)
"suggest explicit braces to avoid ambiguous %<else%>");
if (warn_duplicated_cond)
- {
- /* This if statement does not have an else clause. We don't
- need the condition chain anymore. */
- delete chain;
- chain = NULL;
- }
+ /* This if statement does not have an else clause. We don't
+ need the condition chain anymore. */
+ vec_free (chain);
}
c_finish_if_stmt (loc, cond, first_body, second_body);
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 5da8670f0e2..d68dcb7d74f 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -12247,12 +12247,9 @@ cp_parser_selection_statement (cp_parser* parser, bool
*if_p,
"init-statement in selection statements only available "
"with %<-std=c++17%> or %<-std=gnu++17%>");
if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
- {
- /* A non-empty init-statement can have arbitrary side
- effects. */
- delete chain;
- chain = NULL;
- }
+ /* A non-empty init-statement can have arbitrary side
+ effects. */
+ vec_free (chain);
cp_parser_init_statement (parser, &decl);
}
@@ -12343,13 +12340,10 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p,
}
else if (!cp_lexer_next_token_is_keyword (parser->lexer,
RID_IF))
- {
- /* This is if-else without subsequent if. Zap the
- condition chain; we would have already warned at
- this point. */
- delete chain;
- chain = NULL;
- }
+ /* This is if-else without subsequent if. Zap the
+ condition chain; we would have already warned at
+ this point. */
+ vec_free (chain);
}
begin_else_clause (statement);
/* Parse the else-clause. */
@@ -12384,11 +12378,8 @@ cp_parser_selection_statement (cp_parser* parser, bool
*if_p,
"suggest explicit braces to avoid ambiguous"
" %<else%>");
if (warn_duplicated_cond)
- {
- /* We don't need the condition chain anymore. */
- delete chain;
- chain = NULL;
- }
+ /* We don't need the condition chain anymore. */
+ vec_free (chain);
}
/* Now we're all done with the if-statement. */
base-commit: 3df5b249b3c81e95cdcb293a388155ae5b168f9e