From 6347cf3119969c89259c269f8eba9c267ff098b8 Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Wed, 8 Dec 2010 23:46:28 +0000 Subject: [PATCH] In gcc/objc/: 2010-12-08 Nicola Pero In gcc/objc/: 2010-12-08 Nicola Pero * objc-act.c (objc_build_throw_stmt): Check that the argument of @throw is an object and emit an error if not. In gcc/testsuite/: 2010-12-08 Nicola Pero * objc.dg/exceptions-7.m: New. * obj-c++.dg/exceptions-7.mm: New. * obj-c++.dg/exceptions-3.mm: Adjust for new C++ messages. * obj-c++.dg/exceptions-5.mm: Same change. From-SVN: r167615 --- gcc/objc/ChangeLog | 5 +++++ gcc/objc/objc-act.c | 8 ++++++++ gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/obj-c++.dg/exceptions-3.mm | 4 ++-- gcc/testsuite/obj-c++.dg/exceptions-5.mm | 3 ++- gcc/testsuite/obj-c++.dg/exceptions-7.mm | 18 ++++++++++++++++++ gcc/testsuite/objc.dg/exceptions-7.m | 18 ++++++++++++++++++ 7 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/obj-c++.dg/exceptions-7.mm create mode 100644 gcc/testsuite/objc.dg/exceptions-7.m diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 09977270e2f..09cc1f6f984 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,8 @@ +2010-12-08 Nicola Pero + + * objc-act.c (objc_build_throw_stmt): Check that the argument of + @throw is an object and emit an error if not. + 2010-12-08 Nicola Pero * objc-act.c (objc_finish_foreach_loop): Use error_at() instead of diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index f760aad700a..1b815df7b61 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -5528,6 +5528,14 @@ objc_build_throw_stmt (location_t loc, tree throw_expr) value that we get from the runtime. */ throw_expr = objc_build_exc_ptr (); } + else if (throw_expr != error_mark_node) + { + if (!objc_type_valid_for_messaging (TREE_TYPE (throw_expr), true)) + { + error_at (loc, "%<@throw%> argument is not an object"); + return error_mark_node; + } + } /* A throw is just a call to the runtime throw function with the object as a parameter. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c7e0e21769e..cdddb9a9982 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2010-12-08 Nicola Pero + + * objc.dg/exceptions-7.m: New. + * obj-c++.dg/exceptions-7.mm: New. + * obj-c++.dg/exceptions-3.mm: Adjust for new C++ messages. + * obj-c++.dg/exceptions-5.mm: Same change. + 2010-12-08 Nicola Pero * objc.dg/foreach-6.m: Updated location of error messages. diff --git a/gcc/testsuite/obj-c++.dg/exceptions-3.mm b/gcc/testsuite/obj-c++.dg/exceptions-3.mm index b1ba1852725..adae263790f 100644 --- a/gcc/testsuite/obj-c++.dg/exceptions-3.mm +++ b/gcc/testsuite/obj-c++.dg/exceptions-3.mm @@ -72,8 +72,8 @@ int test (id object) @catch (MyObject x) /* { dg-error "@catch parameter is not a known Objective-C class type" } */ { /* { dg-error "no matching function" "" { target *-*-* } 72 } */ dummy++; /* { dg-warning "MyObject" "" { target *-*-* } 13 } */ - } - + } /* { dg-warning "candidate" "" { target *-*-* } 13 } */ + /* { dg-warning "candidate" "" { target *-*-* } 72 } */ @try { @throw object; } @catch (static MyObject *x) /* { dg-error "storage class" } */ { diff --git a/gcc/testsuite/obj-c++.dg/exceptions-5.mm b/gcc/testsuite/obj-c++.dg/exceptions-5.mm index f7404968844..ba0e543e98a 100644 --- a/gcc/testsuite/obj-c++.dg/exceptions-5.mm +++ b/gcc/testsuite/obj-c++.dg/exceptions-5.mm @@ -72,7 +72,8 @@ int test (id object) @catch (MyObject) /* { dg-error "@catch parameter is not a known Objective-C class type" } */ { /* { dg-error "no matching function" "" { target *-*-* } 72 } */ dummy++; /* { dg-warning "MyObject" "" { target *-*-* } 13 } */ - } + } /* { dg-warning "candidate" "" { target *-*-* } 13 } */ + /* { dg-warning "candidate" "" { target *-*-* } 72 } */ @try { @throw object; } @catch (static MyObject *) /* { dg-error "storage class" } */ diff --git a/gcc/testsuite/obj-c++.dg/exceptions-7.mm b/gcc/testsuite/obj-c++.dg/exceptions-7.mm new file mode 100644 index 00000000000..1f5adfc8906 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/exceptions-7.mm @@ -0,0 +1,18 @@ +/* Contributed by Nicola Pero , December 2010. */ +/* { dg-options "-fobjc-exceptions" } */ +/* { dg-do compile } */ + +/* Test warnings when the argument of @throw is invalid. */ + +#include + +void test (id object) +{ + struct x { int i; } invalid_1, *invalid_2; + + @throw object; /* Ok */ + @throw 1; /* { dg-error ".@throw. argument is not an object" } */ + @throw "string"; /* { dg-error ".@throw. argument is not an object" } */ + @throw invalid_1; /* { dg-error ".@throw. argument is not an object" } */ + @throw invalid_2; /* { dg-error ".@throw. argument is not an object" } */ +} diff --git a/gcc/testsuite/objc.dg/exceptions-7.m b/gcc/testsuite/objc.dg/exceptions-7.m new file mode 100644 index 00000000000..1f5adfc8906 --- /dev/null +++ b/gcc/testsuite/objc.dg/exceptions-7.m @@ -0,0 +1,18 @@ +/* Contributed by Nicola Pero , December 2010. */ +/* { dg-options "-fobjc-exceptions" } */ +/* { dg-do compile } */ + +/* Test warnings when the argument of @throw is invalid. */ + +#include + +void test (id object) +{ + struct x { int i; } invalid_1, *invalid_2; + + @throw object; /* Ok */ + @throw 1; /* { dg-error ".@throw. argument is not an object" } */ + @throw "string"; /* { dg-error ".@throw. argument is not an object" } */ + @throw invalid_1; /* { dg-error ".@throw. argument is not an object" } */ + @throw invalid_2; /* { dg-error ".@throw. argument is not an object" } */ +}