aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorSandra Loosemore <sloosemore@baylibre.com>2024-06-25 13:54:43 +0000
committerSandra Loosemore <sloosemore@baylibre.com>2024-06-25 14:28:40 +0000
commit21f1073d388af8af207183b0ed592e1cc47d20ab (patch)
treefe198c2e4ea7865a2865fd76d50e9a6ee2b803bf /gcc/cp
parent3587bfae391616d155de0c9cbe98206634f3ed6b (diff)
downloadgcc-21f1073d388af8af207183b0ed592e1cc47d20ab.zip
gcc-21f1073d388af8af207183b0ed592e1cc47d20ab.tar.gz
gcc-21f1073d388af8af207183b0ed592e1cc47d20ab.tar.bz2
Fix PR c/115587, uninitialized variable in c_parser_omp_loop_nest
This function had a reference to an uninitialized variable on the error path. The problem was diagnosed by clang but not gcc. It seems the cleanest solution is to initialize all the loop-clause variables at the point of declaration rather than at different places in the code. The C++ front end didn't have this problem, but I've made similar changes there to keep the code in sync. gcc/c/ChangeLog: PR c/115587 * c-parser.cc (c_parser_omp_loop_nest): Move initializations to point of declaration. gcc/cp/ChangeLog: PR c/115587 * parser.cc (cp_parser_omp_loop_nest): Move initializations to point of declaration.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/parser.cc8
1 files changed, 2 insertions, 6 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index e7409b8..e5f16fe 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -45153,8 +45153,8 @@ static tree cp_parser_omp_tile (cp_parser *, cp_token *, bool *);
static tree
cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p)
{
- tree decl, cond, incr, init;
- tree orig_init, real_decl, orig_decl;
+ tree decl = NULL_TREE, cond = NULL_TREE, incr = NULL_TREE, init = NULL_TREE;
+ tree orig_init = NULL_TREE, real_decl = NULL_TREE, orig_decl = NULL_TREE;
tree init_block, body_block;
tree init_placeholder, body_placeholder;
tree init_scope;
@@ -45324,8 +45324,6 @@ cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p)
if (!parens.require_open (parser))
return NULL;
- init = orig_init = decl = real_decl = orig_decl = NULL_TREE;
-
init_placeholder = build_stmt (input_location, EXPR_STMT,
integer_zero_node);
vec_safe_push (omp_for_parse_state->init_placeholderv, init_placeholder);
@@ -45501,12 +45499,10 @@ cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p)
}
}
- cond = NULL;
if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
cond = cp_parser_omp_for_cond (parser, decl, omp_for_parse_state->code);
cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
- incr = NULL;
if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
{
/* If decl is an iterator, preserve the operator on decl