[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / setjmp / setjmp_test.cpp
blob8fa915f841c21a14a20ff1a1b5200dfc9b065df5
1 //===-- Unittests for setjmp and longjmp ----------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/setjmp/longjmp.h"
10 #include "src/setjmp/setjmp_impl.h"
11 #include "test/UnitTest/Test.h"
13 jmp_buf buf;
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.
22 volatile int n = 0;
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) {
26 ++n;
27 jump_back(n);
29 ASSERT_EQ(n, MAX_LOOP + 1);