1 // Make sure that we're aligning the stack properly to support handlers that
2 // expect 16-byte alignment of the stack.
3 //
4 // RUN: %clangxx_xray -std=c++11 %s -o %t
5 // RUN: XRAY_OPTIONS="patch_premain=false verbosity=1" \
6 // RUN:     %run %t 2>&1
7 // REQUIRES: x86_64-target-arch
8 // REQUIRES: built-in-llvm-tree
9 #include "xray/xray_interface.h"
10 #include <stdio.h>
11 #include <xmmintrin.h>
12 
f(__m128 * i)13 [[clang::xray_never_instrument]] __attribute__((weak)) __m128 f(__m128 *i) {
14   return *i;
15 }
16 
noarg()17 [[clang::xray_always_instrument]] __attribute__((noinline)) void noarg() {
18   __m128 v = {};
19   f(&v);
20 }
21 
22 [[ clang::xray_always_instrument, clang::xray_log_args(1) ]]
arg1(int)23 __attribute__((noinline)) void arg1(int) {
24   __m128 v = {};
25   f(&v);
26 }
27 
28 [[clang::xray_always_instrument]] __attribute__((noinline))
no_alignment()29 void no_alignment() {}
30 
noarg_handler(int32_t,XRayEntryType)31 [[clang::xray_never_instrument]] void noarg_handler(int32_t,
32                                                         XRayEntryType) {
33   printf("noarg handler called\n");
34   __m128 v = {};
35   f(&v);
36 }
37 
arg1_handler(int32_t,XRayEntryType,uint64_t)38 [[clang::xray_never_instrument]] void arg1_handler(int32_t, XRayEntryType,
39                                                    uint64_t) {
40   printf("arg1 handler called\n");
41   __m128 v = {};
42   f(&v);
43 }
44 
main(int argc,char * argv[])45 int main(int argc, char *argv[]) {
46   __xray_set_handler(noarg_handler);
47   __xray_set_handler_arg1(arg1_handler);
48   __xray_patch();
49   noarg();    // CHECK: noarg handler called
50   arg1(argc); // CHECK: arg1 handler called
51   no_alignment();
52   __xray_unpatch();
53   __xray_remove_handler();
54   __xray_remove_handler_arg1();
55   noarg();
56   arg1(argc);
57 }
58