[gcc r14-10346] Fix PR c/115587, uninitialized variable in c_parser_omp_loop_nest
Sandra Loosemore
sandra@gcc.gnu.org
Tue Jun 25 21:47:57 GMT 2024
https://gcc.gnu.org/g:b383719aebe45bbe8cc3944e515ed7caa30e8744
commit r14-10346-gb383719aebe45bbe8cc3944e515ed7caa30e8744
Author: Sandra Loosemore <sloosemore@baylibre.com>
Date: Tue Jun 25 13:54:43 2024 +0000
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.
(cherry picked from commit 21f1073d388af8af207183b0ed592e1cc47d20ab)
Diff:
---
gcc/c/c-parser.cc | 4 +---
gcc/cp/parser.cc | 8 ++------
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 00f8bf4376e..5fcfff7134a 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -22240,7 +22240,7 @@ c_parser_omp_scan_loop_body (c_parser *parser, bool open_brace_parsed)
static tree
c_parser_omp_loop_nest (c_parser *parser, bool *if_p)
{
- tree decl, cond, incr, init;
+ tree decl = NULL_TREE, cond = NULL_TREE, incr = NULL_TREE, init = NULL_TREE;
tree body = NULL_TREE;
matching_parens parens;
bool moreloops;
@@ -22330,7 +22330,6 @@ c_parser_omp_loop_nest (c_parser *parser, bool *if_p)
}
/* Parse the loop condition. */
- cond = NULL_TREE;
if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
{
location_t cond_loc = c_parser_peek_token (parser)->location;
@@ -22363,7 +22362,6 @@ c_parser_omp_loop_nest (c_parser *parser, bool *if_p)
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
/* Parse the increment expression. */
- incr = NULL_TREE;
if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
{
location_t incr_loc = c_parser_peek_token (parser)->location;
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 6b786ed8266..7e81c1010c4 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -44756,8 +44756,8 @@ cp_parser_omp_scan_loop_body (cp_parser *parser)
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;
@@ -44793,8 +44793,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);
@@ -44970,12 +44968,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
More information about the Gcc-cvs
mailing list