[llvm] 55c365d - Add LLVM_ATTRIBUTE_NORETURN to report_bad_alloc_error
Aaron Puchert via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 9 08:46:10 PDT 2020
Author: Aaron Puchert
Date: 2020-06-09T17:45:12+02:00
New Revision: 55c365d247b1df358eddba5a98337c8ab9f1e7b0
URL: https://github.com/llvm/llvm-project/commit/55c365d247b1df358eddba5a98337c8ab9f1e7b0
DIFF: https://github.com/llvm/llvm-project/commit/55c365d247b1df358eddba5a98337c8ab9f1e7b0.diff
LOG: Add LLVM_ATTRIBUTE_NORETURN to report_bad_alloc_error
Summary:
The attribute just means that there will be no regular return, it still
leaves room for exceptions to be thrown. It is easily verified: there
are no direct returns and the last statement is either a throw or a call
to abort.
Having the annotation helps static analyzers with this code from
Support/MemAlloc.h (slightly simplified):
LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_malloc(size_t Sz) {
void *Result = std::malloc(Sz);
if (Result == nullptr)
report_bad_alloc_error("Allocation failed");
return Result;
}
Were report_bad_alloc_error to return regularly, the function would
return nullptr, contradicting the attribute.
Reviewers: rnk, sepavloff, dblaikie, aaron.ballman
Reviewed By: dblaikie, aaron.ballman
Differential Revision: https://reviews.llvm.org/D81318
Added:
Modified:
llvm/include/llvm/Support/ErrorHandling.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h
index b4626facd22c..7cbc668b3a0e 100644
--- a/llvm/include/llvm/Support/ErrorHandling.h
+++ b/llvm/include/llvm/Support/ErrorHandling.h
@@ -103,8 +103,8 @@ void install_out_of_memory_new_handler();
/// Reports a bad alloc error, calling any user defined bad alloc
/// error handler. In contrast to the generic 'report_fatal_error'
-/// functions, this function is expected to return, e.g. the user
-/// defined error handler throws an exception.
+/// functions, this function might not terminate, e.g. the user
+/// defined error handler throws an exception, but it won't return.
///
/// Note: When throwing an exception in the bad alloc handler, make sure that
/// the following unwind succeeds, e.g. do not trigger additional allocations
@@ -113,7 +113,8 @@ void install_out_of_memory_new_handler();
/// If no error handler is installed (default), then a bad_alloc exception
/// is thrown, if LLVM is compiled with exception support, otherwise an
/// assertion is called.
-void report_bad_alloc_error(const char *Reason, bool GenCrashDiag = true);
+LLVM_ATTRIBUTE_NORETURN void report_bad_alloc_error(const char *Reason,
+ bool GenCrashDiag = true);
/// This function calls abort(), and prints the optional message to stderr.
/// Use the llvm_unreachable macro (that adds location info), instead of
More information about the llvm-commits
mailing list