-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EH/SjLj] Add tests for mixing exceptions and sjlj (#14732)
This adds three tests for mixing exceptions and sjlj. We currently pass `test_exceptions_longjmp1`, and other two tests will pass after llvm/llvm-project@c285a11. - `test_exceptions_longjmp1` In a function with a `setjmp` call, `invoke` exists in LLVM IR. We have to check both for EH and sjlj when a function throws. - `test_exceptions_longjmp2` In a function without a `setjmp` call, `invoke` exists in LLVM IR. We only have to handle exceptions, but when longjmps occur, we shouldn't swallow them. - `test_exceptions_longjmp3` In a function with a `setjmp` call, there's no `invoke` in LLVM IR. We only have to handle longjmps, but w hen an exceptions occcur, we shouldn't swallow them. Each of these tests corresponds with tests in test/CodeGen/WebAssembly/lower-em-sjlj.ll in llvm/llvm-project@c285a11.
- Loading branch information
Showing
7 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <stdio.h> | ||
#include <setjmp.h> | ||
|
||
static jmp_buf buf; | ||
|
||
void foo() { | ||
longjmp(buf, 1); | ||
} | ||
|
||
int main() { | ||
int jmpval = setjmp(buf); | ||
if (jmpval != 0) { | ||
printf("setjmp returned for the second time\n"); | ||
return 0; | ||
} | ||
try { | ||
foo(); | ||
} catch (...) { | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
setjmp returned for the second time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <stdio.h> | ||
#include <setjmp.h> | ||
|
||
static jmp_buf buf; | ||
|
||
void foo() { | ||
longjmp(buf, 1); | ||
} | ||
|
||
void test() { | ||
try { | ||
foo(); | ||
} catch (...) { | ||
} | ||
} | ||
|
||
int main() { | ||
int jmpval = setjmp(buf); | ||
if (jmpval != 0) { | ||
printf("setjmp returned for second time\n"); | ||
return 0; | ||
} | ||
test(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
setjmp returned for second time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <stdio.h> | ||
#include <setjmp.h> | ||
|
||
static jmp_buf buf; | ||
|
||
void foo() { | ||
throw 3; | ||
} | ||
|
||
void test() { | ||
int jmpval = setjmp(buf); | ||
if (jmpval != 0) { | ||
printf("setjmp returned for 2nd time\n"); | ||
return; | ||
} | ||
foo(); | ||
} | ||
|
||
int main() { | ||
try { | ||
test(); | ||
} catch (int n) { | ||
printf("caught: %d\n", n); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
caught: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters