This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Compiling GCC with a C++ compiler (1/n)
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: gcc-patches at gcc dot gnu dot org
- Date: 25 Jul 2004 19:29:50 +0200
- Subject: Compiling GCC with a C++ compiler (1/n)
- Organization: Integrable Solutions
This patchlet builds on the recent patch from Bernardo
http://gcc.gnu.org/ml/gcc-patches/2004-07/msg02261.html
It replaces uncasted direct calls to ggc_alloc and friends with GGC_NEW
et al.
Bootstrapped and regtested on an i686-pc-linux-gnu.
-- Gaby
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/ChangeLog,v
retrieving revision 1.4242
diff -p -r1.4242 ChangeLog
*** ChangeLog 25 Jul 2004 08:10:26 -0000 1.4242
--- ChangeLog 25 Jul 2004 16:52:06 -0000
***************
*** 1,3 ****
--- 1,29 ----
+ 2004-07-25 Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+ * cp-tree.h (TYPE_SET_PTRMEMFUNC_TYPE): Use GGC_CNEW.
+ * typeck2.c (abstract_virtuals_error): Use GGC_NEW.
+ * name-lookup.c (binding_entry_make): Use GGC_NEW.
+ (binding_table_construct): Use GGC_CNEWVEC.
+ (binding_table_new): Use GGC_NEW.
+ (cxx_binding_make): Likewise.
+ (begin_scope): Likewise.
+ (push_to_top_level): Use GCC_CNEW.
+ * parser.c (cp_token_cache_new): Likewise.
+ (cp_token_cache_push_token): Likewise.
+ (cp_lexer_new_main): Likewise.
+ (cp_lexer_new_from_tokens): Likewise.
+ (cp_parser_context_new): Likewise.
+ (cp_parser_new): Likewise.
+ (cp_lexer_new_from_tokens): Use GGC_NEWVEC.
+ * lex.c (cxx_make_type): Use GGC_CNEW.
+ (retrofit_lang_decl): Use GGC_NEWVAR.
+ (cxx_dup_lang_specific_decl): Likewise.
+ (copy_lang_type): Likewise.
+ * decl.c (use_label): Use GGC_NEW instead of ggc_alloc.
+ (save_function_data): Likewise.
+ (lookup_label): Use GGC_CNEW instead of ggc_alloc_cleared.
+ (cxx_push_function_context): Likewise.
+
2004-07-25 Richard Henderson <rth@redhat.com>
* decl.c (start_preparsed_function): Set DECL_ARTIFICIAL and
Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.643
diff -p -r1.643 class.c
*** class.c 20 Jul 2004 15:36:08 -0000 1.643
--- class.c 25 Jul 2004 16:52:10 -0000
*************** finish_struct_1 (tree t)
*** 5014,5021 ****
n_fields = count_fields (TYPE_FIELDS (t));
if (n_fields > 7)
{
! struct sorted_fields_type *field_vec = ggc_alloc (sizeof (struct sorted_fields_type)
! + n_fields * sizeof (tree));
field_vec->len = n_fields;
add_fields_to_record_type (TYPE_FIELDS (t), field_vec, 0);
qsort (field_vec->elts, n_fields, sizeof (tree),
--- 5014,5022 ----
n_fields = count_fields (TYPE_FIELDS (t));
if (n_fields > 7)
{
! struct sorted_fields_type *field_vec = GGC_NEWVAR
! (struct sorted_fields_type,
! sizeof (struct sorted_fields_type) + n_fields * sizeof (tree));
field_vec->len = n_fields;
add_fields_to_record_type (TYPE_FIELDS (t), field_vec, 0);
qsort (field_vec->elts, n_fields, sizeof (tree),
Index: cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.1021
diff -p -r1.1021 cp-tree.h
*** cp-tree.h 20 Jul 2004 23:20:04 -0000 1.1021
--- cp-tree.h 25 Jul 2004 16:52:13 -0000
*************** struct lang_decl GTY(())
*** 2448,2455 ****
do { \
if (TYPE_LANG_SPECIFIC (NODE) == NULL) \
{ \
! TYPE_LANG_SPECIFIC (NODE) = \
! ggc_alloc_cleared (sizeof (struct lang_type_ptrmem)); \
TYPE_LANG_SPECIFIC (NODE)->u.ptrmem.h.is_lang_type_class = 0; \
} \
TYPE_LANG_SPECIFIC (NODE)->u.ptrmem.record = (VALUE); \
--- 2448,2455 ----
do { \
if (TYPE_LANG_SPECIFIC (NODE) == NULL) \
{ \
! TYPE_LANG_SPECIFIC (NODE) = GGC_CNEWVAR \
! (struct lang_type, sizeof (struct lang_type_ptrmem)); \
TYPE_LANG_SPECIFIC (NODE)->u.ptrmem.h.is_lang_type_class = 0; \
} \
TYPE_LANG_SPECIFIC (NODE)->u.ptrmem.record = (VALUE); \
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1260
diff -p -r1.1260 decl.c
*** decl.c 25 Jul 2004 08:10:27 -0000 1.1260
--- decl.c 25 Jul 2004 16:52:18 -0000
*************** use_label (tree decl)
*** 2073,2079 ****
|| named_label_uses->label_decl != decl)
{
struct named_label_use_list *new_ent;
! new_ent = ggc_alloc (sizeof (struct named_label_use_list));
new_ent->label_decl = decl;
new_ent->names_in_scope = current_binding_level->names;
new_ent->binding_level = current_binding_level;
--- 2073,2079 ----
|| named_label_uses->label_decl != decl)
{
struct named_label_use_list *new_ent;
! new_ent = GGC_NEW (struct named_label_use_list);
new_ent->label_decl = decl;
new_ent->names_in_scope = current_binding_level->names;
new_ent->binding_level = current_binding_level;
*************** lookup_label (tree id)
*** 2109,2115 ****
/* Record this label on the list of labels used in this function.
We do this before calling make_label_decl so that we get the
IDENTIFIER_LABEL_VALUE before the new label is declared. */
! ent = ggc_alloc_cleared (sizeof (struct named_label_list));
ent->old_value = IDENTIFIER_LABEL_VALUE (id);
ent->next = named_labels;
named_labels = ent;
--- 2109,2115 ----
/* Record this label on the list of labels used in this function.
We do this before calling make_label_decl so that we get the
IDENTIFIER_LABEL_VALUE before the new label is declared. */
! ent = GGC_CNEW (struct named_label_list);
ent->old_value = IDENTIFIER_LABEL_VALUE (id);
ent->next = named_labels;
named_labels = ent;
*************** save_function_data (tree decl)
*** 10025,10031 ****
19990908);
/* Make a copy. */
! f = ggc_alloc (sizeof (struct language_function));
memcpy (f, cp_function_chain, sizeof (struct language_function));
DECL_SAVED_FUNCTION_DATA (decl) = f;
--- 10025,10031 ----
19990908);
/* Make a copy. */
! f = GGC_NEW (struct language_function);
memcpy (f, cp_function_chain, sizeof (struct language_function));
DECL_SAVED_FUNCTION_DATA (decl) = f;
*************** revert_static_member_fn (tree decl)
*** 10672,10679 ****
void
cxx_push_function_context (struct function * f)
{
! struct language_function *p
! = ggc_alloc_cleared (sizeof (struct language_function));
f->language = p;
/* Whenever we start a new function, we destroy temporaries in the
--- 10672,10678 ----
void
cxx_push_function_context (struct function * f)
{
! struct language_function *p = GGC_CNEW (struct language_function);
f->language = p;
/* Whenever we start a new function, we destroy temporaries in the
Index: lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/lex.c,v
retrieving revision 1.336
diff -p -r1.336 lex.c
*** lex.c 15 Jul 2004 03:10:26 -0000 1.336
--- lex.c 25 Jul 2004 16:52:18 -0000
*************** retrofit_lang_decl (tree t)
*** 654,660 ****
else
size = sizeof (struct lang_decl_flags);
! ld = ggc_alloc_cleared (size);
ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
--- 654,660 ----
else
size = sizeof (struct lang_decl_flags);
! ld = GGC_CNEWVAR (struct lang_decl, size);
ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
*************** cxx_dup_lang_specific_decl (tree node)
*** 691,697 ****
size = sizeof (struct lang_decl_flags);
else
size = sizeof (struct lang_decl);
! ld = ggc_alloc (size);
memcpy (ld, DECL_LANG_SPECIFIC (node), size);
DECL_LANG_SPECIFIC (node) = ld;
--- 691,697 ----
size = sizeof (struct lang_decl_flags);
else
size = sizeof (struct lang_decl);
! ld = GGC_NEWVAR (struct lang_decl, size);
memcpy (ld, DECL_LANG_SPECIFIC (node), size);
DECL_LANG_SPECIFIC (node) = ld;
*************** copy_lang_type (tree node)
*** 728,734 ****
size = sizeof (struct lang_type);
else
size = sizeof (struct lang_type_ptrmem);
! lt = ggc_alloc (size);
memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
TYPE_LANG_SPECIFIC (node) = lt;
--- 728,734 ----
size = sizeof (struct lang_type);
else
size = sizeof (struct lang_type_ptrmem);
! lt = GGC_NEWVAR (struct lang_type, size);
memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
TYPE_LANG_SPECIFIC (node) = lt;
*************** cxx_make_type (enum tree_code code)
*** 759,767 ****
if (IS_AGGR_TYPE_CODE (code)
|| code == BOUND_TEMPLATE_TEMPLATE_PARM)
{
! struct lang_type *pi;
!
! pi = ggc_alloc_cleared (sizeof (struct lang_type));
TYPE_LANG_SPECIFIC (t) = pi;
pi->u.c.h.is_lang_type_class = 1;
--- 759,765 ----
if (IS_AGGR_TYPE_CODE (code)
|| code == BOUND_TEMPLATE_TEMPLATE_PARM)
{
! struct lang_type *pi = GGC_CNEW (struct lang_type);
TYPE_LANG_SPECIFIC (t) = pi;
pi->u.c.h.is_lang_type_class = 1;
Index: name-lookup.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/name-lookup.c,v
retrieving revision 1.78
diff -p -r1.78 name-lookup.c
*** name-lookup.c 20 Jul 2004 12:25:23 -0000 1.78
--- name-lookup.c 25 Jul 2004 16:52:21 -0000
*************** binding_entry_make (tree name, tree type
*** 85,91 ****
free_binding_entry = entry->chain;
}
else
! entry = ggc_alloc (sizeof (struct binding_entry_s));
entry->name = name;
entry->type = type;
--- 85,91 ----
free_binding_entry = entry->chain;
}
else
! entry = GGC_NEW (struct binding_entry_s);
entry->name = name;
entry->type = type;
*************** binding_table_construct (binding_table t
*** 127,134 ****
{
table->chain_count = chain_count;
table->entry_count = 0;
! table->chain = ggc_alloc_cleared
! (table->chain_count * sizeof (binding_entry));
}
/* Make TABLE's entries ready for reuse. */
--- 127,133 ----
{
table->chain_count = chain_count;
table->entry_count = 0;
! table->chain = GGC_CNEWVEC (binding_entry, table->chain_count);
}
/* Make TABLE's entries ready for reuse. */
*************** binding_table_free (binding_table table)
*** 161,167 ****
static inline binding_table
binding_table_new (size_t chain_count)
{
! binding_table table = ggc_alloc (sizeof (struct binding_table_s));
table->chain = NULL;
binding_table_construct (table, chain_count);
return table;
--- 160,166 ----
static inline binding_table
binding_table_new (size_t chain_count)
{
! binding_table table = GGC_NEW (struct binding_table_s);
table->chain = NULL;
binding_table_construct (table, chain_count);
return table;
*************** cxx_binding_make (tree value, tree type)
*** 351,357 ****
free_bindings = binding->previous;
}
else
! binding = ggc_alloc (sizeof (cxx_binding));
cxx_binding_init (binding, value, type);
--- 350,356 ----
free_bindings = binding->previous;
}
else
! binding = GGC_NEW (cxx_binding);
cxx_binding_init (binding, value, type);
*************** begin_scope (scope_kind kind, tree entit
*** 1309,1315 ****
free_binding_level = scope->level_chain;
}
else
! scope = ggc_alloc (sizeof (cxx_scope));
memset (scope, 0, sizeof (cxx_scope));
scope->this_entity = entity;
--- 1308,1314 ----
free_binding_level = scope->level_chain;
}
else
! scope = GGC_NEW (cxx_scope);
memset (scope, 0, sizeof (cxx_scope));
scope->this_entity = entity;
*************** push_to_top_level (void)
*** 4941,4947 ****
int need_pop;
timevar_push (TV_NAME_LOOKUP);
! s = ggc_alloc_cleared (sizeof (struct saved_scope));
b = scope_chain ? current_binding_level : 0;
--- 4940,4946 ----
int need_pop;
timevar_push (TV_NAME_LOOKUP);
! s = GGC_CNEW (struct saved_scope);
b = scope_chain ? current_binding_level : 0;
Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.230
diff -p -r1.230 parser.c
*** parser.c 20 Jul 2004 19:13:36 -0000 1.230
--- parser.c 25 Jul 2004 16:52:27 -0000
*************** static void cp_token_cache_push_token
*** 131,137 ****
static cp_token_cache *
cp_token_cache_new (void)
{
! return ggc_alloc_cleared (sizeof (cp_token_cache));
}
/* Add *TOKEN to *CACHE. */
--- 131,137 ----
static cp_token_cache *
cp_token_cache_new (void)
{
! return GGC_CNEW (cp_token_cache);
}
/* Add *TOKEN to *CACHE. */
*************** cp_token_cache_push_token (cp_token_cach
*** 145,151 ****
/* See if we need to allocate a new token block. */
if (!b || b->num_tokens == CP_TOKEN_BLOCK_NUM_TOKENS)
{
! b = ggc_alloc_cleared (sizeof (cp_token_block));
b->prev = cache->last;
if (cache->last)
{
--- 145,151 ----
/* See if we need to allocate a new token block. */
if (!b || b->num_tokens == CP_TOKEN_BLOCK_NUM_TOKENS)
{
! b = GGC_CNEW (cp_token_block);
b->prev = cache->last;
if (cache->last)
{
*************** cp_lexer_new_main (void)
*** 311,317 ****
c_common_no_more_pch ();
/* Allocate the memory. */
! lexer = ggc_alloc_cleared (sizeof (cp_lexer));
/* Create the circular buffer. */
lexer->buffer = ggc_calloc (CP_TOKEN_BUFFER_SIZE, sizeof (cp_token));
--- 311,317 ----
c_common_no_more_pch ();
/* Allocate the memory. */
! lexer = GGC_CNEW (cp_lexer);
/* Create the circular buffer. */
lexer->buffer = ggc_calloc (CP_TOKEN_BUFFER_SIZE, sizeof (cp_token));
*************** cp_lexer_new_from_tokens (cp_token_cache
*** 350,362 ****
ptrdiff_t num_tokens;
/* Allocate the memory. */
! lexer = ggc_alloc_cleared (sizeof (cp_lexer));
/* Create a new buffer, appropriately sized. */
num_tokens = 0;
for (block = tokens->first; block != NULL; block = block->next)
num_tokens += block->num_tokens;
! lexer->buffer = ggc_alloc (num_tokens * sizeof (cp_token));
lexer->buffer_end = lexer->buffer + num_tokens;
/* Install the tokens. */
--- 350,362 ----
ptrdiff_t num_tokens;
/* Allocate the memory. */
! lexer = GGC_CNEW (cp_lexer);
/* Create a new buffer, appropriately sized. */
num_tokens = 0;
for (block = tokens->first; block != NULL; block = block->next)
num_tokens += block->num_tokens;
! lexer->buffer = GGC_NEWVEC (cp_token, num_tokens);
lexer->buffer_end = lexer->buffer + num_tokens;
/* Install the tokens. */
*************** cp_parser_context_new (cp_parser_context
*** 1348,1354 ****
memset (context, 0, sizeof (*context));
}
else
! context = ggc_alloc_cleared (sizeof (cp_parser_context));
/* No errors have occurred yet in this context. */
context->status = CP_PARSER_STATUS_KIND_NO_ERROR;
/* If this is not the bottomost context, copy information that we
--- 1348,1354 ----
memset (context, 0, sizeof (*context));
}
else
! context = GGC_CNEW (cp_parser_context);
/* No errors have occurred yet in this context. */
context->status = CP_PARSER_STATUS_KIND_NO_ERROR;
/* If this is not the bottomost context, copy information that we
*************** cp_parser_new (void)
*** 2539,2545 ****
cp_lexer_new_main might load a PCH file. */
lexer = cp_lexer_new_main ();
! parser = ggc_alloc_cleared (sizeof (cp_parser));
parser->lexer = lexer;
parser->context = cp_parser_context_new (NULL);
--- 2539,2545 ----
cp_lexer_new_main might load a PCH file. */
lexer = cp_lexer_new_main ();
! parser = GGC_CNEW (cp_parser);
parser->lexer = lexer;
parser->context = cp_parser_context_new (NULL);
Index: typeck2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck2.c,v
retrieving revision 1.166
diff -p -r1.166 typeck2.c
*** typeck2.c 20 Jul 2004 12:25:33 -0000 1.166
--- typeck2.c 25 Jul 2004 16:52:28 -0000
*************** abstract_virtuals_error (tree decl, tree
*** 263,269 ****
slot = htab_find_slot_with_hash (abstract_pending_vars, type,
(hashval_t)TYPE_UID (type), INSERT);
! pat = ggc_alloc (sizeof (struct pending_abstract_type));
pat->type = type;
pat->decl = decl;
pat->locus = ((decl && DECL_P (decl))
--- 263,269 ----
slot = htab_find_slot_with_hash (abstract_pending_vars, type,
(hashval_t)TYPE_UID (type), INSERT);
! pat = GGC_NEW (struct pending_abstract_type);
pat->type = type;
pat->decl = decl;
pat->locus = ((decl && DECL_P (decl))