[llvm-bugs] [Bug 25892] New: [LIR] Misses opportunity to convert malloc + memset zero -> calloc

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 18 11:32:55 PST 2015


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

            Bug ID: 25892
           Summary: [LIR] Misses opportunity to convert malloc + memset
                    zero -> calloc
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: mcrosier at codeaurora.org
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

float *foo(int size) {
  float *fdata;
  fdata = (float *) malloc(size);
  if (fdata == NULL) {
    fprintf(stderr, "Can't allocate data array.\n");
    exit(1);
  }
  memset(fdata, 0, size);
  return fdata;
}

We should be able to convert the malloc into a calloc and remove the memset.

-- 
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/20151218/84b3a8a1/attachment.html>


More information about the llvm-bugs mailing list