[LLVMbugs] [Bug 12290] New: Overflow builtins

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Mar 16 23:30:31 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=12290

             Bug #: 12290
           Summary: Overflow builtins
           Product: clang
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: xi.wang at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


It would be great if Clang provides builtins to help C/C++ programmers perform
overflow checking.  Here's an possible usage, assuming __umuloz(a, b, p) stores
the result of size_t multiplication a * b to p and returns 0 if no overflow
happens.

void *malloc_array(size_t n, size_t size)
{
    size_t bytes;
    if (__umuloz(n, size, &bytes))
        return NULL;
    return malloc(bytes);
}

Other overflow builtins could include __[s|u][add|sub|mul][16|32|64].

These builtins are convenient to use and less error-prone, compared to popular
ad-hoc checks such as (size && n > SIZE_MAX / size).

LLVM (esp. instcombine) doesn't recognize such ad-hoc checking patterns,
either, and generates code using div rather than a simple jno.  These builtins
could be easily lowered to the LLVM overflow intrinsics llvm.*.with.overflow.*
for better code generation.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list