[llvm-commits] CVS: llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/FarJump.c Looping.c Makefile MultipleSetjmp.c SimpleC++Test.cpp SimpleCTest.c WhileLoop.c
Chris Lattner
lattner at cs.uiuc.edu
Thu Sep 11 14:07:03 PDT 2003
Changes in directory llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp:
FarJump.c added (r1.1)
Looping.c added (r1.1)
Makefile added (r1.1)
MultipleSetjmp.c added (r1.1)
SimpleC++Test.cpp added (r1.1)
SimpleCTest.c added (r1.1)
WhileLoop.c added (r1.1)
---
Log message:
Testcases for setjmp/longjmp support
---
Diffs of the changes:
Index: llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/FarJump.c
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/FarJump.c:1.1
*** /dev/null Thu Sep 11 14:06:53 2003
--- llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/FarJump.c Thu Sep 11 14:06:43 2003
***************
*** 0 ****
--- 1,61 ----
+ /*
+ * This tests that longjmp can jump from a function far down in the
+ * calling chain and past other, non-accepting setjmps.
+ */
+ #include <setjmp.h>
+ #include <stdio.h>
+
+ void quux(jmp_buf buf)
+ {
+ printf("Inside quux\n");
+ printf("Longjmping from quux: 927\n");
+ longjmp(buf, 927);
+ }
+
+ void qux(jmp_buf buf)
+ {
+ jmp_buf local_buf;
+
+ printf("Inside qux\n");
+
+ if (!setjmp(local_buf))
+ quux(buf);
+ else
+ printf("Error: Shouldn't be here in qux\n");
+ }
+
+ void baz(jmp_buf buf)
+ {
+ jmp_buf local_buf;
+
+ printf("Inside baz\n");
+
+ if (!setjmp(local_buf))
+ qux(buf);
+ else
+ printf("Error: Shouldn't be here in baz\n");
+ }
+
+ void bar(jmp_buf buf)
+ {
+ printf("Inside bar\n");
+ baz(buf);
+ }
+
+ void foo()
+ {
+ jmp_buf buf;
+
+ printf("Inside foo\n");
+
+ if (!setjmp(buf))
+ bar(buf);
+ else
+ printf("Returning from longjmp into foo\n");
+ }
+
+ int main()
+ {
+ foo();
+ return 0;
+ }
Index: llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/Looping.c
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/Looping.c:1.1
*** /dev/null Thu Sep 11 14:06:53 2003
--- llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/Looping.c Thu Sep 11 14:06:43 2003
***************
*** 0 ****
--- 1,15 ----
+ #include <setjmp.h>
+ #include <stdio.h>
+
+ int main()
+ {
+ jmp_buf buf;
+ unsigned i = 0;
+
+ if (setjmp(buf) < 10) {
+ printf("i == %u\n", i);
+ longjmp(buf, ++i);
+ }
+
+ return 0;
+ }
Index: llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/Makefile
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/Makefile:1.1
*** /dev/null Thu Sep 11 14:06:53 2003
--- llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/Makefile Thu Sep 11 14:06:43 2003
***************
*** 0 ****
--- 1,5 ----
+ # Programs/SingleSource/UnitTests/SetjmpLongjmp/Makefile
+
+ LEVEL = ../../../../..
+ include $(LEVEL)/test/Programs/SingleSource/Makefile.singlesrc
+
Index: llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/MultipleSetjmp.c
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/MultipleSetjmp.c:1.1
*** /dev/null Thu Sep 11 14:06:53 2003
--- llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/MultipleSetjmp.c Thu Sep 11 14:06:43 2003
***************
*** 0 ****
--- 1,26 ----
+ #include <setjmp.h>
+ #include <stdio.h>
+
+ int bar(jmp_buf buf, int i)
+ {
+ printf("Inside bar %d\n", i);
+ longjmp(buf, i);
+ }
+
+ int main()
+ {
+ jmp_buf buf;
+ int ret;
+
+ if ((ret = setjmp(buf)) != 0) {
+ printf("returning from bar == %d\n", ret);
+
+ if ((ret = setjmp(buf)) != 0) {
+ printf("returning from bar == %d\n", ret);
+ } else {
+ bar(buf, 927);
+ }
+ } else {
+ bar(buf, 37);
+ }
+ }
Index: llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/SimpleC++Test.cpp
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/SimpleC++Test.cpp:1.1
*** /dev/null Thu Sep 11 14:06:53 2003
--- llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/SimpleC++Test.cpp Thu Sep 11 14:06:43 2003
***************
*** 0 ****
--- 1,36 ----
+ #include <csetjmp>
+ #include <cstdio>
+
+ class C {
+ const char *name;
+ public:
+ C(const char *n) : name(n) {}
+ ~C() { printf("Destroying C object in %s\n", name); }
+ };
+
+ void bar(jmp_buf buf)
+ {
+ printf("Inside bar\n");
+ longjmp(buf, 37);
+ }
+
+ void foo(jmp_buf buf)
+ {
+ C Obj("foo");
+ bar(buf);
+ }
+
+ int main()
+ {
+ C Obj("main");
+ jmp_buf buf;
+ int ret;
+
+ printf("Inside main\n");
+
+ if ((ret = setjmp(buf)) != 0) {
+ printf("ret == %d\n", ret);
+ } else {
+ foo(buf);
+ }
+ }
Index: llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/SimpleCTest.c
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/SimpleCTest.c:1.1
*** /dev/null Thu Sep 11 14:06:53 2003
--- llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/SimpleCTest.c Thu Sep 11 14:06:43 2003
***************
*** 0 ****
--- 1,23 ----
+ #include <setjmp.h>
+
+ void baz(jmp_buf buf)
+ {
+ printf("Inside baz\n");
+ longjmp(buf, 37);
+ }
+
+ int main()
+ {
+ jmp_buf buf;
+ int ret;
+
+ printf("Inside main\n");
+
+ if ((ret = setjmp(buf)) != 0) {
+ printf("ret == %d\n", ret);
+ } else {
+ baz(buf);
+ }
+
+ return 0;
+ }
Index: llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/WhileLoop.c
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/WhileLoop.c:1.1
*** /dev/null Thu Sep 11 14:06:53 2003
--- llvm/test/Programs/SingleSource/UnitTests/SetjmpLongjmp/WhileLoop.c Thu Sep 11 14:06:43 2003
***************
*** 0 ****
--- 1,24 ----
+ #include <setjmp.h>
+ #include <stdio.h>
+
+ void foo(jmp_buf buf, int i)
+ {
+ printf("Inside foo: %d\n", i);
+ longjmp(buf, i);
+ }
+
+ int main()
+ {
+ int i = 37;
+
+ while (i--) {
+ jmp_buf buf;
+ int ret;
+
+ if ((ret = setjmp(buf)) != 0) {
+ printf("Return from longjmp: %d\n", ret);
+ } else {
+ foo(buf, i);
+ }
+ }
+ }
More information about the llvm-commits
mailing list