From: Patrick Steinhardt <ps@pks.im>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 2/2] ci: let pedantic job compile with -Og
Date: Thu, 6 Jun 2024 09:41:56 +0200 [thread overview]
Message-ID: <ZmFoRPd52iqxbOTJ@tanuki> (raw)
In-Reply-To: <20240606065236.GA646308@coredump.intra.peff.net>
[-- Attachment #1: Type: text/plain, Size: 4891 bytes --]
On Thu, Jun 06, 2024 at 02:52:36AM -0400, Jeff King wrote:
> On Thu, Jun 06, 2024 at 08:30:34AM +0200, Patrick Steinhardt wrote:
>
> > We have recently noticed that our CI does not always notice variables
> > that may be used uninitialized. While it is expected that compiler
> > warnings aren't perfect, this one was a but puzzling because it was
> > rather obvious that the variable can be uninitialized.
> >
> > Many compiler warnings unfortunately depend on the optimization level
> > used by the compiler. While `-O0` for example will disable a lot of
> > warnings altogether because optimization passes go away, `-O2`, which is
> > our default optimization level used in CI, may optimize specific code
> > away or even double down on undefined behaviour. Interestingly, this
> > specific instance that triggered the investigation does get noted by GCC
> > when using `-Og`.
> >
> > While we could adapt all jobs to compile with `-Og` now, that would
> > potentially mask other warnings that only get diagnosed with `-O2`.
> > Instead, only adapt the "pedantic" job to compile with `-Og`.
>
> Hmm. This is the first time I've ever seen lower optimization levels
> produce more warnings. It is almost always the opposite case in my
> experience. So it's not clear to me that moving to "-Og" will generally
> find more warning spots, and that this isn't a bit of a fluke.
>
> As you note, we'll still compile with -O2 in other jobs. But isn't the
> point of the pedantic job to enable a bunch of extra warnings that
> aren't available elsewhere? We wouldn't have any coverage of those.
>
> So for the pedantic warnings, we're left with a guess as to whether -Og
> or -O2 will yield more results. And in my experience it is probably -O2.
>
> If we want to get coverage of -Og, I'd suggest doing it in a job that is
> otherwise overlapping with another (maybe linux-TEST-vars, which I think
> is otherwise a duplicate build?).
I don't think linux-TEST-vars would be a good candidate for this because
it uses Ubuntu 20.04. Ideally, we'd want to have a test run with an
up-to-date version of Ubuntu so that we also get a recent version of the
compiler toolchain.
I kind of wonder whether we should revamp this pedantic job in the first
place. The consequence of that job is that our codebase needs to be
compile cleanly with `-Wpedantic`. So if that is a requirement anyway,
why don't we run all jobs with `DEVOPTS=pedantic` and just drop this job
altogether? This may surface some additional warnings on platforms where
we currently don't set that, but is that a bad thing?
The only downside I can think of is that we stop compiling on Fedora,
which may have a more up-to-date GCC version than Ubuntu. But if the
goal of this job was to _really_ get an up-to-date compiler toolchain,
then we should rather pick a rolling release distro like Arch. Otherwise
I find this to be of dubious benefit.
If we merge it into the other jobs, then I'd just pick any random job
that uses "ubuntu:latest" like "linux-gcc-default" to compile with
`-Og`.
> > diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh
> > index 98dda42045..e78e19e4a6 100755
> > --- a/ci/run-build-and-tests.sh
> > +++ b/ci/run-build-and-tests.sh
> > @@ -44,6 +44,15 @@ pedantic)
> > # Don't run the tests; we only care about whether Git can be
> > # built.
> > export DEVOPTS=pedantic
> > + # Warnings generated by compilers are unfortunately specific to the
> > + # optimization level. With `-O0`, many warnings won't be shown at all,
> > + # whereas the optimizations performed by our default optimization level
> > + # `-O2` will mask others. We thus use `-Og` here just so that we have
> > + # at least one job with a different optimization level so that we can
> > + # overall surface more warnings.
> > + cat >config.mak <<-EOF
> > + export CFLAGS=-Og
> > + EOF
>
> Writing config.mak is unusual, though I guess just setting CFLAGS in the
> environment isn't enough, because we set it unconditionally in the
> Makefile. Doing "make CFLAGS=-Og" would work, but we'd need help from
> the code that actually runs "make".
Yeah, I went the easy route because setting it via the environment is
not enough, as you correctly mention.
> I do suspect the "export" is unnecessary; it should just be used by the
> Makefile recipes themselves.
>
> Your command above also loses the "-g" and "-Wall" from the default
> CFLAGS. Maybe OK, since DEVELOPER=1 implies -Wall anyway, and "-g" isn't
> important. But one thing I've done for a long time in my config.mak is:
>
> O ?= 2
> CFLAGS = -g -Wall -O$(O)
>
> Then you can "make O=0" or "make O=g" if you want. And I think that
> setting O=g in the environment (exported) would work, as well.
Sure, I can do something along these lines.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-06-06 7:42 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 [this message]
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
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=ZmFoRPd52iqxbOTJ@tanuki \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.