Re: [PATCH] trace2: refactor to avoid gcc warning under -O3
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 11, 2021, 07:03 UTC
- Message-ID
- <xmqqv97pn454.fsf@gitster.g>
- In-Reply-To
- <patch-1.1-87d9bcf1095-20210505T083951Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 27 quoted lines
> Refactor tr2_dst_try_uds_connect() to avoid a gcc warning[1] that > appears under -O3 (but not -O2). This makes the build pass under > DEVELOPER=1 without needing a DEVOPTS=no-error. > > This can be reproduced with GCC Debian 8.3.0-6, but not e.g. with > clang 7.0.1-8+deb10u2. We've had this warning since > ee4512ed481 (trace2: create new combined trace facility, 2019-02-22). > > As noted in [2] this warning happens because the compiler doesn't > assume that errno must be non-zero after a failed syscall. Let's work > around it as suggested in that analysis. We now return -1 ourselves on > error, and save away the value of errno in a variable the caller > passes in. > > 1. > > trace2/tr2_dst.c: In function ‘tr2_dst_get_trace_fd.part.5’: > trace2/tr2_dst.c:296:10: warning: ‘fd’ may be used uninitialized in this function [-Wmaybe-uninitialized] > dst->fd = fd; > ~~~~~~~~^~~~ > trace2/tr2_dst.c:229:6: note: ‘fd’ was declared here > int fd; > ^~ > 2. https://lore.kernel.org/git/20200404142131.GA679473@coredump.intra.peff.net/ > --- > trace2/tr2_dst.c | 27 +++++++++++++++------------ > 1 file changed, 15 insertions(+), 12 deletions(-)
What's the concensus if any on this topic?
In any case, this needs to be signed off before it gets carved into our history.
Thanks.