[PATCH] D34753: [Support] - Add bad alloc error handler for handling allocation malfunctions

Klaus Kretzschmar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 7 07:51:46 PDT 2017


kkretzsch reclaimed this revision.
kkretzsch added a comment.

>>>! In https://reviews.llvm.org/D34753#799802, @MatzeB wrote:
>>  Specifically about this patch: So a failing malloc would now call the handler, but a failing `new` would throw an exception (or more likely `abort()` in the default no-exceptions configuration of LLVM. Maybe we should rather: Use `new` instead of `malloc` wherever possible. I'm not sure why this particular code uses malloc at all? For the cases that still use `malloc` (only good reason I can think of would be using `realloc` later) maybe we can trigger the same C++ exception as a failing new?
> 
> Good idea. I'll run through our malloc patches and check where I can replace the mallocs . So a new bad alloc handler is not necessary anymore, so I'm closing this patch request.

SmallPtrsSet and SmallVector uses realloc which means that the mallocs and frees in that code cannot be replaced with global operator new/delete.  Coming back to your original comment, overriding the global ::operator new in a way that it calls the bad alloc handler in case of OOM would create a consistent behaviour between the malloc/realloc/calloc familiy and global ::operator new.


https://reviews.llvm.org/D34753





More information about the llvm-commits mailing list