This bit of the objective C runtime already knows that TYPE_FIELDS might contain non-FIELD_DECL things. But it has the delightful assumption that the first thing is a FIELD_DECL, which apparently was fine until now. Fixed by simplifying the loop.

nathan

--
Nathan Sidwell
2017-07-14  Nathan Sidwell  <nat...@acm.org>

        gcc/objc/
        * objc-runtime-shared-support.c (build_ivar_list_initializer):
        Don't presume first item is a FIELD_DECL.

Index: gcc/objc/objc-runtime-shared-support.c
===================================================================
--- gcc/objc/objc-runtime-shared-support.c      (revision 250160)
+++ gcc/objc/objc-runtime-shared-support.c      (working copy)
@@ -528,34 +528,32 @@ build_ivar_list_initializer (tree type,
 {
   vec<constructor_elt, va_gc> *inits = NULL;
 
-  do
-    {
-      vec<constructor_elt, va_gc> *ivar = NULL;
-      tree id;
+  for (; field_decl; field_decl = DECL_CHAIN (field_decl))
+    if (TREE_CODE (field_decl) == FIELD_DECL)
+      {
+       vec<constructor_elt, va_gc> *ivar = NULL;
+       tree id;
 
-      /* Set name.  */
-      if (DECL_NAME (field_decl))
-       CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE,
-                               add_objc_string (DECL_NAME (field_decl),
-                                                meth_var_names));
-      else
-       /* Unnamed bit-field ivar (yuck).  */
-       CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE, build_int_cst (NULL_TREE, 0));
+       /* Set name.  */
+       if (DECL_NAME (field_decl))
+         CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE,
+                                 add_objc_string (DECL_NAME (field_decl),
+                                                  meth_var_names));
+       else
+         /* Unnamed bit-field ivar (yuck).  */
+         CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE,
+                                 build_int_cst (NULL_TREE, 0));
 
-      /* Set type.  */
-      id = add_objc_string (encode_field_decl (field_decl),
-                            meth_var_types);
-      CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE, id);
+       /* Set type.  */
+       id = add_objc_string (encode_field_decl (field_decl),
+                             meth_var_types);
+       CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE, id);
 
-      /* Set offset.  */
-      CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE, byte_position (field_decl));
-      CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE,
-                             objc_build_constructor (type, ivar));
-      do
-       field_decl = DECL_CHAIN (field_decl);
-      while (field_decl && TREE_CODE (field_decl) != FIELD_DECL);
+       /* Set offset.  */
+       CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE, byte_position (field_decl));
+       CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE,
+                               objc_build_constructor (type, ivar));
     }
-  while (field_decl);
 
   return objc_build_constructor (build_array_type (type, 0), inits);
 }

Reply via email to