llvm.org GIT mirror llvm / 7abddda
Optimizing to calloc() to malloc() + memset() can be bad on some platforms. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26732 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 13 years ago
1 changed file(s) with 0 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
+0
-33
runtime/GCCLibraries/libc/memory.c less more
None //===-- memory.c - String functions for the LLVM libc Library ----*- C -*-===//
1 //
2 // A lot of this code is ripped gratuitously from glibc and libiberty.
3 //
4 //===---------------------------------------------------------------------===//
5
6 #include
7
8 // If we're not being compiled with GCC, turn off attributes. Question is how
9 // to handle overriding of memory allocation functions in that case.
10 #ifndef __GNUC__
11 #define __attribute__(X)
12 #endif
13
14 // For now, turn off the weak linkage attribute on Mac OS X.
15 #if defined(__GNUC__) && defined(__APPLE_CC__)
16 #define __ATTRIBUTE_WEAK__
17 #elif defined(__GNUC__)
18 #define __ATTRIBUTE_WEAK__ __attribute__((weak))
19 #else
20 #define __ATTRIBUTE_WEAK__
21 #endif
22
23 void *malloc(size_t) __ATTRIBUTE_WEAK__;
24 void free(void *) __ATTRIBUTE_WEAK__;
25 void *memset(void *, int, size_t) __ATTRIBUTE_WEAK__;
26 void *calloc(size_t nelem, size_t elsize) __ATTRIBUTE_WEAK__;
27
28 void *calloc(size_t nelem, size_t elsize) {
29 void *Result = malloc(nelem*elsize);
30 if (Result) memset(Result, 0, nelem*elsize);
31 return Result;
32 }