<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 - -Wconversion misses non-elided integral promotion."
   href="https://bugs.llvm.org/show_bug.cgi?id=37170">37170</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-Wconversion misses non-elided integral promotion.
          </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>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>nicholasjbbaldwin@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Integral promotion of smaller int types (e.g. uint8_t) can be elided when no
difference in observable behavior happens. Thus when -Wconversion is turned on
and the promotion is elided, no warning is reported as it should.

However, in the case where elision cannot happen (such as the following code
sample) and integral promotion clearly takes place, -Wconversion still reports
no error.

#include <stdint.h>
uint8_t test(void);

uint8_t test() {
    uint8_t a = 0x5a;
    uint8_t c = (uint8_t)(~(int)a) >> 4;
    return c;
}

will return 0x05 and produces no errors (correct).

#include <stdint.h>
uint8_t test(void);

uint8_t test() {
    uint8_t a = 0x5a;
    uint8_t c = (~a) >> 4;
    return c;
}

will return 0xf5 and still produces no errors (incorrect). Since a is clearly
being promoted to an int, -Wconversion should warn that a the integer
conversion is losing precision.

I've attached a screenshot of the difference in code gen.</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>