1 // Check that a stack unwinding algorithm works corretly even with the assembly
2 // instrumentation.
3
4 // REQUIRES: x86_64-target-arch
5 // RUN: %clangxx_asan -g -O1 %s -fno-inline-functions -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -mllvm -asan-instrument-assembly -o %t && not %run %t 2>&1 | FileCheck %s
6 // RUN: %clangxx_asan -g -O1 %s -fno-inline-functions -fomit-frame-pointer -momit-leaf-frame-pointer -mllvm -asan-instrument-assembly -o %t && not %run %t 2>&1 | FileCheck %s
7 // RUN: %clangxx_asan -g0 -O1 %s -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-exceptions -fno-inline-functions -fomit-frame-pointer -momit-leaf-frame-pointer -mllvm -asan-instrument-assembly -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nounwind
8
9 #include <cstddef>
10
11 // CHECK: READ of size 4
12 // CHECK-NEXT: {{#0 0x[0-9a-fA-F]+ in foo}}
13 // CHECK-NEXT: {{#1 0x[0-9a-fA-F]+ in main}}
14
15 // CHECK-nounwind: READ of size 4
16 // CHECK-nounwind-NEXT: {{#0 0x[0-9a-fA-F]+ in foo}}
17
foo(size_t n,int * buffer)18 __attribute__((noinline)) int foo(size_t n, int *buffer) {
19 int r;
20 __asm__("movl (%[buffer], %[n], 4), %[r] \n\t"
21 : [r] "=r"(r)
22 : [buffer] "r"(buffer), [n] "r"(n)
23 : "memory");
24 return r;
25 }
26
main()27 int main() {
28 const size_t n = 16;
29 int *buffer = new int[n];
30 foo(n, buffer);
31 delete[] buffer;
32 return 0;
33 }
34