<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - bugs -Wsometimes-uninitialized warning"
href="https://bugs.llvm.org/show_bug.cgi?id=41197">41197</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>bugs -Wsometimes-uninitialized warning
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>8.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>arnd@linaro.org
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>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 <a href="https://godbolt.org/z/7brWaN">https://godbolt.org/z/7brWaN</a>
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>