1673dc3d4SNico Weber // Check that ASan correctly detects SEGV on the zero page.
2673dc3d4SNico Weber // RUN: %clangxx_asan %s -o %t && not %run %t 2>&1 | FileCheck %s
3673dc3d4SNico Weber 
4*f26adaa2SEmily Shi #if __has_feature(ptrauth_calls)
5*f26adaa2SEmily Shi #  include <ptrauth.h>
6*f26adaa2SEmily Shi #endif
7*f26adaa2SEmily Shi 
8673dc3d4SNico Weber typedef void void_f();
main()9673dc3d4SNico Weber int main() {
10673dc3d4SNico Weber   void_f *func = (void_f *)0x4;
11*f26adaa2SEmily Shi #if __has_feature(ptrauth_calls)
12*f26adaa2SEmily Shi   func = ptrauth_sign_unauthenticated(
13*f26adaa2SEmily Shi       func, ptrauth_key_function_pointer, 0);
14*f26adaa2SEmily Shi #endif
15673dc3d4SNico Weber   func();
16673dc3d4SNico Weber   // x86 reports the SEGV with both address=4 and pc=4.
17673dc3d4SNico Weber   // On PowerPC64 ELFv1, the pointer is taken to be a function-descriptor
18673dc3d4SNico Weber   // pointer out of which three 64-bit quantities are read. This will SEGV, but
19673dc3d4SNico Weber   // the compiler is free to choose the order. As a result, the address is
20673dc3d4SNico Weber   // either 0x4, 0xc or 0x14. The pc is still in main() because it has not
21673dc3d4SNico Weber   // actually made the call when the faulting access occurs.
22673dc3d4SNico Weber   // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) 0x0*[4c]}}
23673dc3d4SNico Weber   return 0;
24673dc3d4SNico Weber }
25