summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc/execute/exceptions
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/objc/execute/exceptions
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/objc/execute/exceptions')
-rw-r--r--gcc/testsuite/objc/execute/exceptions/catchall-1.m77
-rw-r--r--gcc/testsuite/objc/execute/exceptions/exceptions.exp50
-rw-r--r--gcc/testsuite/objc/execute/exceptions/finally-1.m76
-rw-r--r--gcc/testsuite/objc/execute/exceptions/foward-1.m62
-rw-r--r--gcc/testsuite/objc/execute/exceptions/foward-1.x11
-rw-r--r--gcc/testsuite/objc/execute/exceptions/handler-1.m53
-rw-r--r--gcc/testsuite/objc/execute/exceptions/local-variables-1.m63
-rw-r--r--gcc/testsuite/objc/execute/exceptions/matcher-1.m68
-rw-r--r--gcc/testsuite/objc/execute/exceptions/pr31281.m27
-rw-r--r--gcc/testsuite/objc/execute/exceptions/throw-nil.m50
-rw-r--r--gcc/testsuite/objc/execute/exceptions/trivial.m19
11 files changed, 556 insertions, 0 deletions
diff --git a/gcc/testsuite/objc/execute/exceptions/catchall-1.m b/gcc/testsuite/objc/execute/exceptions/catchall-1.m
new file mode 100644
index 000000000..2db40a854
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/catchall-1.m
@@ -0,0 +1,77 @@
+/* Test out '@catch(id foo) {...}', which should catch all uncaught
+ exceptions. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#import "../../../objc-obj-c++-shared/Object1.h"
+
+/* The following is not required in actual user code; we include it
+ here to check that the compiler generates an internal definition of
+ _setjmp that is consistent with what <setjmp.h> provides. */
+#include <setjmp.h>
+
+#define CHECK_IF(expr) if(!(expr)) abort()
+
+@interface Frob: Object
+@end
+
+@implementation Frob: Object
+@end
+
+static Frob* _connection = nil;
+
+//--------------------------------------------------------------------
+
+
+void test (Object* sendPort)
+{
+ int cleanupPorts = 1;
+ Frob* receivePort = nil;
+
+ @try {
+ printf ("receivePort = %p\n", receivePort);
+ printf ("sendPort = %p\n", sendPort);
+ printf ("cleanupPorts = %d\n", cleanupPorts);
+ printf ("---\n");
+
+ receivePort = (Frob *) -1;
+ _connection = (Frob *) -1;
+ printf ("receivePort = %p\n", receivePort);
+ printf ("sendPort = %p\n", sendPort);
+ printf ("cleanupPorts = %d\n", cleanupPorts);
+ printf ("---\n");
+
+ receivePort = nil;
+ sendPort = nil;
+ cleanupPorts = 0;
+
+ printf ("receivePort = %p\n", receivePort);
+ printf ("sendPort = %p\n", sendPort);
+ printf ("cleanupPorts = %d\n", cleanupPorts);
+ printf ("---\n");
+
+ @throw [Object new];
+ }
+ @catch(Frob *obj) {
+ printf ("Exception caught by incorrect handler!\n");
+ CHECK_IF(0);
+ }
+ @catch(id exc) {
+ printf ("Exception caught by correct handler.\n");
+ printf ("receivePort = %p (expected 0x0)\n", receivePort);
+ printf ("sendPort = %p (expected 0x0)\n", sendPort);
+ printf ("cleanupPorts = %d (expected 0)\n", cleanupPorts);
+ printf ("---");
+ CHECK_IF(!receivePort);
+ CHECK_IF(!sendPort);
+ CHECK_IF(!cleanupPorts);
+ }
+}
+
+int main (void) {
+
+ test((Object *)-1);
+ return 0;
+}
+#import "../../../objc-obj-c++-shared/Object1-implementation.h"
diff --git a/gcc/testsuite/objc/execute/exceptions/exceptions.exp b/gcc/testsuite/objc/execute/exceptions/exceptions.exp
new file mode 100644
index 000000000..0443ca130
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/exceptions.exp
@@ -0,0 +1,50 @@
+# Copyright (C) 1991, 1992, 1993, 1995, 1997, 2007, 2008, 2010
+# Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# This file was written by Rob Savoye. (rob@cygnus.com)
+# Modified by Ovidiu Predescu (ovidiu@aracnet.com)
+
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set additional_flags ""
+lappend additional_flags "-fobjc-exceptions"
+# load support procs
+load_lib objc-torture.exp
+load_lib torture-options.exp
+load_lib target-supports.exp
+
+torture-init
+objc-set-runtime-options "execute" "additional_flags=-fobjc-exceptions"
+set-torture-options $OBJC_TORTURE_OPTIONS $OBJC_RUNTIME_OPTIONS
+
+#
+# main test loop
+#
+
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.m]] {
+ # If we're only testing specific files and this isn't one of them, skip it.
+ if ![runtest_file_p $runtests $src] then {
+ continue
+ }
+
+ objc-torture-execute $src $additional_flags
+}
+
+torture-finish
diff --git a/gcc/testsuite/objc/execute/exceptions/finally-1.m b/gcc/testsuite/objc/execute/exceptions/finally-1.m
new file mode 100644
index 000000000..370b19bb5
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/finally-1.m
@@ -0,0 +1,76 @@
+#include <stdio.h>
+#include <stdlib.h>
+//#import "../../../objc-obj-c++-shared/Object1.h"
+#ifdef __OBJC2__
+#include <objc/runtime.h>
+@interface Object
++ initialize;
++ new;
+- free;
+@end
+@implementation Object
++ initialize { return self; }
++ new { return class_createInstance (self, 0); }
+- free { return object_dispose(self);}
+@end
+
+#else
+#import "../../../objc-obj-c++-shared/Object1.h"
+#endif
+
+static int made_try = 0;
+
+int
+thrower_try_body()
+{
+ made_try++;
+ return (0);
+}
+
+static int made_finally = 0;
+
+int
+finally_body()
+{
+ made_finally++;
+ return (0);
+}
+
+int
+thrower()
+{
+ @try
+ {
+ thrower_try_body();
+ @throw [Object new];
+ }
+ @finally
+ {
+ finally_body();
+ }
+ return 0;
+}
+
+static int made_catch = 0;
+
+int
+main(int ac, char *av[])
+{
+ @try
+ {
+ thrower();
+ }
+ @catch (id exc)
+ {
+ made_catch++;
+ [exc free];
+ }
+ if (made_try != 1)
+ abort ();
+ if (made_finally != 1)
+ abort ();
+ if (made_catch != 1)
+ abort ();
+ return 0;
+}
+//#import "../../../objc-obj-c++-shared/Object1-implementation.h"
diff --git a/gcc/testsuite/objc/execute/exceptions/foward-1.m b/gcc/testsuite/objc/execute/exceptions/foward-1.m
new file mode 100644
index 000000000..6b31d7cc8
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/foward-1.m
@@ -0,0 +1,62 @@
+/* Check that throwing an exception from a -forward:: works. */
+/* Developed by Marcin Koziej <creep@desk.pl>. */
+
+#include <stdlib.h>
+#include <objc/Object.h>
+#ifndef __NEXT_RUNTIME__
+#import <objc/objc-api.h>
+#endif
+
+#ifdef __OBJC2__
+@interface Object (TEST_SUITE_ADDITIONS)
++ initialize;
++ alloc;
++ new;
+- init;
+- free;
+@end
+
+@implementation Object (TEST_SUITE_ADDITIONS)
++ initialize { return self; }
++ alloc { return class_createInstance (self, 0); }
++ new { return [[self alloc] init]; }
+- init { return self; }
+- free { return object_dispose(self); }
+@end
+#endif
+
+static int i;
+
+__attribute__((objc_exception))
+@interface Thrower : Object
+- forward: (SEL) s : (void*) a;
+@end
+
+@implementation Thrower
+- forward: (SEL) s : (void*) a
+{
+ i++;
+ @throw [Object new];
+ return nil;
+}
+@end
+
+int
+main()
+{
+ id t = [Thrower new];
+ @try
+ {
+ [t doesnotexist];
+ }
+ @catch (id error)
+ {
+ i++;
+ [error free];
+ }
+
+ if (i != 2)
+ abort ();
+
+ return 0;
+}
diff --git a/gcc/testsuite/objc/execute/exceptions/foward-1.x b/gcc/testsuite/objc/execute/exceptions/foward-1.x
new file mode 100644
index 000000000..9acd2737a
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/foward-1.x
@@ -0,0 +1,11 @@
+# XFAIL the run for m64 Darwin NeXT (seems to be a system runtime lib problem).
+if { [istarget *-*-darwin*] && [check_effective_target_lp64] } {
+ set torture_eval_before_execute {
+ global compiler_conditional_xfail_data
+ set compiler_conditional_xfail_data {
+ "Target fails for fnext-runtime" "*-*-*" { "-fnext-runtime" } { "" }
+ }
+ }
+}
+# carry on...
+return false
diff --git a/gcc/testsuite/objc/execute/exceptions/handler-1.m b/gcc/testsuite/objc/execute/exceptions/handler-1.m
new file mode 100644
index 000000000..ab2fe8c53
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/handler-1.m
@@ -0,0 +1,53 @@
+/* Test custom exception handlers */
+/* Author: David Ayers */
+
+#ifdef __NEXT_RUNTIME__
+/* This test only runs for the GNU runtime. TODO: It should work on
+ the NEXT runtime as well (needs testing).
+ */
+
+int main(void)
+{
+ return 0;
+}
+
+#else
+
+#include <objc/objc-api.h>
+#include <objc/objc-exception.h>
+#include <objc/Object.h>
+#include <stdlib.h>
+
+static unsigned int handlerExpected = 0;
+
+void
+my_exception_handler(id excp)
+{
+ /* Returning from the handler would abort. */
+ if (handlerExpected)
+ exit(0);
+
+ abort();
+}
+
+int
+main(int argc, char *argv[])
+{
+ objc_setUncaughtExceptionHandler (my_exception_handler);
+
+ @try
+ {
+ @throw [Object new];
+ }
+ @catch (id exc)
+ {
+ handlerExpected = 1;
+ }
+
+ @throw [Object new];
+ abort();
+ return 0;
+}
+
+
+#endif
diff --git a/gcc/testsuite/objc/execute/exceptions/local-variables-1.m b/gcc/testsuite/objc/execute/exceptions/local-variables-1.m
new file mode 100644
index 000000000..0488d792d
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/local-variables-1.m
@@ -0,0 +1,63 @@
+/* Check that local variables that get modified inside the @try
+ block survive until the @catch block is reached. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>. */
+
+#include <stdlib.h>
+#include <stdio.h>
+#import "../../../objc-obj-c++-shared/Object1.h"
+
+int gi1 = 9, gi2 = 19;
+float gf1 = 9.0, gf2 = 19.0;
+id obj2 = nil;
+
+void foo (int arg1, float *arg2)
+{
+ int *pi = &gi1;
+ float *pf = &gf1;
+ id obj1 = nil;
+ int local1 = 45, local2 = 47;
+ float local3 = 3.0, local4 = 4.0;
+ register int local5 = 15;
+ static float local6 = 16.0;
+
+ @try {
+ local1 = 123;
+ local2 = 345;
+ local3 = 5.0;
+ local4 = 6.0;
+ local5 = 17;
+ local6 = 18.0;
+ pi = &gi2;
+ pf = &gf2;
+ obj2 = obj1 = [Object new];
+ arg1 = 17;
+ arg2 = &gf2;
+
+ @throw [Object new];
+ }
+ @catch (Object *obj) {
+ if (local1 != 123 || local2 != 345 || local3 != 5.0 || local4 != 6.0
+ || local5 != 17 || local6 != 18.0) {
+ printf("Abort 1\n");
+ abort();
+ }
+ if(pi != &gi2 || pf != &gf2) {
+ printf("Abort 2\n");
+ abort();
+ }
+ if(!obj1 || obj1 != obj2) {
+ printf("Abort 3\n");
+ abort();
+ }
+ if(arg1 != 17 || arg2 != &gf2) {
+ printf("Abort 4\n");
+ abort();
+ }
+ }
+}
+
+int main(void) {
+ foo(15, &gf1);
+ return 0;
+}
+#import "../../../objc-obj-c++-shared/Object1-implementation.h"
diff --git a/gcc/testsuite/objc/execute/exceptions/matcher-1.m b/gcc/testsuite/objc/execute/exceptions/matcher-1.m
new file mode 100644
index 000000000..ef0b627da
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/matcher-1.m
@@ -0,0 +1,68 @@
+/* Test custom exception matchers */
+/* Author: Nicola Pero */
+
+#ifdef __NEXT_RUNTIME__
+/* This test only runs for the GNU runtime. TODO: It should work on
+ the NEXT runtime as well (needs testing).
+ */
+
+int main(void)
+{
+ return 0;
+}
+
+#else
+
+#include <objc/objc-api.h>
+#include <objc/objc-exception.h>
+#include <objc/Object.h>
+#include <stdlib.h>
+
+static unsigned int handlerExpected = 0;
+
+void
+my_exception_matcher(Class match_class, id exception)
+{
+ /* Always matches. */
+ return 1;
+}
+
+@interface A : Object
+@end
+
+@implementation A
+@end
+
+@interface B : Object
+@end
+
+@implementation B
+@end
+
+int
+main(int argc, char *argv[])
+{
+ objc_setExceptionMatcher (my_exception_matcher);
+
+ @try
+ {
+ @throw [A new];
+ }
+ @catch (B *exception)
+ {
+ /* Since we installed an exception matcher that always matches,
+ the exception should be sent here even if it's of class A and
+ this is looking for exceptions of class B.
+ */
+ return 0;
+ }
+ @catch (id exception)
+ {
+ abort ();
+ }
+
+ abort ();
+}
+
+
+#endif
diff --git a/gcc/testsuite/objc/execute/exceptions/pr31281.m b/gcc/testsuite/objc/execute/exceptions/pr31281.m
new file mode 100644
index 000000000..41e7a8e16
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/pr31281.m
@@ -0,0 +1,27 @@
+/* From PR31281. */
+extern void abort (void);
+int __attribute__((noinline))
+f(unsigned int i)
+{
+ int j, k;
+ @try { } @catch(id) { return 13; }
+ for (j=0; j<i; j++)
+ for (k=0; k<i; k++)
+ {
+ @try {
+ if (i)
+ break;
+ } @catch(id) { }
+ return 9;
+ }
+ return 0;
+}
+
+
+int
+main()
+{
+ if (f(1))
+ abort ();
+ return 0 ;
+}
diff --git a/gcc/testsuite/objc/execute/exceptions/throw-nil.m b/gcc/testsuite/objc/execute/exceptions/throw-nil.m
new file mode 100644
index 000000000..cd9a797f5
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/throw-nil.m
@@ -0,0 +1,50 @@
+#include <objc/objc.h>
+#include <objc/Object.h>
+
+#ifdef __NEXT_RUNTIME__
+/* This test only runs for the GNU runtime. */
+
+int main(void)
+{
+ return 0;
+}
+
+#else
+
+/* Test throwing a nil exception. A 'nil' exception can only be
+ caugth by a generic exception handler.
+ */
+
+int main (void)
+{
+ int exception_catched = 0;
+ int finally_called = 0;
+
+ @try
+ {
+ @throw nil;
+ }
+ @catch (Object *exc)
+ {
+ abort ();
+ }
+ @catch (id exc)
+ {
+ exception_catched = 1;
+ }
+ @finally
+ {
+ finally_called = 1;
+ }
+
+
+ if (exception_catched != 1
+ || finally_called != 1)
+ {
+ abort ();
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/gcc/testsuite/objc/execute/exceptions/trivial.m b/gcc/testsuite/objc/execute/exceptions/trivial.m
new file mode 100644
index 000000000..4e55e9d84
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/trivial.m
@@ -0,0 +1,19 @@
+#include <stdlib.h>
+#import "../../../objc-obj-c++-shared/Object1.h"
+
+/* do nothing except prove we can compile and link code calling the
+ ecceptions mechanism */
+
+int main(void)
+{
+ @try {
+ int a = 1 ;
+ @throw [Object new];
+ }
+ @catch (Object *obj) {
+ return 0;
+ }
+ abort();
+}
+
+#import "../../../objc-obj-c++-shared/Object1-implementation.h"