]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR objc/19321 (objc ignores volatile in argument types for messages)
authorZiemowit Laski <zlaski@apple.com>
Sat, 15 Jan 2005 21:18:56 +0000 (21:18 +0000)
committerZiemowit Laski <zlaski@gcc.gnu.org>
Sat, 15 Jan 2005 21:18:56 +0000 (21:18 +0000)
[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.

From-SVN: r93706

gcc/objc/ChangeLog
gcc/objc/objc-act.c
gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/func-ptr-2.m [new file with mode: 0644]
gcc/testsuite/objc.dg/volatile-1.m [new file with mode: 0644]

index f7ebee3db40be620b381a615139e8bf43136f70a..77a62a1d22a9861ee1955977e8d2fa3b48af7bed 100644 (file)
@@ -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
index e735d55e391ec2dc4be9627baf1b52471f7e4f8c..be21d08bdaba834fea25208c04878d515f40abac 100644 (file)
@@ -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
index ea1ba53ddf8ad493ddbdd873b6ff33d14b186444..9dec00bef42b0ef29d2a4c66b4c294303589e098 100644 (file)
@@ -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 (file)
index 0000000..625ce9f
--- /dev/null
@@ -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 (file)
index 0000000..8b5381a
--- /dev/null
@@ -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* } } } */