objc-act.c (build_ivar_chain): Remove.
authorZiemowit Laski <zlaski@apple.com>
Tue, 20 Aug 2002 01:27:39 +0000 (01:27 +0000)
committerZiemowit Laski <zlaski@gcc.gnu.org>
Tue, 20 Aug 2002 01:27:39 +0000 (01:27 +0000)
[gcc]
2002-08-19  Ziemowit Laski  <zlaski@apple.com>

        * objc/objc-act.c (build_ivar_chain): Remove.
        (objc_copy_list): Likewise.
        (get_class_ivars): Inline call to removed build_ivar_chain
        function.  Save off a clean copy of ivars in the CLASS_OWN_IVARS
        slot; use that slot (rather than CLASS_IVARS) when accessing
        ivars for base classes.  Call copy_list and chainon instead of
        objc_copy_list.
        (build_private_template): Call get_class_ivars instead of
        build_ivar_chain.
        (start_class): Allocate room for the CLASS_OWN_IVARS slot.
        (continue_class): Call get_class_ivars instead of
        build_ivar_chain.
        (encode_field_decl): Check for DECL_BIT_FIELD_TYPE instead
        of DECL_BIT_FIELD (which may have been cleared).
        * objc/objc-act.h (CLASS_OWN_IVARS): New accessor macro.

[gcc/testsuite]
2002-08-19  Ziemowit Laski  <zlaski@apple.com>

        * objc.dg/bitfield-1.m: New test.
        * objc.dg/bitfield-2.m: New test.

From-SVN: r56451

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

