[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / try-catch.cpp
blob8e35a9dd2a5ff0f96eb3c9ddd72f480e46134fa4
1 // This test is broken with shared libstdc++ / libc++ on Android.
2 // RUN: %clangxx_hwasan -static-libstdc++ %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=GOOD
3 // RUN: %clangxx_hwasan -static-libstdc++ -DNO_SANITIZE_F %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=GOOD
4 // RUN: %clangxx_hwasan_oldrt -static-libstdc++ %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=GOOD
5 // RUN: %clangxx_hwasan_oldrt -static-libstdc++ %s -mllvm -hwasan-instrument-landing-pads=0 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=BAD
7 // C++ tests on x86_64 require instrumented libc++/libstdc++.
8 // REQUIRES: aarch64-target-arch
10 #include <stdexcept>
11 #include <cstdio>
13 static void optimization_barrier(void* arg) {
14 asm volatile("" : : "r"(arg) : "memory");
17 __attribute__((noinline))
18 void h() {
19 char x[1000];
20 optimization_barrier(x);
21 throw std::runtime_error("hello");
24 __attribute__((noinline))
25 void g() {
26 char x[1000];
27 optimization_barrier(x);
28 h();
29 optimization_barrier(x);
32 __attribute__((noinline))
33 void hwasan_read(char *p, int size) {
34 char volatile sink;
35 for (int i = 0; i < size; ++i)
36 sink = p[i];
39 __attribute__((noinline, no_sanitize("hwaddress"))) void after_catch() {
40 char x[10000];
41 hwasan_read(&x[0], sizeof(x));
45 __attribute__((noinline))
46 #ifdef NO_SANITIZE_F
47 __attribute__((no_sanitize("hwaddress")))
48 #endif
49 void f() {
50 char x[1000];
51 try {
52 // Put two tagged frames on the stack, throw an exception from the deepest one.
53 g();
54 } catch (const std::runtime_error &e) {
55 // Put an untagged frame on stack, check that it is indeed untagged.
56 // This relies on exception support zeroing out stack tags.
57 // BAD: tag-mismatch
58 after_catch();
59 // Check that an in-scope stack allocation is still tagged.
60 // This relies on exception support not zeroing too much.
61 hwasan_read(&x[0], sizeof(x));
62 // GOOD: hello
63 printf("%s\n", e.what());
67 int main() {
68 f();