public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Faust <david.faust@oracle.com>
To: gcc-patches@gcc.gnu.org
Subject: [committed] bpf: avoid possible use of uninitialized variable
Date: Tue, 15 Nov 2022 11:05:23 -0800	[thread overview]
Message-ID: <20221115190523.23018-1-david.faust@oracle.com> (raw)

Fix a maybe-uninitialized warning introduced in commit:
068baae1864 bpf: add preserve_field_info builtin

Thanks to Jan-Benedict Glaw for pointing this out.

Tested on bpf-unknown-none, committed as obvious.

gcc/

	* config/bpf/bpf.cc (bpf_expand_builtin): Avoid use of uninitialized
	variable in error case.
---
 gcc/config/bpf/bpf.cc | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc
index 16af2412bf6..51e46955015 100644
--- a/gcc/config/bpf/bpf.cc
+++ b/gcc/config/bpf/bpf.cc
@@ -1254,11 +1254,14 @@ bpf_expand_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
       /* A resolved overloaded __builtin_preserve_field_info.  */
       tree src = CALL_EXPR_ARG (exp, 0);
       tree kind_tree = CALL_EXPR_ARG (exp, 1);
-      unsigned HOST_WIDE_INT kind_val;
+      unsigned HOST_WIDE_INT kind_val = 0;
       if (tree_fits_uhwi_p (kind_tree))
 	kind_val = tree_to_uhwi (kind_tree);
       else
-	error ("invalid argument to built-in function");
+	{
+	  error ("invalid argument to built-in function");
+	  return expand_normal (error_mark_node);
+	}
 
       enum btf_core_reloc_kind kind = (enum btf_core_reloc_kind) kind_val;
 
-- 
2.37.2


                 reply	other threads:[~2022-11-15 19:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221115190523.23018-1-david.faust@oracle.com \
    --to=david.faust@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).