summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2010-09-28 17:58:55 +0000
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2010-09-28 17:58:55 +0000
commitea446b0bb9467cd9b535627d91601fec66fc9e69 (patch)
tree222e7d1bcfa9a85e0e42abfaa76ed4e639156e1f
parentc4bdb14e03dae134ad9a5d1e84d5facc62315841 (diff)
downloadgcc-ea446b0bb9467cd9b535627d91601fec66fc9e69.tar.gz
In gcc/objc/:
2010-09-28 Nicola Pero <nicola.pero@meta-innovation.com> Merge from 'apple/trunk' branch on FSF servers. 2005-08-23 Stuart Hastings <stuart@apple.com> Ziemowit Laski <zlaski@apple.com> Radar 4209854 * objc-act.c (objc_decay_parm_type): New function. (get_arg_type_list): Decay types for all named arguments. (objc_push_parm): Rebuild the PARM_DECL if its type has been decayed. In gcc/testsuite/: 2010-09-28 Nicola Pero <nicola.pero@meta-innovation.com> Merge from 'apple/trunk' branch on FSF servers (test method-20.m from the branch renamed to method-20b.m to avoid clashes). 2005-08-23 Stuart Hastings <stuart@apple.com> Ziemowit Laski <zlaski@apple.com> Radar 4209854 * obj-c++.dg/method-23.mm: New. * objc.dg/method-20.m: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164694 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/objc/ChangeLog13
-rw-r--r--gcc/objc/objc-act.c43
-rw-r--r--gcc/testsuite/ChangeLog12
-rw-r--r--gcc/testsuite/obj-c++.dg/method-23.mm43
-rw-r--r--gcc/testsuite/objc.dg/method-20b.m43
5 files changed, 135 insertions, 19 deletions
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog
index 5263b4060cd..65d61b1d0e1 100644
--- a/gcc/objc/ChangeLog
+++ b/gcc/objc/ChangeLog
@@ -1,3 +1,16 @@
+2010-09-28 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ Merge from 'apple/trunk' branch on FSF servers.
+
+ 2005-08-23 Stuart Hastings <stuart@apple.com>
+ Ziemowit Laski <zlaski@apple.com>
+
+ Radar 4209854
+ * objc-act.c (objc_decay_parm_type): New function.
+ (get_arg_type_list): Decay types for all named arguments.
+ (objc_push_parm): Rebuild the PARM_DECL if its type has
+ been decayed.
+
2010-09-28 Nicola Pero <nicola@nicola.brainstorm.co.uk>
* objc-act.c (encode_type): Fixed encoding enums with the next
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 8013252e6fe..8e6c6838edf 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -213,6 +213,7 @@ static void really_start_method (tree, tree);
static void really_start_method (tree, struct c_arg_info *);
#endif
static int comp_proto_with_proto (tree, tree, int);
+static tree objc_decay_parm_type (tree);
static void objc_push_parm (tree);
#ifdef OBJCPLUS
static tree objc_get_parm_info (int);
@@ -6108,11 +6109,8 @@ get_arg_type_list (tree meth, int context, int superflag)
{
tree arg_type = TREE_VALUE (TREE_TYPE (akey));
- /* Decay arrays and functions into pointers. */
- if (TREE_CODE (arg_type) == ARRAY_TYPE)
- arg_type = build_pointer_type (TREE_TYPE (arg_type));
- else if (TREE_CODE (arg_type) == FUNCTION_TYPE)
- arg_type = build_pointer_type (arg_type);
+ /* Decay argument types for the underlying C function as appropriate. */
+ arg_type = objc_decay_parm_type (arg_type);
chainon (arglist, build_tree_list (NULL_TREE, arg_type));
}
@@ -6124,6 +6122,8 @@ get_arg_type_list (tree meth, int context, int superflag)
{
tree arg_type = TREE_TYPE (TREE_VALUE (akey));
+ arg_type = objc_decay_parm_type (arg_type);
+
chainon (arglist, build_tree_list (NULL_TREE, arg_type));
}
@@ -8599,6 +8599,19 @@ encode_field_decl (tree field_decl, int curtype, int format)
encode_type (TREE_TYPE (field_decl), curtype, format);
}
+/* Decay array and function parameters into pointers. */
+
+static tree
+objc_decay_parm_type (tree type)
+{
+ if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == FUNCTION_TYPE)
+ type = build_pointer_type (TREE_CODE (type) == ARRAY_TYPE
+ ? TREE_TYPE (type)
+ : type);
+
+ return type;
+}
+
static GTY(()) tree objc_parmlist = NULL_TREE;
/* Append PARM to a list of formal parameters of a method, making a necessary
@@ -8607,7 +8620,7 @@ static GTY(()) tree objc_parmlist = NULL_TREE;
static void
objc_push_parm (tree parm)
{
- bool relayout_needed = false;
+ tree type;
if (TREE_TYPE (parm) == error_mark_node)
{
@@ -8616,20 +8629,12 @@ objc_push_parm (tree parm)
}
/* Decay arrays and functions into pointers. */
- if (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE)
- {
- TREE_TYPE (parm) = build_pointer_type (TREE_TYPE (TREE_TYPE (parm)));
- relayout_needed = true;
- }
- else if (TREE_CODE (TREE_TYPE (parm)) == FUNCTION_TYPE)
- {
- TREE_TYPE (parm) = build_pointer_type (TREE_TYPE (parm));
- relayout_needed = true;
- }
+ type = objc_decay_parm_type (TREE_TYPE (parm));
- if (relayout_needed)
- relayout_decl (parm);
-
+ /* If the parameter type has been decayed, a new PARM_DECL needs to be
+ built as well. */
+ if (type != TREE_TYPE (parm))
+ parm = build_decl (input_location, PARM_DECL, DECL_NAME (parm), type);
DECL_ARG_TYPE (parm)
= lang_hooks.types.type_promotes_to (TREE_TYPE (parm));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3de4bc015d4..6e54f4e78ee 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,15 @@
+2010-09-28 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ Merge from 'apple/trunk' branch on FSF servers (test method-20.m
+ from the branch renamed to method-20b.m to avoid clashes).
+
+ 2005-08-23 Stuart Hastings <stuart@apple.com>
+ Ziemowit Laski <zlaski@apple.com>
+
+ Radar 4209854
+ * obj-c++.dg/method-23.mm: New.
+ * objc.dg/method-20.m: New.
+
2010-09-28 Jan Hubicka <jh@suse.cz>
* gcc.dg/tree-ssa/foldconst-5.c: New testcase.
diff --git a/gcc/testsuite/obj-c++.dg/method-23.mm b/gcc/testsuite/obj-c++.dg/method-23.mm
new file mode 100644
index 00000000000..9b8625a9b17
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/method-23.mm
@@ -0,0 +1,43 @@
+/* Check if array and function parameters get decayed to pointers as
+ they should. */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#include "../objc-obj-c++-shared/Object1.h"
+#include <string.h>
+#include <stdlib.h>
+
+static char global_buf[20];
+
+char *strcpy_like_callee(const char *s) {
+ strcpy(global_buf, s);
+ return global_buf;
+}
+
+typedef char io_string_t[512];
+typedef char *(func_type)(const char *);
+
+@interface DeviceObject: Object
+- (void) func:(func_type)func stucPathInIORegistry:(io_string_t)ioRegPath;
+@end
+@implementation DeviceObject
+- (void) func:(func_type)func stucPathInIORegistry:(io_string_t)ioRegPath
+{
+ func(ioRegPath);
+}
+@end
+
+int main (void) {
+ io_string_t my_string;
+ DeviceObject *obj = [DeviceObject new];
+
+ strcpy (my_string, "Hello!");
+ strcpy (global_buf, "Good-bye!");
+
+ [obj func:strcpy_like_callee stucPathInIORegistry:my_string];
+
+ if (strcmp (global_buf, "Hello!"))
+ abort ();
+
+ return 0;
+}
diff --git a/gcc/testsuite/objc.dg/method-20b.m b/gcc/testsuite/objc.dg/method-20b.m
new file mode 100644
index 00000000000..9b8625a9b17
--- /dev/null
+++ b/gcc/testsuite/objc.dg/method-20b.m
@@ -0,0 +1,43 @@
+/* Check if array and function parameters get decayed to pointers as
+ they should. */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#include "../objc-obj-c++-shared/Object1.h"
+#include <string.h>
+#include <stdlib.h>
+
+static char global_buf[20];
+
+char *strcpy_like_callee(const char *s) {
+ strcpy(global_buf, s);
+ return global_buf;
+}
+
+typedef char io_string_t[512];
+typedef char *(func_type)(const char *);
+
+@interface DeviceObject: Object
+- (void) func:(func_type)func stucPathInIORegistry:(io_string_t)ioRegPath;
+@end
+@implementation DeviceObject
+- (void) func:(func_type)func stucPathInIORegistry:(io_string_t)ioRegPath
+{
+ func(ioRegPath);
+}
+@end
+
+int main (void) {
+ io_string_t my_string;
+ DeviceObject *obj = [DeviceObject new];
+
+ strcpy (my_string, "Hello!");
+ strcpy (global_buf, "Good-bye!");
+
+ [obj func:strcpy_like_callee stucPathInIORegistry:my_string];
+
+ if (strcmp (global_buf, "Hello!"))
+ abort ();
+
+ return 0;
+}