[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / use-after-scope-setjmp.cpp
blobe9728704084a1b4b975044653beed4514e45d2a8
1 // RUN: %clangxx_hwasan -mllvm -hwasan-use-stack-safety=0 -O2 %s -o %t && \
2 // RUN: %run %t 2>&1
4 // REQUIRES: aarch64-target-arch || riscv64-target-arch
6 #include <sanitizer/hwasan_interface.h>
7 #include <setjmp.h>
8 #include <stdlib.h>
9 #include <string.h>
11 #include <sys/types.h>
12 #include <unistd.h>
14 volatile const char *stackbuf = nullptr;
15 jmp_buf jbuf;
17 __attribute__((noinline)) bool jump() {
18 // Fool the compiler so it cannot deduce noreturn.
19 if (getpid() != 0) {
20 longjmp(jbuf, 1);
21 return true;
23 return false;
26 bool target() {
27 switch (setjmp(jbuf)) {
28 case 1:
29 return false;
30 default:
31 break;
34 while (true) {
35 char buf[4096];
36 stackbuf = buf;
37 if (!jump()) {
38 break;
41 return true;
44 int main() {
45 target();
47 void *untagged = __hwasan_tag_pointer(stackbuf, 0);
48 if (stackbuf == untagged) {
49 // The buffer wasn't tagged in the first place, so the test will not work
50 // as expected.
51 return 2;
53 if (__hwasan_test_shadow(untagged, 4096) != -1) {
54 return 1;
57 return 0;