When compiling a release build of a Mesa driver which uses nir and configured with 'meson -D buildtype=release -D b_ndebug=true ...' gcc 8.2.1 generate this warning: [69/241] Compiling C object 'src/compiler/nir/068b2c8@@nir@sta/nir_loop_analyze.c.o'. ../../home/oschowa/mnt/data/_home/storage/builds/mesa/src/compiler/nir/nir_loop_analyze.c: In function ‘process_loops’: ../../home/oschowa/mnt/data/_home/storage/builds/mesa/src/compiler/nir/nir_loop_analyze.c:270:55: warning: ‘alu_op’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (alu->src[0].src.ssa == alu_srcs[0] && ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ alu->src[1].src.ssa == alu_srcs[1] && ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ alu->op == alu_op) { ~~~~~~~~~~~~~~~~~ ../../home/oschowa/mnt/data/_home/storage/builds/mesa/src/compiler/nir/nir_loop_analyze.c:255:20: note: ‘alu_op’ was declared here nir_op alu_op; There indeed seems to be a comparison with an uninitialized variable. A debug build does not trigger this warning.
The first two conditions of the if can never be true on the first iteration of the loop so we will never actually do a comparison with an uninitialized variable. Unfortunately the compiler can't know that.
Ok, that makes sense, thanks. Would it be a good idea to zero-initialize the variable anyways, just to silence the warning? Anyways, feel free to close this.
I've sent a patch to avoid the warning: https://patchwork.freedesktop.org/patch/275164/
Fixed by: commit 6dade5d534a752ba769f2ea91153c6c5d2acb956 Author: Timothy Arceri <tarceri@itsqueeze.com> Date: Mon Jan 7 10:33:43 2019 +1100 nir: avoid uninitialized variable warning Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=109231
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.