[llvm-bugs] [Bug 52134] New: The result of malloc(-1) is not as expected

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 11 04:35:06 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=52134

            Bug ID: 52134
           Summary: The result of malloc(-1) is not as expected
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: 499537630 at qq.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

test as:
int main(void) {
  void *p;

  p = malloc (-1);
  if (p != NULL) {
    return 1;
  }
  return 0;
}

$clang test.c -O2 && ./a.out

It's always return 1, but as we know p is null as expected?

No matter how much memory is malloced, it's always true.

Inst Combiner replace %cmp = icmp ne i8* @malloc(i32 -1)
with i1 true directly.

-- 
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/20211011/6bb6483f/attachment-0001.html>


More information about the llvm-bugs mailing list