xref: /llvm-project/compiler-rt/test/asan/TestCases/Linux/clang_gcc_abi.cpp (revision 039126c97d39fbd8ca6a82f103db8f2591e793cd)
1*039126c9SAdhemerval Zanella // RUN: %clangxx_asan -O0 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
2*039126c9SAdhemerval Zanella // RUN: %clangxx_asan -O1 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
3*039126c9SAdhemerval Zanella // RUN: %clangxx_asan -O2 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
4*039126c9SAdhemerval Zanella // RUN: %clangxx_asan -O3 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
5673dc3d4SNico Weber 
6673dc3d4SNico Weber // REQUIRES: (arm-target-arch || armhf-target-arch), fast-unwinder-works
7673dc3d4SNico Weber 
8673dc3d4SNico Weber #include <stdlib.h>
9673dc3d4SNico Weber 
10673dc3d4SNico Weber __attribute__((noinline))
boom()11673dc3d4SNico Weber int boom() {
12673dc3d4SNico Weber   volatile int three = 3;
13673dc3d4SNico Weber   char * volatile s = (char *)malloc(three);
14673dc3d4SNico Weber // CHECK: #1 0x{{.*}} in boom {{.*}}clang_gcc_abi.cpp:[[@LINE-1]]
15673dc3d4SNico Weber   return s[three]; //BOOM
16673dc3d4SNico Weber }
17673dc3d4SNico Weber 
gcc_abi()18673dc3d4SNico Weber __attribute__((naked, noinline)) void gcc_abi() {
19673dc3d4SNico Weber // CHECK: #2 0x{{.*}} in gcc_abi {{.*}}clang_gcc_abi.cpp:[[@LINE+1]]
20673dc3d4SNico Weber   asm volatile("str fp, [sp, #-8]!\n\t"
21673dc3d4SNico Weber                "str lr, [sp, #4]\n\t"
22673dc3d4SNico Weber                "add fp, sp, #4\n\t"
23673dc3d4SNico Weber                "bl  boom\n\t"
24673dc3d4SNico Weber                "sub sp, fp, #4\n\t"
25673dc3d4SNico Weber                "ldr fp, [sp]\n\t"
26673dc3d4SNico Weber                "add sp, sp, #4\n\t"
27673dc3d4SNico Weber                "ldr pc, [sp], #4\n\t"
28673dc3d4SNico Weber               );
29673dc3d4SNico Weber }
30673dc3d4SNico Weber 
clang_abi()31673dc3d4SNico Weber __attribute__((naked, noinline)) void clang_abi() {
32673dc3d4SNico Weber // CHECK: #3 0x{{.*}} in clang_abi {{.*}}clang_gcc_abi.cpp:[[@LINE+1]]
33673dc3d4SNico Weber   asm volatile("push {r11, lr}\n\t"
34673dc3d4SNico Weber                "mov r11, sp\n\t"
35673dc3d4SNico Weber                "bl  gcc_abi\n\t"
36673dc3d4SNico Weber                "add r0, r0, #1\n\t"
37673dc3d4SNico Weber                "pop {r11, pc}\n\t"
38673dc3d4SNico Weber               );
39673dc3d4SNico Weber }
40673dc3d4SNico Weber 
main()41673dc3d4SNico Weber int main() {
42673dc3d4SNico Weber   clang_abi();
43673dc3d4SNico Weber // CHECK: #4 0x{{.*}} in main {{.*}}clang_gcc_abi.cpp:[[@LINE-1]]
44673dc3d4SNico Weber }
45