aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/objc/ChangeLog13
-rw-r--r--gcc/objc/objc-act.c35
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/objc.dg/func-ptr-2.m37
-rw-r--r--gcc/testsuite/objc.dg/volatile-1.m18
5 files changed, 97 insertions, 12 deletions
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog
index f7ebee3..77a62a1 100644
--- a/gcc/objc/ChangeLog
+++ b/gcc/objc/ChangeLog
@@ -1,3 +1,16 @@
+2005-01-15 Ziemowit Laski <zlaski@apple.com>
+
+ PR objc/19321
+ * objc-act.c (get_arg_type_list): Decay function arguments into
+ pointers.
+ (objc_push_parm): Likewise; bring PARM_DECL construction closer
+ in line with what the C front-end does.
+ (objc_get_parm_info): Call pushdecl() and finish_decl() on
+ each PARM_DECL, like the C front-end does.
+ (start_method_def): Remove redundant ARRAY_TYPE decay.
+ (objc_start_function): Bring closer in line with what the
+ C front-end does for functions.
+
2005-01-14 Mike Stump <mrs@apple.com>
* lang-specs.h ("@objective-c"): Use cc1obj when -E is used so
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index e735d55..be21d08 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -5298,9 +5298,11 @@ get_arg_type_list (tree meth, int context, int superflag)
{
tree arg_type = TREE_VALUE (TREE_TYPE (akey));
- /* Decay arrays into pointers. */
+ /* 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);
chainon (arglist, build_tree_list (NULL_TREE, arg_type));
}
@@ -7379,11 +7381,21 @@ static GTY(()) tree objc_parmlist = NULL_TREE;
static void
objc_push_parm (tree parm)
{
- /* Convert array parameters of unknown size into pointers. */
- if (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE
- && !TYPE_SIZE (TREE_TYPE (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)));
+ else if (TREE_CODE (TREE_TYPE (parm)) == FUNCTION_TYPE)
+ TREE_TYPE (parm) = build_pointer_type (TREE_TYPE (parm));
+ DECL_ARG_TYPE_AS_WRITTEN (parm) = TREE_TYPE (parm);
+ DECL_ARG_TYPE (parm) = c_type_promotes_to (TREE_TYPE (parm));
+
+ /* Record constancy and volatility. */
+ c_apply_type_quals_to_decl
+ ((TYPE_READONLY (TREE_TYPE (parm)) ? TYPE_QUAL_CONST : 0)
+ | (TYPE_RESTRICT (TREE_TYPE (parm)) ? TYPE_QUAL_RESTRICT : 0)
+ | (TYPE_VOLATILE (TREE_TYPE (parm)) ? TYPE_QUAL_VOLATILE : 0), parm);
+
objc_parmlist = chainon (objc_parmlist, parm);
}
@@ -7415,7 +7427,8 @@ objc_get_parm_info (int have_ellipsis)
tree next = TREE_CHAIN (parm_info);
TREE_CHAIN (parm_info) = NULL_TREE;
- pushdecl (parm_info);
+ parm_info = pushdecl (parm_info);
+ finish_decl (parm_info, NULL_TREE, NULL_TREE);
parm_info = next;
}
arg_info = get_parm_info (have_ellipsis);
@@ -7477,10 +7490,6 @@ start_method_def (tree method)
{
tree type = TREE_VALUE (TREE_TYPE (parmlist)), parm;
- /* Decay arrays into pointers. */
- if (TREE_CODE (type) == ARRAY_TYPE)
- type = build_pointer_type (TREE_TYPE (type));
-
parm = build_decl (PARM_DECL, KEYWORD_ARG_NAME (parmlist), type);
objc_push_parm (parm);
parmlist = TREE_CHAIN (parmlist);
@@ -7619,24 +7628,26 @@ objc_start_function (tree name, tree type, tree attrs,
#ifdef OBJCPLUS
DECL_ARGUMENTS (fndecl) = params;
-#endif
DECL_INITIAL (fndecl) = error_mark_node;
DECL_EXTERNAL (fndecl) = 0;
TREE_STATIC (fndecl) = 1;
-
-#ifdef OBJCPLUS
retrofit_lang_decl (fndecl);
cplus_decl_attributes (&fndecl, attrs, 0);
start_preparsed_function (fndecl, attrs, /*flags=*/SF_DEFAULT);
#else
decl_attributes (&fndecl, attrs, 0);
announce_function (fndecl);
+ DECL_INITIAL (fndecl) = error_mark_node;
+ DECL_EXTERNAL (fndecl) = 0;
+ TREE_STATIC (fndecl) = 1;
current_function_decl = pushdecl (fndecl);
push_scope ();
declare_parm_level ();
DECL_RESULT (current_function_decl)
= build_decl (RESULT_DECL, NULL_TREE,
TREE_TYPE (TREE_TYPE (current_function_decl)));
+ DECL_ARTIFICIAL (DECL_RESULT (current_function_decl)) = 1;
+ DECL_IGNORED_P (DECL_RESULT (current_function_decl)) = 1;
start_fname_decls ();
store_parm_decls_from (params);
#endif
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ea1ba53..9dec00b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2005-01-15 Ziemowit Laski <zlaski@apple.com>
+
+ PR objc/19321
+ * objc.dg/func-ptr-2.m: New.
+ * objc.dg/volatile-1.m: New.
+
2005-01-15 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
* gcc.dg/20040813-1.c: Add hppa*64*-*-* to no stabs list.
diff --git a/gcc/testsuite/objc.dg/func-ptr-2.m b/gcc/testsuite/objc.dg/func-ptr-2.m
new file mode 100644
index 0000000..625ce9f
--- /dev/null
+++ b/gcc/testsuite/objc.dg/func-ptr-2.m
@@ -0,0 +1,37 @@
+/* Check if method parameters that are functions are gracefully decayed
+ into pointers. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com> */
+/* { dg-do run } */
+
+#include <objc/Object.h>
+#include <stdlib.h>
+
+@interface Func: Object
++ (int) processNumber:(int)a and:(int)b usingFunction:(int(int,int))func;
+@end
+
+@implementation Func
++ (int) processNumber:(int)a and:(int)b usingFunction:(int(int,int))func {
+ return func (a, b);
+}
+@end
+
+static int my_computation(int a, int b) {
+ return a * 2 + b * 3;
+}
+
+static int processNumber(int a, int b, int func(int, int)) {
+ return func(a, b);
+}
+
+int main(void) {
+ int result = processNumber (6, 8, my_computation);
+ if (result != 36)
+ abort ();
+
+ result = [Func processNumber:8 and:6 usingFunction:my_computation];
+ if (result != 34)
+ abort ();
+
+ return 0;
+}
diff --git a/gcc/testsuite/objc.dg/volatile-1.m b/gcc/testsuite/objc.dg/volatile-1.m
new file mode 100644
index 0000000..8b5381a
--- /dev/null
+++ b/gcc/testsuite/objc.dg/volatile-1.m
@@ -0,0 +1,18 @@
+/* Test for proper handling of volatile parameters in ObjC methods. */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* Contributed by Ziemowit Laski <zlaski@apple.com> */
+
+@interface Test
+-(void) test2: (volatile int) a;
+@end
+
+@implementation Test
+-(void) test2: (volatile int) a
+{
+ /* The following assignment should NOT be optimized away. */
+ a = 1;
+}
+@end
+
+/* { dg-final { scan-assembler "li r\[0-9\]+,1" { target powerpc*-*-darwin* } } } */