View | Details | Return to bug 10962 | Differences between
and this patch

Collapse All | Expand All

(-)c-decl.c (+121 lines)
Lines 280-287 static tree any_external_decl PARAMS (( Link Here
280
static void record_external_decl	PARAMS ((tree));
281
static void record_external_decl	PARAMS ((tree));
281
static void warn_if_shadowing		PARAMS ((tree, tree));
282
static void warn_if_shadowing		PARAMS ((tree, tree));
282
static void clone_underlying_type	PARAMS ((tree));
283
static void clone_underlying_type	PARAMS ((tree));
284
static int field_decl_cmp		PARAMS ((const PTR, const PTR));
285
static int resort_field_decl_cmp	(const void*, const void*);
283
static bool flexible_array_type_p	PARAMS ((tree));
286
static bool flexible_array_type_p	PARAMS ((tree));
284
287
288
285
/* States indicating how grokdeclarator() should handle declspecs marked
289
/* States indicating how grokdeclarator() should handle declspecs marked
286
   with __attribute__((deprecated)).  An object declared as
290
   with __attribute__((deprecated)).  An object declared as
287
   __attribute__((deprecated)) suppresses warnings of uses of other
291
   __attribute__((deprecated)) suppresses warnings of uses of other
Lines 4959-4964 detect_field_duplicates (tree fieldlist) Link Here
4959
    }
4963
    }
4960
}
4964
}
4961
4965
4966
/* Function to help qsort sort FIELD_DECLs by name order.  */
4967
4968
4969
static int
4970
field_decl_cmp (xp, yp)
4971
      const PTR xp;
4972
      const PTR yp;
4973
{
4974
  tree *x = (tree *)xp, *y = (tree *)yp;
4975
  
4976
  if (DECL_NAME (*x) == DECL_NAME (*y))
4977
    return 0;
4978
  if (DECL_NAME (*x) == NULL)
4979
    return -1;
4980
  if (DECL_NAME (*y) == NULL)
4981
    return 1;
4982
  if (DECL_NAME (*x) < DECL_NAME (*y))
4983
    return -1;
4984
  return 1;
4985
}
4986
4987
static struct {
4988
  gt_pointer_operator new_value;
4989
  void *cookie;     
4990
} resort_data; 
4991
4992
/* This routine compares two fields like field_decl_cmp but using the
4993
   pointer operator in resort_data.  */
4994
4995
static int
4996
resort_field_decl_cmp (const void* x_p, const void* y_p)
4997
{
4998
  const tree *const x = x_p;
4999
  const tree *const y = y_p;
5000
5001
  if (DECL_NAME (*x) == DECL_NAME (*y))
5002
    return 0;
5003
  if (DECL_NAME (*x) == NULL_TREE)
5004
    return -1;
5005
  if (DECL_NAME (*y) == NULL_TREE)
5006
    return 1;
5007
  {
5008
    tree d1 = DECL_NAME (*x);
5009
    tree d2 = DECL_NAME (*y);
5010
    resort_data.new_value (&d1, resort_data.cookie);
5011
    resort_data.new_value (&d2, resort_data.cookie);
5012
    if (d1 < d2)
5013
      return -1;    
5014
  }
5015
  return 1;
5016
}
5017
5018
5019
/* Resort DECL_SORTED_FIELDS because pointers have been reordered.  */
5020
5021
void
5022
resort_sorted_fields (void* obj,
5023
                      void* orig_obj ATTRIBUTE_UNUSED ,
5024
                      gt_pointer_operator new_value,
5025
                      void* cookie)
5026
{
5027
  lang_type_s_1 sf = obj;
5028
  resort_data.new_value = new_value;
5029
  resort_data.cookie = cookie;
5030
  qsort (&sf->elts[0], sf->len, sizeof (tree),
5031
         resort_field_decl_cmp);
5032
}
5033
4962
/* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5034
/* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
4963
   FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5035
   FIELDLIST is a chain of FIELD_DECL nodes for the fields.
4964
   ATTRIBUTES are attributes to be applied to the structure.  */
5036
   ATTRIBUTES are attributes to be applied to the structure.  */
Lines 5162-5167 finish_struct (t, fieldlist, attributes) Link Here
5162
5234
5163
  TYPE_FIELDS (t) = fieldlist;
5235
  TYPE_FIELDS (t) = fieldlist;
5164
5236
5237
  /* If there are lots of fields, sort so we can look through them fast.
5238
    We arbitrarily consider 16 or more elts to be "a lot".  */
5239
5240
  {
5241
    int len = 0;
5242
5243
    for (x = fieldlist; x; x = TREE_CHAIN (x))
5244
      {
5245
        if (len > 15 || DECL_NAME (x) == NULL)
5246
          break;
5247
        len += 1;
5248
      }
5249
5250
    if (len > 15)
5251
      {
5252
        tree *field_array;
5253
        char *space;
5254
        char *space2;
5255
        
5256
        len += list_length (x);
5257
  
5258
        /* Use the same allocation policy here that make_node uses, to
5259
          ensure that this lives as long as the rest of the struct decl.
5260
          All decls in an inline function need to be saved.  */
5261
  
5262
        space = ggc_alloc (sizeof (struct lang_type));
5263
        space2 = ggc_alloc (sizeof (struct lang_type_s) + len * sizeof (tree));
5264
        
5265
        len = 0;
5266
	((struct lang_type *) space)->s = (lang_type_s_1) space2;
5267
	field_array = &(((struct lang_type *) space)->s->elts[0]);
5268
        for (x = fieldlist; x; x = TREE_CHAIN (x))
5269
          {
5270
            field_array[len++] = x;
5271
          
5272
            /* if there is anonymous struct or unoin break out of the loop */
5273
            if (DECL_NAME (x) == NULL)
5274
              break;
5275
          }
5276
        /* found no anonymous struct/union add the TYPE_LANG_SPECIFIC. */
5277
        if (x == NULL)
5278
          {
5279
            TYPE_LANG_SPECIFIC (t) = (struct lang_type *) space;
5280
            TYPE_LANG_SPECIFIC (t)->s->len = len;
5281
            field_array = &TYPE_LANG_SPECIFIC (t)->s->elts[0];
5282
            qsort (field_array, len, sizeof (tree), field_decl_cmp);
5283
          }
5284
      }
5285
  }
5286
  
5165
  for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
5287
  for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
5166
    {
5288
    {
5167
      TYPE_FIELDS (x) = TYPE_FIELDS (t);
5289
      TYPE_FIELDS (x) = TYPE_FIELDS (t);
(-)c-tree.h (-2 / +12 lines)
Lines 23-28 Software Foundation, 59 Temple Place - S Link Here
23
#define GCC_C_TREE_H
23
#define GCC_C_TREE_H
24
24
25
#include "c-common.h"
25
#include "c-common.h"
26
#include "ggc.h"
26
27
27
/* Language-dependent contents of an identifier.  */
28
/* Language-dependent contents of an identifier.  */
28
29
Lines 106-118 struct lang_decl GTY(()) Link Here
106
#define DECL_DECLARED_INLINE_P(NODE) \
107
#define DECL_DECLARED_INLINE_P(NODE) \
107
  (DECL_LANG_SPECIFIC (NODE)->base.declared_inline)
108
  (DECL_LANG_SPECIFIC (NODE)->base.declared_inline)
108
109
109
/* In a RECORD_TYPE, a sorted array of the fields of the type.  */
110
struct lang_type_s GTY(()) 
110
struct lang_type GTY(())
111
{
111
{
112
  int len;
112
  int len;
113
  tree GTY((length ("%h.len"))) elts[1];
113
  tree GTY((length ("%h.len"))) elts[1];
114
};
114
};
115
115
116
typedef struct lang_type_s *lang_type_s_1;
117
118
/* In a RECORD_TYPE, a sorted array of the fields of the type.  */
119
struct lang_type GTY(())
120
{
121
  lang_type_s_1 GTY ((reorder ("resort_sorted_fields"))) s; 
122
};
123
116
/* Record whether a type or decl was written with nonconstant size.
124
/* Record whether a type or decl was written with nonconstant size.
117
   Note that TYPE_SIZE may have simplified to a constant.  */
125
   Note that TYPE_SIZE may have simplified to a constant.  */
118
#define C_TYPE_VARIABLE_SIZE(TYPE) TYPE_LANG_FLAG_1 (TYPE)
126
#define C_TYPE_VARIABLE_SIZE(TYPE) TYPE_LANG_FLAG_1 (TYPE)
Lines 179-184 extern tree poplevel PARAMS ((int,int Link Here
179
extern void insert_block			PARAMS ((tree));
187
extern void insert_block			PARAMS ((tree));
180
extern void set_block				PARAMS ((tree));
188
extern void set_block				PARAMS ((tree));
181
extern tree pushdecl				PARAMS ((tree));
189
extern tree pushdecl				PARAMS ((tree));
190
extern void resort_sorted_fields
191
  (void *, void *, gt_pointer_operator, void *);
182
192
183
extern void c_insert_default_attributes		PARAMS ((tree));
193
extern void c_insert_default_attributes		PARAMS ((tree));
184
extern void c_init_decl_processing		PARAMS ((void));
194
extern void c_init_decl_processing		PARAMS ((void));
(-)ggc.h (+4 lines)
Lines 18-23 along with GCC; see the file COPYING. I Link Here
18
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
18
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19
02111-1307, USA.  */
19
02111-1307, USA.  */
20
20
21
#ifndef GCC_GGC_H
22
#define GCC_GGC_H
23
21
/* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with
24
/* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with
22
   an external gc library that might be linked in.  */
25
   an external gc library that might be linked in.  */
23
26
Lines 268-270 extern void stringpool_statistics PARAMS Link Here
268
extern int ggc_min_expand_heuristic PARAMS ((void));
271
extern int ggc_min_expand_heuristic PARAMS ((void));
269
extern int ggc_min_heapsize_heuristic PARAMS ((void));
272
extern int ggc_min_heapsize_heuristic PARAMS ((void));
270
extern void init_ggc_heuristics PARAMS ((void));
273
extern void init_ggc_heuristics PARAMS ((void));
274
#endif
(-)c-typeck.c (-2 / +2 lines)
Lines 1038-1048 lookup_field (decl, component) Link Here
1038
  if (TYPE_LANG_SPECIFIC (type))
1038
  if (TYPE_LANG_SPECIFIC (type))
1039
    {
1039
    {
1040
      int bot, top, half;
1040
      int bot, top, half;
1041
      tree *field_array = &TYPE_LANG_SPECIFIC (type)->elts[0];
1041
      tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
1042
1042
1043
      field = TYPE_FIELDS (type);
1043
      field = TYPE_FIELDS (type);
1044
      bot = 0;
1044
      bot = 0;
1045
      top = TYPE_LANG_SPECIFIC (type)->len;
1045
      top = TYPE_LANG_SPECIFIC (type)->s->len;
1046
      while (top - bot > 1)
1046
      while (top - bot > 1)
1047
	{
1047
	{
1048
	  half = (top - bot + 1) >> 1;
1048
	  half = (top - bot + 1) >> 1;

Return to bug 10962