This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Fix PR objc/19321 and assorted bogosities


This patch (finally!) fixes the mysterious loss of volatile-ness experienced by PARM_DECLs
in ObjC methods. I'm not terribly proud of the objc.dg/volatile-1.m test case, as it only really works for PowerPC Darwin targets; I'm hoping people can add assembly patterns to search for on their own platforms. Or perhaps there is a better, target-independent way of testing this; suggestions are welcome and encouraged.


While I was at it, I also fixed problems with using functions as ObjC method parameters; the proper decay to pointers was not happening, and this is a regression from gcc 3.x.

I'll wait until tomorrow for comments before committing.

--Zem

[gcc/objc/ChangeLog]
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.

[gcc/testsuite/ChangeLog]
2005-01-15  Ziemowit Laski  <zlaski@apple.com>

        PR objc/19321
        * objc.dg/func-ptr-2.m: New.
        * objc.dg/volatile-1.m: New.


Index: gcc/objc/objc-act.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v retrieving revision 1.260 diff -u -3 -p -r1.260 objc-act.c --- gcc/objc/objc-act.c 2 Jan 2005 07:52:28 -0000 1.260 +++ gcc/objc/objc-act.c 15 Jan 2005 02:12:47 -0000 @@ -5298,9 +5298,11 @@ get_arg_type_list (tree meth, int contex { 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
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 typ

#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
Index: gcc/testsuite/objc.dg/func-ptr-2.m
===================================================================
RCS file: gcc/testsuite/objc.dg/func-ptr-2.m
diff -N gcc/testsuite/objc.dg/func-ptr-2.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/objc.dg/func-ptr-2.m 15 Jan 2005 02:12:57 -0000
@@ -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;
+}
Index: gcc/testsuite/objc.dg/volatile-1.m
===================================================================
RCS file: gcc/testsuite/objc.dg/volatile-1.m
diff -N gcc/testsuite/objc.dg/volatile-1.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/objc.dg/volatile-1.m 15 Jan 2005 02:12:57 -0000
@@ -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* } } } */



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]