This change updates the Checked C tests so that they run properly on Apple ARM64 hardware running a recent version of MacOS. The changes consist of:

- Using SIGTRAP signal handlers catch runtime checking failures instead of SIGILL.
- Only run Linux-specific header file tests on Linux.
- Add a bounds-safe interface specific to MacOS so that errno work properly in a checked scope.

Testing:
check-checkedc passes on Windows x86 and MacOS 13.4.1
This commit is contained in:
David Tarditi 2023-07-18 22:57:44 -07:00 коммит произвёл GitHub
Родитель a37445f262
Коммит 9544bafa10
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
17 изменённых файлов: 104 добавлений и 55 удалений

Просмотреть файл

@ -24,7 +24,11 @@
#if defined(_WIN32) || defined(_WIN64)
__declspec(dllimport) int* __cdecl _errno(void) : itype(_Ptr<int>);
#elif defined(__APPLE__)
#if defined(__aarch64__)
extern int * __error(void) : itype(_Ptr<int>);
#else
extern int* __errno_location(void) : itype(_Ptr<int>);
#endif
#else
extern int* __errno_location(void) : itype(_Ptr<int>) __THROW __attribute_const__;
#endif

Просмотреть файл

@ -1,4 +1,4 @@
// UNSUPPORTED: system-windows
// UNSUPPORTED: !linux
//
// Test include files for all combinations of Checked C enabled/disabled,
// and implicit inclusion of checked headers enabled/disabled. By default, both

Просмотреть файл

@ -1,4 +1,4 @@
// UNSUPPORTED: system-windows
// UNSUPPORTED: !linux
//
// Test include files for all combinations of Checked C enabled/disabled,
// and implicit inclusion of checked headers enabled/disabled. By default, both

Просмотреть файл

@ -1,4 +1,4 @@
// UNSUPPORTED: system-windows
// UNSUPPORTED: !linux
//
// Test include files for all combinations of Checked C enabled/disabled,
// and implicit inclusion of checked headers enabled/disabled. By default, both

Просмотреть файл

