<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - fixit hints: don't suggest initialization with 0 if var is known to be divisor"
   href="https://llvm.org/bugs/show_bug.cgi?id=31661">31661</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>fixit hints: don't suggest initialization with 0 if var is known to be divisor
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.9
          </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>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>matthias.krueger@famsik.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is not a big issue, I just found it a little strange:

this code:

static u64 get_dev_extent_len(struct map_lookup *map)
{
    int div;

    switch (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
    case 0: /* Single */
    case BTRFS_BLOCK_GROUP_DUP:
    case BTRFS_BLOCK_GROUP_RAID1:
        div = 1;
        break;
    case BTRFS_BLOCK_GROUP_RAID5:
        div = (map->num_stripes - 1);
        break;
    case BTRFS_BLOCK_GROUP_RAID6:
        div = (map->num_stripes - 2);
        break;
    case BTRFS_BLOCK_GROUP_RAID10:
        div = (map->num_stripes / map->sub_stripes);
        break;
    default:
        /* normally, read chunk security hook should handled it */
        BUG_ON(1);
    }
    return map->ce.size / div;
}
from btrfs
<a href="https://github.com/kdave/btrfs-progs/blob/bde687343b827bd425e912136ecf191c593b38fd/extent-tree.c#L3669">https://github.com/kdave/btrfs-progs/blob/bde687343b827bd425e912136ecf191c593b38fd/extent-tree.c#L3669</a>

produces this warning:

extent-tree.c:3688:2: warning: variable 'div' is used uninitialized whenever
switch default is taken [-Wsometimes-uninitialized]
        default:
        ^~~~~~~
extent-tree.c:3692:24: note: uninitialized use occurs here
        return map->ce.size / div;
                              ^~~
extent-tree.c:3671:9: note: initialize the variable 'div' to silence this
warning
        int div;
               ^
                = 0


So if we initialized with 0 and the default case was taken (which should not
happen in theory), we would have a division by zero.
Perhaps clang could suggest initializing with "1" if the variable is known to
have uninitialized access as divisor otherwise?

Just an idea, feel free to close if you think this ticket is nonsense.

clang 3.9 and dev(to-be 4.0)

Kind regards
Matthias</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>