index 1fc5a24c1c900964ba266f0650c49c147791d5eb..e04ce0e013de2531b0e879c16933e7e9a77d732d 100644 (file)
@@ -1,3 +1,21 @@
+2002-08-19  Ziemowit Laski  <zlaski@apple.com>
+
+       * objc/objc-act.c (build_ivar_chain): Remove.
+       (objc_copy_list): Likewise.
+       (get_class_ivars): Inline call to removed build_ivar_chain
+       function.  Save off a clean copy of ivars in the CLASS_OWN_IVARS
+       slot; use that slot (rather than CLASS_IVARS) when accessing
+       ivars for base classes.  Call copy_list and chainon instead of
+       objc_copy_list.
+       (build_private_template): Call get_class_ivars instead of
+       build_ivar_chain.
+       (start_class): Allocate room for the CLASS_OWN_IVARS slot.
+       (continue_class): Call get_class_ivars instead of 
+       build_ivar_chain.
+       (encode_field_decl): Check for DECL_BIT_FIELD_TYPE instead
+       of DECL_BIT_FIELD (which may have been cleared).
+       * objc/objc-act.h (CLASS_OWN_IVARS): New accessor macro.
+
 2002-08-19  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * genautomata.c (output_translate_vect, output_state_ainsn_table,
index 44edf72bec9745e1f7d65288a35d79e2b4fbcb13..78413073b67e7b171aea097eb90564ee03827531 100644 (file)
@@ -128,7 +128,6 @@ static tree build_objc_method_call          PARAMS ((int, tree, tree,
 static void generate_strings                   PARAMS ((void));
 static tree get_proto_encoding                         PARAMS ((tree));
 static void build_selector_translation_table   PARAMS ((void));
-static tree build_ivar_chain                   PARAMS ((tree, int));
 
 static tree objc_add_static_instance           PARAMS ((tree, tree));
 
@@ -249,7 +248,6 @@ static tree build_typed_selector_reference          PARAMS ((tree, tree));
 static tree build_selector_reference           PARAMS ((tree));
 static tree build_class_reference_decl         PARAMS ((void));
 static void add_class_reference                        PARAMS ((tree));
-static tree objc_copy_list                     PARAMS ((tree, tree *));
 static tree build_protocol_template            PARAMS ((void));
 static tree build_descriptor_table_initializer PARAMS ((tree, tree));
 static tree build_method_prototype_list_template PARAMS ((tree, int));
@@ -2277,51 +2275,23 @@ lookup_interface (ident)
   return NULL_TREE;
 }
 
-static tree
-objc_copy_list (list, head)
-     tree list;
-     tree *head;
-{
-  tree newlist = NULL_TREE, tail = NULL_TREE;
-
-  while (list)
-    {
-      tail = copy_node (list);
-
-      /* The following statement fixes a bug when inheriting instance
-        variables that are declared to be bitfields. finish_struct
-        expects to find the width of the bitfield in DECL_INITIAL.  */
-      if (DECL_BIT_FIELD (tail) && DECL_INITIAL (tail) == 0)
-       DECL_INITIAL (tail) = DECL_SIZE (tail);
-
-      newlist = chainon (newlist, tail);
-      list = TREE_CHAIN (list);
-    }
-
-  *head = newlist;
-  return tail;
-}
-
-/* Used by: build_private_template, get_class_ivars, and
-   continue_class.  COPY is 1 when called from @defs.  In this case
-   copy all fields.  Otherwise don't copy leaf ivars since we rely on
-   them being side-effected exactly once by finish_struct.  */
+/* Used by: build_private_template, continue_class,
+   and for @defs constructs.  */
 
-static tree
-build_ivar_chain (interface, copy)
+tree
+get_class_ivars (interface)
      tree interface;
-     int copy;
 {
   tree my_name, super_name, ivar_chain;
 
   my_name = CLASS_NAME (interface);
   super_name = CLASS_SUPER_NAME (interface);
+  ivar_chain = CLASS_IVARS (interface);
 
-  /* Possibly copy leaf ivars.  */
-  if (copy)
-    objc_copy_list (CLASS_IVARS (interface), &ivar_chain);
-  else
-    ivar_chain = CLASS_IVARS (interface);
+  /* Save off a pristine copy of the leaf ivars (i.e, those not
+     inherited from a super class).  */
+  if (!CLASS_OWN_IVARS (interface))
+    CLASS_OWN_IVARS (interface) = copy_list (ivar_chain);
 
   while (super_name)
     {
@@ -2345,14 +2315,14 @@ build_ivar_chain (interface, copy)
       my_name = CLASS_NAME (interface);
       super_name = CLASS_SUPER_NAME (interface);
 
-      op1 = CLASS_IVARS (interface);
+      op1 = CLASS_OWN_IVARS (interface);
       if (op1)
         {
-         tree head, tail = objc_copy_list (op1, &head);
+         tree head = copy_list (op1);
 
          /* Prepend super class ivars...make a copy of the list, we
             do not want to alter the original.  */
-         TREE_CHAIN (tail) = ivar_chain;
+         chainon (head, ivar_chain);
          ivar_chain = head;
         }
     }
@@ -2379,7 +2349,7 @@ build_private_template (class)
     {
       uprivate_record = start_struct (RECORD_TYPE, CLASS_NAME (class));
 
-      ivar_context = build_ivar_chain (class, 0);
+      ivar_context = get_class_ivars (class);
 
       finish_struct (uprivate_record, ivar_context, NULL_TREE);
 
@@ -5660,18 +5630,6 @@ is_public (expr, identifier)
 
   return 1;
 }
-
-/* Implement @defs (<classname>) within struct bodies.  */
-
-tree
-get_class_ivars (interface)
-     tree interface;
-{
-  /* Make sure we copy the leaf ivars in case @defs is used in a local
-     context.  Otherwise finish_struct will overwrite the layout info
-     using temporary storage.  */
-  return build_ivar_chain (interface, 1);
-}
 \f
 /* Make sure all entries in CHAIN are also in LIST.  */
 
@@ -5903,7 +5861,7 @@ start_class (code, class_name, super_name, protocol_list)
     }
 
   class = make_node (code);
-  TYPE_BINFO (class) = make_tree_vec (5);
+  TYPE_BINFO (class) = make_tree_vec (6);
 
   CLASS_NAME (class) = class_name;
   CLASS_SUPER_NAME (class) = super_name;
@@ -6093,7 +6051,7 @@ continue_class (class)
 
       if (!TYPE_FIELDS (record))
        {
-         finish_struct (record, build_ivar_chain (class, 0), NULL_TREE);
+         finish_struct (record, get_class_ivars (class), NULL_TREE);
          CLASS_STATIC_TEMPLATE (class) = record;
 
          /* Mark this record as a class template for static typing.  */
@@ -6717,14 +6675,14 @@ encode_field_decl (field_decl, curtype, format)
      the bitfield typing information.  */
   if (flag_next_runtime)
     {
-      if (DECL_BIT_FIELD (field_decl))
+      if (DECL_BIT_FIELD_TYPE (field_decl))
        encode_bitfield (tree_low_cst (DECL_SIZE (field_decl), 1));
       else
        encode_type (TREE_TYPE (field_decl), curtype, format);
     }
   else
     {
-      if (DECL_BIT_FIELD (field_decl))
+      if (DECL_BIT_FIELD_TYPE (field_decl))
        encode_complete_bitfield (int_bit_position (field_decl),
                                  DECL_BIT_FIELD_TYPE (field_decl),
                                  tree_low_cst (DECL_SIZE (field_decl), 1));
index aebccf8af52a47ec5b279eb6cf45da7d0b0245be..af10387c3978ef2d1cd7574dc6044c607adef6dc 100644 (file)
@@ -97,6 +97,7 @@ tree build_encode_expr                                PARAMS ((tree));
 #define CLASS_STATIC_TEMPLATE(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 2)
 #define CLASS_CATEGORY_LIST(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 3)
 #define CLASS_PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 4)
+#define CLASS_OWN_IVARS(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 5)
 #define PROTOCOL_NAME(CLASS) ((CLASS)->type.name)
 #define PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 0)
 #define PROTOCOL_NST_METHODS(CLASS) ((CLASS)->type.minval)
index dad59ab4d4a8161e9a919383b7afd74a5ff6ca66..775dcb0e01644639345617deeedcc69aa32373f7 100644 (file)
@@ -1,3 +1,8 @@
+2002-08-19  Ziemowit Laski  <zlaski@apple.com>
+
+       * objc.dg/bitfield-1.m: New test.
+       * objc.dg/bitfield-2.m: New test.
+
 2002-08-17  Joseph S. Myers  <jsm@polyomino.org.uk>
 
        * gcc.dg/c90-flex-array-1.c, gcc.dg/c99-flex-array-3.c,
diff --git a/gcc/testsuite/objc.dg/bitfield-1.m b/gcc/testsuite/objc.dg/bitfield-1.m
new file mode 100644 (file)
index 0000000..8791eb3
--- /dev/null
@@ -0,0 +1,80 @@
+/* Check if bitfield ivars are inherited correctly (i.e., without
+   being "promoted" to ints).  */
+/* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
+/* { dg-do run } */
+
+#include <objc/objc.h>
+#include <objc/Object.h>
+
+extern void abort(void);
+
+#define CHECK_IF(expr) if(!(expr)) abort();
+
+@interface Base: Object 
+{
+    int full;
+    int full2: 32;
+    int _refs: 8;
+    int field2: 3;
+    unsigned f3: 8;
+    short cc;
+    unsigned g: 16;
+    int r2: 8;
+    int r3: 8;
+    int r4: 2;
+    int r5: 8;
+    char c;
+}
+- (void)setValues;
+@end
+
+@interface Derived: Base
+{
+    char d;
+    int _field3: 6;
+}
+- (void)checkValues;
+@end
+
+@implementation Base
+-(void)setValues {
+  full = 1;
+  full2 = 2;
+  _refs = 3;
+  field2 = 1;
+  f3 = 6;
+  cc = 7;
+  g = 8;
+  r2 = 9;
+  r3 = 10;
+  r4 = 1;
+  r5 = 12;
+  c = 13;
+}
+@end
+
+@implementation Derived
+-(void)checkValues {
+  CHECK_IF(full == 1);
+  CHECK_IF(full2 == 2);
+  CHECK_IF(_refs == 3);
+  CHECK_IF(field2 == 1);
+  CHECK_IF(f3 == 6);
+  CHECK_IF(cc == 7);
+  CHECK_IF(g == 8);
+  CHECK_IF(r2 == 9);
+  CHECK_IF(r3 == 10);
+  CHECK_IF(r4 == 1);
+  CHECK_IF(r5 == 12);
+  CHECK_IF(c == 13);
+}
+@end
+
+int main(void) {
+  Derived *obj = [[Derived alloc] init];
+
+  [obj setValues];
+  [obj checkValues];
+
+  return 0;
+}
diff --git a/gcc/testsuite/objc.dg/bitfield-2.m b/gcc/testsuite/objc.dg/bitfield-2.m
new file mode 100644 (file)
index 0000000..25a4862
--- /dev/null
@@ -0,0 +1,55 @@
+/* Check if bitfield ivars are correctly @encode'd when
+   the NeXT runtime is used.  */
+/* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
+/* { dg-options "-fnext-runtime" } */
+/* { dg-do run } */
+
+struct objc_object { struct objc_class *class_pointer; } *id;
+
+extern void abort(void);
+extern int strcmp(const char *, const char *);
+
+#define CHECK_IF(expr) if(!(expr)) abort();
+
+@interface Base 
+{
+    struct objc_class *isa;
+    int full;
+    int full2: 32;
+    int _refs: 8;
+    int field2: 3;
+    unsigned f3: 8;
+    short cc;
+    unsigned g: 16;
+    int r2: 8;
+    int r3: 8;
+    int r4: 2;
+    int r5: 8;
+    char c;
+}
+@end
+
+@interface Derived: Base
+{
+    char d;
+    int _field3: 6;
+}
+@end
+
+@implementation Base
+@end
+
+@implementation Derived
+@end
+
+int main(void) {
+  const char *s1r = "{Base=#ib32b8b3b8sb16b8b8b2b8c}";
+  const char *s1 = @encode(Base);
+  const char *s2r = "{Derived=#ib32b8b3b8sb16b8b8b2b8ccb6}";
+  const char *s2 = @encode(Derived);
+
+  CHECK_IF(!strcmp(s1r, s1));
+  CHECK_IF(!strcmp(s2r, s2));
+
+  return 0;
+}