-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Support] Report OOM from allocate_buffer
#85449
Conversation
@llvm/pr-subscribers-llvm-support Author: Josh Stone (cuviper) ChangesPreviously, it called Ref: #85281 Full diff: https://github.com/llvm/llvm-project/pull/85449.diff 1 Files Affected:
diff --git a/llvm/lib/Support/MemAlloc.cpp b/llvm/lib/Support/MemAlloc.cpp
index 07a26cf26480b3..6adc9abd75c5b9 100644
--- a/llvm/lib/Support/MemAlloc.cpp
+++ b/llvm/lib/Support/MemAlloc.cpp
@@ -13,12 +13,15 @@
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void *
llvm::allocate_buffer(size_t Size, size_t Alignment) {
- return ::operator new(Size
+ void *Result = ::operator new(Size,
#ifdef __cpp_aligned_new
- ,
- std::align_val_t(Alignment)
+ std::align_val_t(Alignment),
#endif
- );
+ std::nothrow);
+ if (Result == nullptr) {
+ report_bad_alloc_error("Buffer allocation failed");
+ }
+ return Result;
}
void llvm::deallocate_buffer(void *Ptr, size_t Size, size_t Alignment) {
|
Previously, it called `::operator new` which may throw `std::bad_alloc`, regardless of whether LLVM itself was built with exception handling, and this can cause safety issues if outside code has destructors that will call back into LLVM. Now we use `::operator new(..., nothrow)` and call `llvm::report_bad_alloc_error` when allocation fails, which will abort when LLVM is built without exceptions. Ref: llvm#85281
fd9ddc5
to
24f1938
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems good, but could you run this through llvm-compile-time-tracker?
Ok, I'll look into that. |
Thanks @nikic! If we're good to go, please do merge it for me, as I don't have write access. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/13554 Here is the relevant piece of the build log for the reference
|
It doesn't make sense to me that this failure would have anything to do with my change. |
Previously, it called
::operator new
which may throwstd::bad_alloc
,regardless of whether LLVM itself was built with exception handling, and
this can cause safety issues if outside code has destructors that will
call back into LLVM. Now we use
::operator new(..., nothrow)
and callllvm::report_bad_alloc_error
when allocation fails, which will abortwhen LLVM is built without exceptions.
Ref: #85281