<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 --- - clang-analyzer-core.uninitialized.Assign doesn't understand bits sets/read operations"
   href="https://llvm.org/bugs/show_bug.cgi?id=25235">25235</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-analyzer-core.uninitialized.Assign doesn't understand bits sets/read operations
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>kremenek@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>gonzalobg88@gmail.com
          </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>Given an uninitialized variable:

uint32_t var;

and a function to set the i-th bit of var to a value: 

template <typename Int>
constexpr void set(Int& x, unsigned b, bool value) {
  static_assert(std::is_integral<Int>{}, "");
  assert(bit < CHAR_BIT * sizeof(Int{}));
  if (value) {
    x |= (Int{1} << b);
  } else {
    x &= ~(Int{1} << b);
  }
}

Then static analyzer complains when:

set(var, 3, true);

is used to set the 3rd bit of var to true because set reads and writes not only
the 3rd bit, but obviously the whole variable, which is uninitialized.

Probably static_analyzer will also fail when reading the 3rd bit back from var.

Since bit operations and bit masks are very common, static analyzer should
probably track the bits or at least understand the basic bit manipulation
operations.</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>