aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.cc
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/c/c-parser.cc
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/c/c-parser.cc')
-rw-r--r--gcc/c/c-parser.cc4
1 files changed, 1 insertions, 3 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index e83e9c6..33643ec 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -22430,7 +22430,7 @@ static tree c_parser_omp_unroll (location_t, c_parser *, bool *);
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;
@@ -22619,7 +22619,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;
@@ -22652,7 +22651,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;