public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Tsukasa OI <research_trasio@irq.a4lg.com>
To: Tsukasa OI <research_trasio@irq.a4lg.com>,
	Nelson Chu <nelson@rivosinc.com>,
	Kito Cheng <kito.cheng@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>
Cc: binutils@sourceware.org
Subject: [PATCH] RISC-V: Fix build failure for -Werror=maybe-uninitialized
Date: Fri, 28 Oct 2022 06:53:02 +0000	[thread overview]
Message-ID: <ac4f3f3c7115a824f73aca6935789b14d33c9a58.1666939920.git.research_trasio@irq.a4lg.com> (raw)

Commit 40f1a1a4564b ("RISC-V: Output mapping symbols with ISA string.")
caused a build failure on GCC 12 as follows:

make[3]: Entering directory '$(builddir)/gas'
  CC       config/tc-riscv.o
In file included from $(srcdir)/gas/config/tc-riscv.c:23:
$(srcdir)/gas/as.h: In function ‘make_mapping_symbol’:
$(srcdir)/gas/as.h:123:15: error: ‘buff’ may be used uninitialized [-Werror=maybe-uninitialized]
  123 | #define xfree free
      |               ^~~~
$(srcdir)/gas/config/tc-riscv.c:487:9: note: ‘buff’ was declared here
  487 |   char *buff;
      |         ^~~~
cc1: all warnings being treated as errors
make[3]: *** [Makefile:1425: config/tc-riscv.o] Error 1

This is caused by a false positive of "maybe uninitialized" variable
detection (-Wmaybe-uninitialized).  To avoid this error, this commit
initializes the local variable buff to NULL first in all cases.

gas/ChangeLog:

	* config/tc-riscv.c (make_mapping_symbol): Initialize variable
	buff with NULL to avoid build failure caused by a GCC's false
	positive of maybe uninitialized variable detection.
---
 gas/config/tc-riscv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 91cff7de604..f4478eac11e 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -484,7 +484,7 @@ make_mapping_symbol (enum riscv_seg_mstate state,
 		     bool reset_seg_arch_str)
 {
   const char *name;
-  char *buff;
+  char *buff = NULL;
   switch (state)
     {
     case MAP_DATA:

base-commit: 56d4450bdfc873ff3c2d1ebb194c7a076d4d13f6
-- 
2.37.2


             reply	other threads:[~2022-10-28  6:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28  6:53 Tsukasa OI [this message]
2022-10-28  7:38 ` Nelson Chu

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=ac4f3f3c7115a824f73aca6935789b14d33c9a58.1666939920.git.research_trasio@irq.a4lg.com \
    --to=research_trasio@irq.a4lg.com \
    --cc=binutils@sourceware.org \
    --cc=kito.cheng@sifive.com \
    --cc=nelson@rivosinc.com \
    --cc=palmer@dabbelt.com \
    /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).