[llvm-bugs] [Bug 41197] New: bugs -Wsometimes-uninitialized warning

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 22 04:07:38 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41197

            Bug ID: 41197
           Summary: bugs -Wsometimes-uninitialized warning
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: arnd at linaro.org
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

I found a couple of instances in the linux kernel where clang warns about an
uninitialized variable getting used in a condition that is clearly never true:

Here is a simplified test case from https://godbolt.org/z/7brWaN
int f3(int x)
{
    int y3;

    if (x == 1)
        y3 = 1;
    else if (x != 1)
        y3 = 1;

    return y3;
}

gcc does not warn here, but it's unclear whether this is intentional or not,
given that it also does not warn about similar but incorrect code.

Related warnings I see in the kernel are:

**
    drivers/pwm/pwm-img.c:126:13: error: variable 'timebase' is used
uninitialized whenever 'if' condition is false
          [-Werror,-Wsometimes-uninitialized]
            } else if (mul > max_timebase * 512) {
                       ^~~~~~~~~~~~~~~~~~~~~~~~
    drivers/pwm/pwm-img.c:132:22: note: uninitialized use occurs here
            duty = DIV_ROUND_UP(timebase * duty_ns, period_ns);
                                ^~~~~~~~
**
    drivers/block/rbd.c:2402:4: error: variable 'ret' is used uninitialized
whenever 'if' condition is false
          [-Werror,-Wsometimes-uninitialized]
                            rbd_assert(0);
                            ^~~~~~~~~~~~~
    drivers/block/rbd.c:563:7: note: expanded from macro 'rbd_assert'
                    if (unlikely(!(expr))) {                                \
                        ^~~~~~~~~~~~~~~~~
    include/linux/compiler.h:48:23: note: expanded from macro 'unlikely'
     #  define unlikely(x)   (__branch_check__(x, 0, __builtin_constant_p(x)))
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/block/rbd.c:2410:6: note: uninitialized use occurs here
            if (ret) {
                ^~~
    drivers/block/rbd.c:2402:4: note: remove the 'if' if its condition is
always true
                            rbd_assert(0);
                            ^
    drivers/block/rbd.c:563:3: note: expanded from macro 'rbd_assert'
                    if (unlikely(!(expr))) {                                \
                    ^
    drivers/block/rbd.c:2376:9: note: initialize the variable 'ret' to silence
this warning
            int ret;
**
    drivers/net/wireless/intel/iwlwifi/mvm/sta.c:2114:12: error: variable
'queue' is used uninitialized whenever 'if'
          condition is false [-Werror,-Wsometimes-uninitialized]
                    else if (WARN(1, "Missing required TXQ for adding bcast
STA\n"))
                            
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    include/asm-generic/bug.h:130:36: note: expanded from macro 'WARN'
     #define WARN(condition, format...) ({                                   \
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/net/wireless/intel/iwlwifi/mvm/sta.c:2119:33: note: uninitialized
use occurs here
                    iwl_mvm_enable_txq(mvm, NULL, queue, 0, &cfg, wdg_timeout);
                                                  ^~~~~
**
    fs/btrfs/uuid-tree.c:129:13: error: variable 'eb' is used uninitialized
whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
            } else if (ret < 0) {
                       ^~~~~~~
    fs/btrfs/uuid-tree.c:139:22: note: uninitialized use occurs here
            write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le));
                                ^~
    fs/btrfs/uuid-tree.c:129:9: note: remove the 'if' if its condition is
always true
            } else if (ret < 0) {
                   ^~~~~~~~~~~~~
    fs/btrfs/uuid-tree.c:90:26: note: initialize the variable 'eb' to silence
this warning
            struct extent_buffer *eb;
**
    net/wireless/util.c:1223:11: error: variable 'result' is used uninitialized
whenever 'if' condition is false
          [-Werror,-Wsometimes-uninitialized]
            else if (WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    include/asm-generic/bug.h:130:36: note: expanded from macro 'WARN'
     define WARN(condition, format...) ({                                   \
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    net/wireless/util.c:1228:8: note: uninitialized use occurs here
            tmp = result;
                  ^~~~~~
    net/wireless/util.c:1223:7: note: remove the 'if' if its condition is
always true
            else if (WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    net/wireless/util.c:1187:12: note: initialize the variable 'result' to
silence this warning
            u32 result;


I have made workaround for all of the above.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190322/f754ad46/attachment.html>


More information about the llvm-bugs mailing list