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, adapt the "linux-gcc-default" job to compile with `-Og`. This job is chosen because it uses the "ubuntu:latest" image and should thus have a comparatively recent compiler toolchain, and because we have other jobs that use "ubuntu:latest" so that we do not loose coverage for warnings diagnosed only on `-O2` level. To make it easier to set up the optimization level in our CI, add support in our Makefile to specify the level via an environment variable. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- I was a little torn whether we really want to name the variable `O` here because it feels so easy to set it by accident. We could rename this to `OPTIMIZATION` or `OPTIMIZATION_LEVEL`, but that's quite a mouthful. Alternatively, if we don't want to have this variable in the first place, then I'm also happy to adapt the script itself to pass the optimization level via an argument. Makefile | 3 ++- ci/run-build-and-tests.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 59d98ba688..ff57c94fdf 100644 --- a/Makefile +++ b/Makefile @@ -1357,7 +1357,8 @@ endif # tweaked by config.* below as well as the command-line, both of # which'll override these defaults. # Older versions of GCC may require adding "-std=gnu99" at the end. -CFLAGS = -g -O2 -Wall +O ?= 2 +CFLAGS = -g -O$(O) -Wall LDFLAGS = CC_LD_DYNPATH = -Wl,-rpath, BASIC_CFLAGS = -I. diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh index 98dda42045..0f00dbd289 100755 --- a/ci/run-build-and-tests.sh +++ b/ci/run-build-and-tests.sh @@ -13,6 +13,15 @@ esac run_tests=t case "$jobname" in +linux-gcc-default) + # 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. + export O=g + ;; linux-gcc) export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main ;; -- 2.45.2.409.g7b0defb391.dirty
Attachment:
signature.asc
Description: PGP signature