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
13[[clang::xray_never_instrument]] __attribute__((weak)) __m128 f(__m128 *i) {
14 return *i;
15}
16
17[[clang::xray_always_instrument]] __attribute__((noinline)) void noarg() {
18 __m128 v = {};
19 f(i: &v);
20}
21
22[[ clang::xray_always_instrument, clang::xray_log_args(1) ]]
23__attribute__((noinline)) void arg1(int) {
24 __m128 v = {};
25 f(i: &v);
26}
27
28[[clang::xray_always_instrument]] __attribute__((noinline))
29void no_alignment() {}
30
31[[clang::xray_never_instrument]] void noarg_handler(int32_t,
32 XRayEntryType) {
33 printf(format: "noarg handler called\n");
34 __m128 v = {};
35 f(i: &v);
36}
37
38[[clang::xray_never_instrument]] void arg1_handler(int32_t, XRayEntryType,
39 uint64_t) {
40 printf(format: "arg1 handler called\n");
41 __m128 v = {};
42 f(i: &v);
43}
44
45int main(int argc, char *argv[]) {
46 __xray_set_handler(entry: noarg_handler);
47 __xray_set_handler_arg1(entry: 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

source code of compiler-rt/test/xray/TestCases/Posix/common-trampoline-alignment.cpp