This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch: use xcalloc in lieu of xmalloc/memset
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 10 Aug 2003 15:17:45 -0400 (EDT)
- Subject: Patch: use xcalloc in lieu of xmalloc/memset
Minor cleanup to use xcalloc in lieu of xmalloc/memset.
Tested via bootstrap on sparc-sun-solaris2.7 (minus libgcj), no
regressions. I also built cpu.o in cross-compilers targetted to
ia64-unknown-linux-gnu and avr-unknown-elf.
Ok for mainline?
Thanks,
--Kaveh
2003-08-09 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* config/avr/avr.c (avr_init_once): Use xcalloc in lieu of
xmalloc/memset.
* config/ia64/ia64.c (ia64_reorg): Likewise.
* conflict.c (conflict_graph_new): Likewise.
* fixinc/fixincl.c (run_compiles): Likewise.
* genattrtab.c (optimize_attrs): Likewise.
* genrecog.c (new_decision): Likewise.
* haifa-sched.c (schedule_block): Likewise.
* hashtable.c (ht_create): Likewise.
diff -rup orig/egcc-CVS20030808/gcc/config/avr/avr.c egcc-CVS20030808/gcc/config/avr/avr.c
--- orig/egcc-CVS20030808/gcc/config/avr/avr.c Mon Jun 30 23:48:30 2003
+++ egcc-CVS20030808/gcc/config/avr/avr.c Sat Aug 9 18:58:34 2003
@@ -281,20 +281,17 @@ avr_override_options ()
void
avr_init_once ()
{
- tmp_reg_rtx = xmalloc (sizeof (struct rtx_def) + 1 * sizeof (rtunion));
- memset (tmp_reg_rtx, 0, sizeof (struct rtx_def) + 1 * sizeof (rtunion));
+ tmp_reg_rtx = xcalloc (1, sizeof (struct rtx_def) + 1 * sizeof (rtunion));
PUT_CODE (tmp_reg_rtx, REG);
PUT_MODE (tmp_reg_rtx, QImode);
XINT (tmp_reg_rtx, 0) = TMP_REGNO;
- zero_reg_rtx = xmalloc (sizeof (struct rtx_def) + 1 * sizeof (rtunion));
- memset (zero_reg_rtx, 0, sizeof (struct rtx_def) + 1 * sizeof (rtunion));
+ zero_reg_rtx = xcalloc (1, sizeof (struct rtx_def) + 1 * sizeof (rtunion));
PUT_CODE (zero_reg_rtx, REG);
PUT_MODE (zero_reg_rtx, QImode);
XINT (zero_reg_rtx, 0) = ZERO_REGNO;
- ldi_reg_rtx = xmalloc (sizeof (struct rtx_def) + 1 * sizeof (rtunion));
- memset (ldi_reg_rtx, 0, sizeof (struct rtx_def) + 1 * sizeof (rtunion));
+ ldi_reg_rtx = xcalloc (1, sizeof (struct rtx_def) + 1 * sizeof (rtunion));
PUT_CODE (ldi_reg_rtx, REG);
PUT_MODE (ldi_reg_rtx, QImode);
XINT (ldi_reg_rtx, 0) = LDI_REG_REGNO;
diff -rup orig/egcc-CVS20030808/gcc/config/ia64/ia64.c egcc-CVS20030808/gcc/config/ia64/ia64.c
--- orig/egcc-CVS20030808/gcc/config/ia64/ia64.c Fri Aug 8 20:01:11 2003
+++ egcc-CVS20030808/gcc/config/ia64/ia64.c Sat Aug 9 19:00:08 2003
@@ -7419,14 +7419,11 @@ ia64_reorg ()
PREV_INSN (ia64_nop) = NEXT_INSN (ia64_nop) = NULL_RTX;
recog_memoized (ia64_nop);
clocks_length = get_max_uid () + 1;
- stops_p = (char *) xmalloc (clocks_length);
- memset (stops_p, 0, clocks_length);
+ stops_p = xcalloc (1, clocks_length);
if (ia64_tune == PROCESSOR_ITANIUM)
{
- clocks = (int *) xmalloc (clocks_length * sizeof (int));
- memset (clocks, 0, clocks_length * sizeof (int));
- add_cycles = (int *) xmalloc (clocks_length * sizeof (int));
- memset (add_cycles, 0, clocks_length * sizeof (int));
+ clocks = xcalloc (clocks_length, sizeof (int));
+ add_cycles = xcalloc (clocks_length, sizeof (int));
}
if (ia64_tune == PROCESSOR_ITANIUM2)
{
diff -rup orig/egcc-CVS20030808/gcc/conflict.c egcc-CVS20030808/gcc/conflict.c
--- orig/egcc-CVS20030808/gcc/conflict.c Sat Jul 19 10:42:07 2003
+++ egcc-CVS20030808/gcc/conflict.c Sat Aug 9 18:40:02 2003
@@ -160,9 +160,8 @@ conflict_graph_new (int num_regs)
obstack_init (&graph->arc_obstack);
/* Create and zero the lookup table by register number. */
- graph->neighbor_heads = xmalloc (num_regs * sizeof (conflict_graph_arc));
+ graph->neighbor_heads = xcalloc (num_regs, sizeof (conflict_graph_arc));
- memset (graph->neighbor_heads, 0, num_regs * sizeof (conflict_graph_arc));
return graph;
}
diff -rup orig/egcc-CVS20030808/gcc/fixinc/fixincl.c egcc-CVS20030808/gcc/fixinc/fixincl.c
--- orig/egcc-CVS20030808/gcc/fixinc/fixincl.c Fri Aug 1 20:01:24 2003
+++ egcc-CVS20030808/gcc/fixinc/fixincl.c Sat Aug 9 18:40:43 2003
@@ -481,11 +481,10 @@ run_compiles (void)
{
tFixDesc *p_fixd = fixDescList;
int fix_ct = FIX_COUNT;
- regex_t *p_re = xmalloc (REGEX_COUNT * sizeof (regex_t));
+ regex_t *p_re = xcalloc (REGEX_COUNT, sizeof (regex_t));
/* Make sure compile_re does not stumble across invalid data */
- memset (p_re, '\0', REGEX_COUNT * sizeof (regex_t));
memset (&incl_quote_re, '\0', sizeof (regex_t));
compile_re (incl_quote_pat, &incl_quote_re, 1,
diff -rup orig/egcc-CVS20030808/gcc/genattrtab.c egcc-CVS20030808/gcc/genattrtab.c
--- orig/egcc-CVS20030808/gcc/genattrtab.c Sat Jul 19 10:42:13 2003
+++ egcc-CVS20030808/gcc/genattrtab.c Sat Aug 9 18:42:25 2003
@@ -3393,10 +3393,8 @@ optimize_attrs (void)
return;
/* Make 2 extra elements, for "code" values -2 and -1. */
- insn_code_values = xmalloc ((insn_code_number + 2)
- * sizeof (struct attr_value_list *));
- memset (insn_code_values, 0,
- (insn_code_number + 2) * sizeof (struct attr_value_list *));
+ insn_code_values = xcalloc ((insn_code_number + 2),
+ sizeof (struct attr_value_list *));
/* Offset the table address so we can index by -2 or -1. */
insn_code_values += 2;
diff -rup orig/egcc-CVS20030808/gcc/genrecog.c egcc-CVS20030808/gcc/genrecog.c
--- orig/egcc-CVS20030808/gcc/genrecog.c Sat Jul 19 10:42:14 2003
+++ egcc-CVS20030808/gcc/genrecog.c Sat Aug 9 18:43:00 2003
@@ -316,9 +316,8 @@ extern void debug_decision_list
static struct decision *
new_decision (const char *position, struct decision_head *last)
{
- struct decision *new = xmalloc (sizeof (struct decision));
+ struct decision *new = xcalloc (1, sizeof (struct decision));
- memset (new, 0, sizeof (*new));
new->success = *last;
new->position = xstrdup (position);
new->number = next_number++;
diff -rup orig/egcc-CVS20030808/gcc/haifa-sched.c egcc-CVS20030808/gcc/haifa-sched.c
--- orig/egcc-CVS20030808/gcc/haifa-sched.c Sat Jul 19 10:42:15 2003
+++ egcc-CVS20030808/gcc/haifa-sched.c Sat Aug 9 18:44:11 2003
@@ -2138,8 +2138,7 @@ schedule_block (int b, int rgn_n_insns)
{
/* It is used for first cycle multipass scheduling. */
temp_state = alloca (dfa_state_size);
- ready_try = xmalloc ((rgn_n_insns + 1) * sizeof (char));
- memset (ready_try, 0, (rgn_n_insns + 1) * sizeof (char));
+ ready_try = xcalloc ((rgn_n_insns + 1), sizeof (char));
choice_stack = xmalloc ((rgn_n_insns + 1)
* sizeof (struct choice_entry));
for (i = 0; i <= rgn_n_insns; i++)
diff -rup orig/egcc-CVS20030808/gcc/hashtable.c egcc-CVS20030808/gcc/hashtable.c
--- orig/egcc-CVS20030808/gcc/hashtable.c Fri Aug 8 20:01:05 2003
+++ egcc-CVS20030808/gcc/hashtable.c Sat Aug 9 18:45:18 2003
@@ -58,8 +58,7 @@ ht_create (unsigned int order)
unsigned int nslots = 1 << order;
hash_table *table;
- table = xmalloc (sizeof (hash_table));
- memset (table, 0, sizeof (hash_table));
+ table = xcalloc (1, sizeof (hash_table));
/* Strings need no alignment. */
_obstack_begin (&table->stack, 0, 0,