[LLVMbugs] [Bug 20193] New: ubsan emits superfluous overflow checks for promoted arithmetic

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 2 16:10:40 PDT 2014


            Bug ID: 20193
           Summary: ubsan emits superfluous overflow checks for promoted
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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; }


define i32 @main() #0 prefix <{ i32, i8* }> <{ i32 1413876459, i8* bitcast ({
i8*, i8* }* @_ZTIFivE to i8*) }> {
  %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.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140702/faa8e141/attachment.html>

More information about the llvm-bugs mailing list