16d1862363c88c183b0ed7740fca876342cf0474bStephen Hines// Check that ASan correctly detects SEGV on the zero page.
26d1862363c88c183b0ed7740fca876342cf0474bStephen Hines// RUN: %clangxx_asan %s -o %t && not %run %t 2>&1 | FileCheck %s
36d1862363c88c183b0ed7740fca876342cf0474bStephen Hines
46d1862363c88c183b0ed7740fca876342cf0474bStephen Hinestypedef void void_f();
56d1862363c88c183b0ed7740fca876342cf0474bStephen Hinesint main() {
66d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  void_f *func = (void_f *)0x4;
76d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  func();
86d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  // x86 reports the SEGV with both address=4 and pc=4.
986277eb844c4983c81de62d7c050e92fe7155788Stephen Hines  // On PowerPC64 ELFv1, the pointer is taken to be a function-descriptor
1086277eb844c4983c81de62d7c050e92fe7155788Stephen Hines  // pointer out of which three 64-bit quantities are read. This will SEGV, but
1186277eb844c4983c81de62d7c050e92fe7155788Stephen Hines  // the compiler is free to choose the order. As a result, the address is
1286277eb844c4983c81de62d7c050e92fe7155788Stephen Hines  // either 0x4, 0xc or 0x14. The pc is still in main() because it has not
1386277eb844c4983c81de62d7c050e92fe7155788Stephen Hines  // actually made the call when the faulting access occurs.
1486277eb844c4983c81de62d7c050e92fe7155788Stephen Hines  // CHECK: {{AddressSanitizer: SEGV.*(address|pc) 0x0*[4c]}}
156d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  return 0;
166d1862363c88c183b0ed7740fca876342cf0474bStephen Hines}
17