Displaying 1 result from an estimated 1 matches for "malloc_array_2".
Did you mean:
malloc_array_1
2012 Aug 22
1
[LLVMdev] RFC: optimizing integer overflow checks
.../3429064
https://gist.github.com/3429069
Here goes an example.
$ cat t.c
#include <stdlib.h>
#include <stdint.h>
void *malloc_array_1(size_t n, size_t size)
{
if (size && n > SIZE_MAX / size)
return NULL;
return malloc(n * size);
}
void *malloc_array_2(size_t n, size_t size)
{
size_t bytes = n * size;
if (size && n != bytes / size)
return NULL;
return malloc(bytes);
}
$ clang -emit-llvm -S -o - t.c | opt -S -mem2reg -simplifycfg -overflow-idiom -simplifycfg -sink -overflow-combine -adce
define i8*...