[LLVMbugs] [Bug 16868] New: warn on conditions that are too late to check for undefined behaviour

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Aug 12 20:32:50 PDT 2013


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

            Bug ID: 16868
           Summary: warn on conditions that are too late to check for
                    undefined behaviour
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nlewycky at google.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Examples:

bool test(int *p) {
  int i = *p;
  if (!p)
    return false;
  // ... continue using i
}

We should warn on the condition, because if the condition is ever true then
undefined behaviour must have already occurred. (Similarly on 'p' and the
condition being false.)

bool test2(int idx) {
  char arr[100];
  arr[idx] = '\0';
  if (idx < 0 || idx >= 100)  // either of these alone should also suffice to
warn
    return false;
  // ...
}

Examples putting the overflow inside the condition expression:

bool test3(int x) {
  if ((x+1) < x)
  ...

bool test4(int x, int y) {
  if (x != (x*y)/y)
  ...

-- 
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/20130813/167a31d5/attachment.html>


More information about the llvm-bugs mailing list