<html>
    <head>
      <base href="http://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 --- - ubsan emits superfluous overflow checks for promoted arithmetic"
   href="http://llvm.org/bugs/show_bug.cgi?id=20193">20193</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ubsan emits superfluous overflow checks for promoted arithmetic
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Arithmetic on types that are smaller than 'int' cannot overflow, with the
exception of SHRT_MIN * SHRT_MIN. Ubsan emits superfluous with.overflow
intrinsics in this case anyway:

char min; int main() { return min + min; }

gives:

define i32 @main() #0 prefix <{ i32, i8* }> <{ i32 1413876459, i8* bitcast ({
i8*, i8* }* @_ZTIFivE to i8*) }> {
entry:
  %0 = load i8* @min, align 1, !tbaa !1
  %conv = sext i8 %0 to i32
  %1 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %conv, i32 %conv)
  %2 = extractvalue { i32, i1 } %1, 0
  %3 = extractvalue { i32, i1 } %1, 1
  br i1 %3, label %handler.add_overflow, label %cont, !prof !4
; ...


We also emit unnecessary overflow checks when one of the operands is a constant
and the other is promoted. It would seem straightforward to look at the input
value and check if it's obviously got multiple sign bits, and if so, figure out
that the overflow is impossible.</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>