From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Patrick Steinhardt <ps@pks.im>, git@vger.kernel.org
Subject: Re: [PATCH v4 2/2] ci: compile "linux-gcc-default" job with -Og
Date: Thu, 13 Jun 2024 06:15:22 -0400 [thread overview]
Message-ID: <20240613101522.GC817573@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqqo785olpp.fsf@gitster.g>
On Wed, Jun 12, 2024 at 03:11:30PM -0700, Junio C Hamano wrote:
> By the way, I do not know if any compiler gives us such a feature,
> but if the trick to squelch a false positive were finer grained, I
> would have been much more receptive to the idea of building with
> different optimization level, allowing a bit more false positives.
>
> The workaround everybody jumps at is to initialize the variable to a
> meaningless value (like 0) and I have explained why it is suboptimal
> already. But if we can tell less intelligent compilers "we know our
> use of this variable AT THIS POINT is safe", e.g. by annotating the
> above snippet of the code, perhaps like this:
>
> if (ret) {
> if (data)
> /* -Wno-uninitialized (mtimes_size) */
> munmap(data, mtimes_size);
> printf("debug %d\n", (int)mtimes_size);
>
> then it would be clear to the compiler that understand the
> annotation that inside that "if (data)" block, we know that
> the use of mtimes_size is not using an uninitialized variable.
>
> For the use of the same variable on the next "debug" line, because
> it is outside of that "if (data)" block, the annotation should have
> no effect, and the compiler is free to do its own analysis and we
> will accept if it finds mtimes_size can be used uninitialized there.
> Any new use added for the same variable will not be masked by a
> meaningless initialization if we can use such a "workaround" to
> squelch false positives.
I agree that such an annotation is much more focused. It's still not
foolproof, though (e.g., we might chance earlier code so that the
data/mtimes_size correlation is no longer true).
I think you could do it with:
if (data)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
munmap(data, mtimes_size);
#pragma GCC diagnostic pop
which is...ugly. There's a _Pragma() operator, too, which I think would
let you make a macro like:
if (data)
SUPPRESS("-Wuninitialized", munmap(data, mtimes_size));
which is maybe slightly less horrific? Still pretty magical though.
But if the alternative is to do none of that, and just continue to avoid
looking for warnings with -Os, I prefer that.
-Peff
next prev parent reply other threads:[~2024-06-13 10:15 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-06 6:30 [PATCH 0/2] ci: detect more warnings via `-Og` Patrick Steinhardt
2024-06-06 6:30 ` [PATCH 1/2] ci: fix check for Ubuntu 20.04 Patrick Steinhardt
2024-06-06 6:53 ` Jeff King
2024-06-06 7:44 ` Patrick Steinhardt
2024-06-06 6:30 ` [PATCH 2/2] ci: let pedantic job compile with -Og Patrick Steinhardt
2024-06-06 6:52 ` Jeff King
2024-06-06 7:41 ` Patrick Steinhardt
2024-06-06 8:05 ` Jeff King
2024-06-06 8:25 ` Patrick Steinhardt
2024-06-06 9:31 ` [PATCH v2 0/2] ci: detect more warnings via `-Og` Patrick Steinhardt
2024-06-06 9:31 ` [PATCH v2 1/2] ci: fix check for Ubuntu 20.04 Patrick Steinhardt
2024-06-06 9:31 ` [PATCH v2 2/2] ci: compile "linux-gcc-default" job with -Og Patrick Steinhardt
2024-06-06 15:32 ` Justin Tobler
2024-06-06 17:02 ` Junio C Hamano
2024-06-07 5:28 ` Patrick Steinhardt
2024-06-07 18:45 ` Junio C Hamano
2024-06-08 8:49 ` Jeff King
2024-06-07 18:48 ` Junio C Hamano
2024-06-07 20:35 ` Junio C Hamano
2024-06-07 6:46 ` [PATCH v3 0/4] ci: detect more warnings via `-Og` Patrick Steinhardt
2024-06-07 6:46 ` [PATCH v3 1/4] ci: fix check for Ubuntu 20.04 Patrick Steinhardt
2024-06-07 6:46 ` [PATCH v3 2/4] Makefile: add ability to append to CFLAGS and LDFLAGS Patrick Steinhardt
2024-06-08 8:55 ` Jeff King
2024-06-08 19:01 ` Junio C Hamano
2024-06-10 7:01 ` Patrick Steinhardt
2024-06-07 6:46 ` [PATCH v3 3/4] ci: compile code with V=1 Patrick Steinhardt
2024-06-07 6:46 ` [PATCH v3 4/4] ci: compile "linux-gcc-default" job with -Og Patrick Steinhardt
2024-06-07 20:47 ` [PATCH v3 0/4] ci: detect more warnings via `-Og` Junio C Hamano
2024-06-08 9:28 ` Jeff King
2024-06-08 23:12 ` Junio C Hamano
2024-06-10 6:25 ` Patrick Steinhardt
2024-06-06 16:32 ` [PATCH 2/2] ci: let pedantic job compile with -Og Junio C Hamano
2024-06-07 5:10 ` Patrick Steinhardt
2024-06-07 18:42 ` Junio C Hamano
2024-06-10 6:38 ` [PATCH v4 0/2] ci: detect more warnings via `-Og` Patrick Steinhardt
2024-06-10 6:38 ` [PATCH v4 1/2] Makefile: add ability to append to CFLAGS and LDFLAGS Patrick Steinhardt
2024-06-10 6:38 ` [PATCH v4 2/2] ci: compile "linux-gcc-default" job with -Og Patrick Steinhardt
2024-06-10 16:06 ` Junio C Hamano
2024-06-10 18:36 ` [PATCH 1/2] DONTAPPLY: -Og fallout workaround Junio C Hamano
2024-06-10 20:05 ` Junio C Hamano
2024-06-11 12:09 ` Patrick Steinhardt
2024-06-11 17:30 ` Junio C Hamano
2024-06-12 4:42 ` Patrick Steinhardt
2024-06-12 4:45 ` Patrick Steinhardt
2024-06-10 18:36 ` [PATCH 2/2] DONTAPPLY: -Os " Junio C Hamano
2024-06-12 22:11 ` [PATCH v4 2/2] ci: compile "linux-gcc-default" job with -Og Junio C Hamano
2024-06-13 10:15 ` Jeff King [this message]
2024-06-13 15:47 ` Junio C Hamano
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=20240613101522.GC817573@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ps@pks.im \
/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 NNTP newsgroup(s).