From: Jeff King <firstname.lastname@example.org> To: "Ævar Arnfjörð Bjarmason" <email@example.com> Cc: firstname.lastname@example.org, Junio C Hamano <email@example.com>, Denton Liu <firstname.lastname@example.org>, Jeff Hostetler <email@example.com>, Johannes Schindelin <Johannes.Schindelin@gmx.de> Subject: Re: [PATCH v2] trace2: refactor to avoid gcc warning under -O3 Date: Tue, 11 May 2021 13:54:19 -0400 [thread overview] Message-ID: <YJrEy8IPi+PFWuzT@coredump.intra.peff.net> (raw) In-Reply-To: <patch-1.1-782555daade-20210511T130231Zfirstname.lastname@example.org> On Tue, May 11, 2021 at 03:04:28PM +0200, Ævar Arnfjörð Bjarmason wrote: > Refactor tr2_dst_try_uds_connect() to avoid a gcc warning 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  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. Thanks, I think this describes the problem nicely. > On Tue, May 11 2021, Junio C Hamano wrote: > > > What's the concensus if any on this topic? > > Having read Johannes's comments I think it's still most readable to > just return -1 unconditionally. The resulting code isn't weird, I'd > argue that it's a better pattern to save away errno like this, but the > commit messages notes that we're working around a GCC bug. Agreed. Returning "-1" is the usual style in our code base. And while I think the original code is correct, I did have to go double-check the C standard to confirm that it's so. I slightly disagree with the notion that gcc's behavior is a bug. It seems more like a lack of feature (it does not have any way to annotate this special property of errno). But that is neither here nor there for your patch, and really a matter of opinion. :) > > In any case, this needs to be signed off before it gets carved into > > our history. > > Done, and also changed the variable name to minimize the size of the > diff. A shorter name allowed for less re-flowing of lines. It's quite short. I'm OK with it for a static-local function with few callers like this, though. -Peff
next prev parent reply other threads:[~2021-05-11 17:54 UTC|newest] Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-01 7:30 [PATCH] Fix -Wmaybe-uninitialized warnings under -O0 Denton Liu [not found] ` <CAPUEspgBkmxszgBee8C9hZnEwqztf-XKEj7LB_jWVFJaJCge0w@mail.gmail.com> 2020-04-01 9:05 ` Denton Liu 2020-04-01 9:52 ` Jeff King 2020-04-01 14:06 ` Denton Liu 2020-04-03 14:04 ` Jeff King 2020-04-03 14:38 ` Jeff King 2020-04-04 12:07 ` Denton Liu 2020-04-04 14:21 ` Jeff King 2021-05-05 8:40 ` [PATCH] trace2: refactor to avoid gcc warning under -O3 Ævar Arnfjörð Bjarmason 2021-05-05 9:47 ` Junio C Hamano 2021-05-05 13:34 ` Jeff King 2021-05-05 14:38 ` Johannes Schindelin 2021-05-06 1:26 ` Junio C Hamano 2021-05-06 20:29 ` Johannes Schindelin 2021-05-06 21:10 ` Junio C Hamano 2021-05-11 14:34 ` Johannes Schindelin 2021-05-11 18:00 ` Jeff King 2021-05-11 20:58 ` Junio C Hamano 2021-05-11 21:07 ` Jeff King 2021-05-11 21:33 ` Junio C Hamano 2021-05-11 7:03 ` Junio C Hamano 2021-05-11 13:04 ` [PATCH v2] " Ævar Arnfjörð Bjarmason 2021-05-11 16:40 ` Jeff Hostetler 2021-05-11 17:54 ` Jeff King [this message] 2021-05-11 18:08 ` Jeff King 2021-05-11 21:09 ` Junio C Hamano 2021-05-20 0:20 ` Junio C Hamano 2021-05-20 11:05 ` [PATCH v3] " Ævar Arnfjörð Bjarmason 2021-05-20 13:13 ` Jeff King 2021-05-20 22:08 ` Junio C Hamano 2021-05-21 9:34 ` Jeff King
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 List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=YJrEy8IPi+PFWuzT@coredump.intra.peff.net \ --email@example.com \ --cc=Johannes.Schindelin@gmx.de \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --subject='Re: [PATCH v2] trace2: refactor to avoid gcc warning under -O3' \ /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
Code repositories for project(s) associated with this inbox: https://80x24.org/mirrors/git.git 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).