[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / use-after-scope-setjmp.cpp
blob396a03d22bb863b70e051d74ad52ae57dbb402ab
1 // RUN: %clangxx_hwasan -mllvm -hwasan-use-stack-safety=0 -mllvm -hwasan-use-after-scope -O2 %s -o %t && \
2 // RUN: %run %t 2>&1
4 // REQUIRES: aarch64-target-arch
5 // REQUIRES: stable-runtime
7 #include <sanitizer/hwasan_interface.h>
8 #include <setjmp.h>
9 #include <stdlib.h>
10 #include <string.h>
12 #include <sys/types.h>
13 #include <unistd.h>
15 volatile const char *stackbuf = nullptr;
16 jmp_buf jbuf;
18 __attribute__((noinline)) bool jump() {
19 // Fool the compiler so it cannot deduce noreturn.
20 if (getpid() != 0) {
21 longjmp(jbuf, 1);
22 return true;
24 return false;
27 bool target() {
28 switch (setjmp(jbuf)) {
29 case 1:
30 return false;
31 default:
32 break;
35 while (true) {
36 char buf[4096];
37 stackbuf = buf;
38 if (!jump()) {
39 break;
42 return true;
45 int main() {
46 target();
48 void *untagged = __hwasan_tag_pointer(stackbuf, 0);
49 if (stackbuf == untagged) {
50 // The buffer wasn't tagged in the first place, so the test will not work
51 // as expected.
52 return 2;
54 if (__hwasan_test_shadow(untagged, 4096) != -1) {
55 return 1;
58 return 0;