Bug 109231 - [nir] src/compiler/nir/nir_loop_analyze.c uninitialized variable
Summary: [nir] src/compiler/nir/nir_loop_analyze.c uninitialized variable
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: git
Hardware: Other All
: medium normal
Assignee: mesa-dev
QA Contact: mesa-dev
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-06 13:39 UTC by oschowa
Modified: 2019-01-06 23:58 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description oschowa 2019-01-06 13:39:01 UTC
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.
Comment 1 Timothy Arceri 2019-01-06 22:26:27 UTC
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.
Comment 2 oschowa 2019-01-06 23:10:16 UTC
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.
Comment 3 Timothy Arceri 2019-01-06 23:36:19 UTC
I've sent a patch to avoid the warning:

https://patchwork.freedesktop.org/patch/275164/
Comment 4 Timothy Arceri 2019-01-06 23:58:58 UTC
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.