From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Namhyung Kim <namhyung@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/1] perf annotate: Initialize 'arch' variable not to trip some -Werror=maybe-uninitialized
Date: Wed, 3 Apr 2024 16:52:28 -0300 [thread overview]
Message-ID: <Zg2zfKFdGCJaYc36@x1> (raw)
In-Reply-To: <CAP-5=fUqtjxAsmdGrnkjhUTLHs-JvV10TtxyocpYDJK_+LYTiQ@mail.gmail.com>
On Wed, Apr 03, 2024 at 09:01:56AM -0700, Ian Rogers wrote:
> On Wed, Apr 3, 2024 at 8:16 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> >
> > In some older distros the build is failing due to
> > -Werror=maybe-uninitialized, in this case we know that this isn't the
> > case because 'arch' gets initialized by evsel__get_arch(), so just init
> > it to NULL to silence those cases.
> >
> > E.g.:
> >
> > 32 17.12 opensuse:15.5 : FAIL gcc version 7.5.0 (SUSE Linux)
> > util/annotate.c: In function 'hist_entry__get_data_type':
> > util/annotate.c:2269:15: error: 'arch' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> > struct arch *arch;
> > ^~~~
> > cc1: all warnings being treated as errors
> >
> > 43 7.30 ubuntu:18.04-x-powerpc64el : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> > util/annotate.c: In function 'hist_entry__get_data_type':
> > util/annotate.c:2351:36: error: 'arch' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> > if (map__dso(ms->map)->kernel && arch__is(arch, "x86") &&
> > ^~~~~~~~~~~~~~~~~~~~~
> > cc1: all warnings being treated as errors
> >
> > Cc: Adrian Hunter <adrian.hunter@intel.com>
> > Cc: Ian Rogers <irogers@google.com>
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> This looks fine but I couldn't line up the errors with code in the
> tree. I was curious why the "maybe-uninitialized" was failing. Perhaps
> evsel__get_arch should set the out argument to NULL when an error
> occurs. This fix is also good but may potentially need repeating for
> other evsel__get_arch cases, so a fix in evsel__get_arch may be
> preferable.
>
> Reviewed-by: Ian Rogers <irogers@google.com>
Trying with this on top, i.e. what you suggests:
From 70e6fd996ce7f9c9adbb30640ed666025bf6f1e4 Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Wed, 3 Apr 2024 16:49:54 -0300
Subject: [PATCH 1/1] WIP
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/annotate.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index f316e0b65897957a..35235147b111e788 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -838,8 +838,10 @@ static int evsel__get_arch(struct evsel *evsel, struct arch **parch)
struct arch *arch;
int err;
- if (!arch_name)
+ if (!arch_name) {
+ *parch = NULL;
return errno;
+ }
*parch = arch = arch__find(arch_name);
if (arch == NULL) {
@@ -2266,7 +2268,7 @@ struct annotated_data_type *hist_entry__get_data_type(struct hist_entry *he)
{
struct map_symbol *ms = &he->ms;
struct evsel *evsel = hists_to_evsel(he->hists);
- struct arch *arch = NULL;
+ struct arch *arch;
struct disasm_line *dl;
struct annotated_insn_loc loc;
struct annotated_op_loc *op_loc;
--
2.44.0
next prev parent reply other threads:[~2024-04-03 19:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-03 15:16 [PATCH 1/1] perf annotate: Initialize 'arch' variable not to trip some -Werror=maybe-uninitialized Arnaldo Carvalho de Melo
2024-04-03 16:01 ` Ian Rogers
2024-04-03 19:52 ` Arnaldo Carvalho de Melo [this message]
2024-04-03 20:15 ` Namhyung Kim
2024-04-03 21:03 ` Arnaldo Carvalho de Melo
2024-04-03 22:01 ` Ian Rogers
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=Zg2zfKFdGCJaYc36@x1 \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.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