[libc] add noexcept to external function headers

To improve code generation for C++ code that directly includes our
headers, the external function definitions will now be marked noexcept.
This may not be necessary for the internal definitions since we build
with the -fno-exceptions flag.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D141095
This commit is contained in:
Michael Jones 2023-01-04 10:37:51 -08:00
parent eecce28ded
commit 9b8a64b88d
6 changed files with 12 additions and 8 deletions

View File

@ -18,7 +18,7 @@ def AssertMacro : MacroDef<"assert"> {
#ifdef __cplusplus
extern "C"
#endif
_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *);
_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;
#define assert(e) \
((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))

View File

@ -32,6 +32,9 @@
#undef _Thread_local
#define _Thread_local thread_local
#undef __NOEXCEPT
#define __NOEXCEPT noexcept
#else // not __cplusplus
#undef __BEGIN_C_DECLS
@ -43,6 +46,9 @@
#undef __restrict
#define __restrict restrict // C99 and above support the restrict keyword.
#undef __NOEXCEPT
#define __NOEXCEPT
#endif // __cplusplus
#endif // LLVM_LIBC___COMMON_H

View File

@ -14,7 +14,6 @@
#include <errno.h>
#include <limits.h>
#include <string.h>
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;

View File

@ -15,7 +15,6 @@
#include <errno.h>
#include <limits.h>
#include <string.h>
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;

View File

@ -81,7 +81,7 @@ bool TestGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &records) {
if (i < size - 1)
OS << ", ";
}
OS << "), decltype(" << entrypoint << ")>, ";
OS << ") __NOEXCEPT, decltype(" << entrypoint << ")>, ";
OS << '"' << entrypoint
<< " prototype in TableGen does not match public header" << '"';
OS << ");\n";
@ -93,9 +93,9 @@ bool TestGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &records) {
// We provide dummy malloc and free implementations to support the case
// when LLVM libc does to include them.
OS << "void *malloc(size_t) { return nullptr; }\n";
OS << "void *realloc(void *, size_t) { return nullptr; }\n";
OS << "void free(void *) {}\n";
OS << "void *malloc(size_t) __NOEXCEPT { return nullptr; }\n";
OS << "void *realloc(void *, size_t) __NOEXCEPT { return nullptr; }\n";
OS << "void free(void *) __NOEXCEPT {}\n";
return false;
}

View File

@ -112,7 +112,7 @@ void writeAPIFromIndex(APIIndexer &G,
OS << ", ";
}
OS << ");\n\n";
OS << ") __NOEXCEPT;\n\n";
}
// Make another pass over entrypoints to emit object declarations.