1 //===-- Unittests for setjmp and longjmp ----------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/setjmp/longjmp.h"
10 #include "src/setjmp/setjmp_impl.h"
11 #include "test/UnitTest/Test.h"
14 constexpr int MAX_LOOP
= 123;
16 void jump_back(int n
) {
17 __llvm_libc::longjmp(buf
, n
); // Will return |n| out of setjmp
20 TEST(LlvmLibcSetJmpTest
, SetAndJumpBack
) {
21 // Local variables in setjmp scope should be declared volatile.
23 // The first time setjmp is called, it should return 0.
24 // Subsequent calls will return the value passed to jump_back below.
25 if (__llvm_libc::setjmp(buf
) <= MAX_LOOP
) {
29 ASSERT_EQ(n
, MAX_LOOP
+ 1);