Skip to content

Commit e7be51f

Browse files
authored
[SjLj] Add test for when setjmp is within a loop (#16112)
1 parent 611b14a commit e7be51f

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

tests/core/test_setjmp_within_loop.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <setjmp.h>
2+
#include <stdio.h>
3+
4+
static jmp_buf buf;
5+
6+
void a() { printf("a\n"); }
7+
void b() { printf("b\n"); }
8+
void c() { printf("c\n"); }
9+
int d() {
10+
static int first = 1;
11+
if (first) {
12+
first = 0;
13+
printf("d\n");
14+
return 1;
15+
}
16+
return 0;
17+
}
18+
19+
int n = 3;
20+
21+
int main() {
22+
while (n-- > 0) {
23+
a();
24+
if (setjmp(buf))
25+
b();
26+
else
27+
c();
28+
}
29+
if (d())
30+
longjmp(buf, 3);
31+
return 0;
32+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
a
2+
c
3+
a
4+
c
5+
a
6+
c
7+
d
8+
b

tests/test_core.py

+4
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,10 @@ def test_setjmp_many_2(self):
11421142
def test_setjmp_noleak(self):
11431143
self.do_runf(test_file('core/test_setjmp_noleak.c'), 'ok.')
11441144

1145+
@with_both_eh_sjlj
1146+
def test_setjmp_within_loop(self):
1147+
self.do_core_test('test_setjmp_within_loop.c')
1148+
11451149
@with_both_eh_sjlj
11461150
def test_exceptions(self):
11471151
self.set_setting('EXCEPTION_DEBUG')

0 commit comments

Comments
 (0)