33 lines · cpp
1// Check that ASan correctly detects SEGV on the zero page.2// RUN: %clangxx_asan %s -o %t && not %run %t 2>&1 | FileCheck %s3 4// Handled as a codesigning violation and exits with SIGKILL not SEGV5// UNSUPPORTED: ios6 7 8#if defined(_MSC_VER) && !defined(__CLANG__)9# define __has_feature(x) 010#endif11 12#if __has_feature(ptrauth_calls)13# include <ptrauth.h>14#endif15 16typedef void void_f();17int main() {18 void_f *func = (void_f *)0x4;19#if __has_feature(ptrauth_calls)20 func = ptrauth_sign_unauthenticated(21 func, ptrauth_key_function_pointer, 0);22#endif23 func();24 // x86 reports the SEGV with both address=4 and pc=4.25 // On PowerPC64 ELFv1, the pointer is taken to be a function-descriptor26 // pointer out of which three 64-bit quantities are read. This will SEGV, but27 // the compiler is free to choose the order. As a result, the address is28 // either 0x4, 0xc or 0x14. The pc is still in main() because it has not29 // actually made the call when the faulting access occurs.30 // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) 0x0*[45c]}}31 return 0;32}33