From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 820E3385DDD5 for ; Tue, 25 Jun 2024 14:29:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 820E3385DDD5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 820E3385DDD5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719325803; cv=none; b=WM39xcDBASv+AZIom73rNEHL2YZaOOkNUGoh29ZhvLCPX6z1v78AXrJtRK6SSPZ+FPY5FPvQV8EpDKBvYcKRS6anWI/j6HjSfQ55GGwCvv9AeM7xIzMKBT9flEvfo2xV2gfY4NYofn53Wl+69WWFLLS2zoPcicf/jcH8oTjJ5KE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719325803; c=relaxed/simple; bh=BeeVpN0EnZJ5M7WFg0qoef0cgjY3CwlGcYelNxvh1Wg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=WOAhes2TSiB4GCN6U1aPgVCWb14LahwbjLgKecT/C6GUmuOSO0JemwFGLCzMN8QR5TNWCb4/zb47Z0IADX0kk3T9IiXBZsBriR8UgXH6cmiYmB3oKX+Pqn85yKQEtn6ke+O2UI/mGyfAPGFjQig94PQ7VIbnjJzvjr4W7UxyQQc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-3737dc4a669so22234155ab.0 for ; Tue, 25 Jun 2024 07:29:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1719325798; x=1719930598; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=jhjsBGnfKjKytp8bbH13P/GiZmi9YYfJe4aTUbAaXT0=; b=J2uZebiLzn8BufiycJY9I/KDJEXk0Wrrea/vOXwc2eIRS/mjLymD8pNhiLNHeCWiD0 BPUi5uwzwQpRFmCgCH9Gn8RPw/4gNaJKWU5ZsAN9qHvd1TsfeuigTj90yawWEc6NIyc5 noyYc0AVqFT/80kFd+FFgH0X5QqwJISxbiAspC9ILTh0y7Zkog5m3QunTEIvu2YLt7GP U1On9ICX4DwLF9WHXXnL6FwigKl6jz/YaGKm5VIEnR0YVvhybUtNgt21bVPE6aD1RucI nnSVzorNo0NQP25ecTvJB79sm+74JtA/8jazkNkvuzWejjNlRMuNtmM4JiFuUUoh72/f 8LFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719325798; x=1719930598; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jhjsBGnfKjKytp8bbH13P/GiZmi9YYfJe4aTUbAaXT0=; b=w2hTEg3UcqIadY69zirrovQTyZIb10Zxh2A1qYhkhBGsZDiWzLDswFcIdDVkTNsAPY SxShoQRkcco1HlNYyMyb0/SfjdYiiIndSFA3BKrPQ3XkmSYmNqd/eYLY8aDDfnyRXizN +IvxWyjRApx8Q8zczQxu9GkBR8RRA7INW5z9DksoxDAoVEijIOuGOZ8eKJ39VnBIC6C7 IzfUT1jas6wW9qObYHihkXTzPnnX88jI613Yvp1D6SjpfcMyXXBEM6PfcB6CTco0pJe1 /A+aSSZRdmr0RQ/AAygXLc5A9QvD4D0WWFk0KIOJzRXf5GL4Qj9yg386GTf2vRL+DCI1 TZ9g== X-Gm-Message-State: AOJu0YwNasOx8YBaaELwwNHATgdw8kL09OOUuuMfWD4rmv7OOvUpHJl8 SxHM1DWUH2VHa34uGwqiFl6mM4ZNzw0pmQnd7EeuyfO3hyW54HDTSN+T4gEuya0XSUuY95MpiW6 9 X-Google-Smtp-Source: AGHT+IGbuyhhU1mUVc9oBZcppEVEkeH6h3w591aCOMOemH3+/myGluhx/5SHkIcUXtuYhYuYhalRuA== X-Received: by 2002:a05:6e02:2162:b0:374:93d5:e370 with SMTP id e9e14a558f8ab-3763f6cc395mr102088085ab.23.1719325798202; Tue, 25 Jun 2024 07:29:58 -0700 (PDT) Received: from pondscum.hsd1.co.comcast.net ([2601:281:d901:5620:d4dd:b13d:1466:d5e]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-377161d1255sm465655ab.5.2024.06.25.07.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 07:29:57 -0700 (PDT) From: Sandra Loosemore To: gcc-patches@gcc.gnu.org Subject: [PATCH, obvious] Fix PR c/115587, uninitialized variable in c_parser_omp_loop_nest Date: Tue, 25 Jun 2024 08:29:53 -0600 Message-Id: <20240625142954.331746-1-sloosemore@baylibre.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. --- 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 e83e9c683f7..33643ec910a 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; diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index e7409b856f1..e5f16fe963d 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 -- 2.25.1