@ -62,9 +62,12 @@ int write_fail(int testnum, int pos, ptr<struct S1> s, ptr<struct S3> s3);
int main(int argc, array_ptr<char*> argv : count(argc)) {
// Set up the handler for a failing bounds check. Currently the Checked C
// clang implementation raises a SIGILL when a bounds check fails. This
// may change in the future.
// clang implementation raises a SIGILL or SIGTRIP when a bounds check fails,
// dpending on the target OS. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// This makes sure output is not buffered for when
// we hit errors.

Просмотреть файл

@ -96,9 +96,12 @@ void read_test(int failure_point, int *p : count(p_len), int p_len,
int main(int argc, array_ptr<char*> argv : count(argc)) {
// Set up the handler for a failing bounds check. Currently the Checked C
// clang implementation raises a SIGILL when a bounds check fails. This
// may change in the future.
// clang implementation raises a SIGILL or SIGTRAP when a bounds check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// This makes sure output is not buffered for when
// we hit errors.

Просмотреть файл

@ -88,9 +88,12 @@ void handle_error(int err) {
int main(int argc, array_ptr<char*> argv : count(argc)) {
// Set up the handler for a failing bounds check. Currently the Checked C
// clang implementation raises a SIGILL when a bounds check fails. This
// may change in the future.
// clang implementation raises a SIGILL or SIGTRAP when a bounds check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// This makes sure output is not buffered for when
// we hit errors.

Просмотреть файл

@ -137,9 +137,12 @@ void handle_error(int err) {
int main(int argc, array_ptr<char*> argv : count(argc)) {
// Set up the handler for a failing bounds check. Currently the Checked C
// clang implementation raises a SIGILL when a bounds check fails. This
// may change in the future.
// clang implementation raises a SIGILL or SIGTRAP when a bounds check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// This makes sure output is not buffered for when
// we hit errors.

Просмотреть файл

@ -73,9 +73,12 @@ void handle_error(int err) {
int main(int argc, array_ptr<char*> argv : count(argc)) {
// Set up the handler for a failing bounds check. Currently the Checked C
// clang implementation raises a SIGILL when a bounds check fails. This
// may change in the future.
// clang implementation raises a SIGILL or SIGTRAP when a bounds check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// This makes sure output is not buffered for when
// we hit errors.

Просмотреть файл

@ -40,7 +40,13 @@ void fail1(int x) {
}
int main(int argc, array_ptr<char*> argv : count(argc)) {
// Set up the handler for a failing bounds check. Currently the Checked C
// clang implementation raises a SIGILL or SIGTRAP when a bounds check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// This makes sure output is not buffered for when
// we hit errors.

Просмотреть файл

@ -198,9 +198,12 @@ void handle_error(int err) {
int main(int argc, array_ptr<char*> argv : count(argc)) {
// Set up the handler for a failing bounds check. Currently the Checked C
// clang implementation raises a SIGILL when a bounds check fails. This
// may change in the future.
// clang implementation raises a SIGILL or SIGTRAP when a bounds check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// Unfortunately, using atoi everywhere below isn't super
// great, as it will return 0 if it can't parse, which is a valid,

Просмотреть файл

@ -740,9 +740,12 @@ void test_md_dependent_bounds(int argc, array_ptr<nt_array_ptr<char>> argv : cou
int main(int argc, array_ptr<nt_array_ptr<char>> argv : count(argc)) {
// Set up the handler for a failing bounds check. Currently the Checked C
// clang implementation raises a SIGILL when a bounds check fails. This
// may change in the future.
// clang implementation raises a SIGILL or SIGTRAP when a bounds check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// Unfortunately, using atoi everywhere below isn't super
// great, as it will return 0 if it can't parse, which is a valid,

Просмотреть файл

@ -123,9 +123,12 @@ void handle_error(int err) {
int main(int argc, array_ptr<char*> argv : count(argc)) {
// Set up the handler for a failing bounds check. Currently the Checked C
// clang implementation raises a SIGILL when a bounds check fails. This
// may change in the future.
// clang implementation raises a SIGILL or SIGTRAP when a bounds check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// This makes sure output is not buffered for when
// we hit errors.

Просмотреть файл

@ -44,9 +44,12 @@ void handle_error(int err) {
int main(int argc, char**_Array argv _Count(argc)) {
// Set up the handler for a failing bounds check. Currently the Checked C
// clang implementation raises a SIGILL when a bounds check fails. This
// may change in the future.
// clang implementation raises a SIGILL or SIGTRAP when a bounds check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// This makes sure output is not buffered for when
// we hit errors.

Просмотреть файл

@ -23,9 +23,13 @@ void handle_error(int err) {
}
int main(void) {
// Currently the Checked C clang implementation raises a SIGILL when a
// dynamic check fails. This may change in the future.
// Set up the handler for a failing dynamic check. Currently the Checked C
// clang implementation raises a SIGILL or SIGTRAP when a dynamic check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
f1(50);

Просмотреть файл

@ -2,6 +2,7 @@
//
// The following lines are for the LLVM test harness:
//
// RUN %clang -###
// RUN: %clang -Xclang -verify -o %t.exe %s %checkedc_target_flags
// RUN: %checkedc_rununder %t.exe
@ -15,9 +16,13 @@ void handle_error(int err) {
}
int main(void) {
// Currently the Checked C clang implementation raises a SIGILL when a
// dynamic check fails. This may change in the future.
// Set up the handler for a failing dynamic check. Currently the Checked C
// clang implementation raises a SIGILL or SIGTRAP when a dynamic check fails,
// depending on the target platform. This may change in the future.
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// This is expected fail at runtime. It is simple enough for clang to issue a warning
dynamic_check(false); // expected-warning {{dynamic check will always fail}}

Просмотреть файл

@ -128,6 +128,9 @@ void pass3() {
int main(int argc, array_ptr<char *> argv : count(argc)) {
signal(SIGILL, handle_error);
#if defined(__APPLE__) && defined(__aarch64__)
signal(SIGTRAP, handle_error);
#endif
// This makes sure output is not buffered for when
// we hit errors.