Message ID | Pine.LNX.4.64.1006291742081.18619@wotan.suse.de |
---|---|
State | New |
Headers | show |
On Tue, Jun 29, 2010 at 5:45 PM, Michael Matz <matz@suse.de> wrote: > Hello, > > Allocating an array of length num_ssa_names, then doing foldings or other > transformations that can create new SSA names, and then iterating that > array again as if it had num_ssa_names elements is not a good idea. > > This fixes the testcase. I'm going to regstrap this, once the > function_arg_advance brokenness is fixed. Okay, assuming this will work? Ok. Thanks, Richard. > > Ciao, > Michael. > -- > PR bootstrap/44699 > * tree-vrp.c (vrp_finalize): Deal with changing num_ssa_names. > > testsuite/ > PR bootstrap/44699 > * gcc.dg/pr44699.c: New test. > > Index: tree-vrp.c > =================================================================== > --- tree-vrp.c (revision 161496) > +++ tree-vrp.c (working copy) > @@ -7315,6 +7315,7 @@ vrp_finalize (void) > size_t i; > prop_value_t *single_val_range; > bool do_value_subst_p; > + unsigned num = num_ssa_names; > > if (dump_file) > { > @@ -7326,10 +7327,10 @@ vrp_finalize (void) > /* We may have ended with ranges that have exactly one value. Those > values can be substituted as any other const propagated > value using substitute_and_fold. */ > - single_val_range = XCNEWVEC (prop_value_t, num_ssa_names); > + single_val_range = XCNEWVEC (prop_value_t, num); > > do_value_subst_p = false; > - for (i = 0; i < num_ssa_names; i++) > + for (i = 0; i < num; i++) > if (vr_value[i] > && vr_value[i]->type == VR_RANGE > && vr_value[i]->min == vr_value[i]->max > @@ -7357,7 +7358,7 @@ vrp_finalize (void) > identify_jump_threads (); > > /* Free allocated memory. */ > - for (i = 0; i < num_ssa_names; i++) > + for (i = 0; i < num; i++) > if (vr_value[i]) > { > BITMAP_FREE (vr_value[i]->equiv); > Index: testsuite/gcc.dg/pr44699.c > =================================================================== > --- testsuite/gcc.dg/pr44699.c (revision 0) > +++ testsuite/gcc.dg/pr44699.c (revision 0) > @@ -0,0 +1,157 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2" } */ > +typedef long unsigned int size_t; > +typedef long int intmax_t; > +typedef long unsigned int uintmax_t; > +extern void *xmalloc (size_t) __attribute__ ((__malloc__)); > +extern const char *trim_filename (const char *); > + > +static __inline void * > +__inline_memcpy_chk (void *__dest, const void *__src, size_t __len) > +{ > + return __builtin___memcpy_chk (__dest, __src, __len, __builtin_object_size (__dest, 0)); > +} > + > +typedef unsigned int hashval_t; > +typedef hashval_t (*htab_hash) (const void *); > +typedef int (*htab_eq) (const void *, const void *); > +typedef void (*htab_del) (void *); > +typedef int (*htab_trav) (void **, void *); > +typedef void *(*htab_alloc) (size_t, size_t); > +typedef void (*htab_free) (void *); > + > +typedef void *(*htab_alloc_with_arg) (void *, size_t, size_t); > +typedef void (*htab_free_with_arg) (void *, void *); > +struct htab { > + htab_hash hash_f; > + htab_eq eq_f; > + htab_del del_f; > + void ** entries; > + size_t size; > + size_t n_elements; > + size_t n_deleted; > + unsigned int searches; > + unsigned int collisions; > + htab_alloc alloc_f; > + htab_free free_f; > + void * alloc_arg; > + htab_alloc_with_arg alloc_with_arg_f; > + htab_free_with_arg free_with_arg_f; > + unsigned int size_prime_index; > +}; > + > +typedef struct htab *htab_t; > +enum insert_option {NO_INSERT, INSERT}; > +extern void * htab_find (htab_t, const void *); > +extern void ** htab_find_slot (htab_t, const void *, enum insert_option); > + > +enum mode_class { MODE_RANDOM, MODE_CC, MODE_INT, MODE_PARTIAL_INT, MODE_FRACT, MODE_UFRACT, MODE_ACCUM, MODE_UACCUM, MODE_FLOAT, MODE_DECIMAL_FLOAT, MODE_COMPLEX_INT, MODE_COMPLEX_FLOAT, MODE_VECTOR_INT, MODE_VECTOR_FRACT, MODE_VECTOR_UFRACT, MODE_VECTOR_ACCUM, MODE_VECTOR_UACCUM, MODE_VECTOR_FLOAT, MAX_MODE_CLASS }; > + > +static const char *const mode_class_names[MAX_MODE_CLASS] = > +{ > + "MODE_RANDOM", "MODE_CC", "MODE_INT", "MODE_PARTIAL_INT", "MODE_FRACT", "MODE_UFRACT", "MODE_ACCUM", "MODE_UACCUM", "MODE_FLOAT", "MODE_DECIMAL_FLOAT", "MODE_COMPLEX_INT", "MODE_COMPLEX_FLOAT", "MODE_VECTOR_INT", "MODE_VECTOR_FRACT", "MODE_VECTOR_UFRACT", "MODE_VECTOR_ACCUM", "MODE_VECTOR_UACCUM", "MODE_VECTOR_FLOAT" > +}; > +struct mode_data > +{ > + struct mode_data *next; > + > + const char *name; > + enum mode_class cl; > + unsigned int precision; > + unsigned int bytesize; > + unsigned int ncomponents; > + unsigned int alignment; > + const char *format; > + > + struct mode_data *component; > + struct mode_data *wider; > + struct mode_data *wider_2x; > + > + struct mode_data *contained; > + > + struct mode_data *next_cont; > + > + const char *file; > + unsigned int line; > + unsigned int counter; > + unsigned int ibit; > + unsigned int fbit; > +}; > + > +static struct mode_data *modes[MAX_MODE_CLASS]; > +static unsigned int n_modes[MAX_MODE_CLASS]; > +static struct mode_data *void_mode; > + > +static const struct mode_data blank_mode = { > + 0, "<unknown>", MAX_MODE_CLASS, > + -1U, -1U, -1U, -1U, > + 0, 0, 0, 0, 0, 0, > + "<unknown>", 0, 0, 0, 0 > +}; > + > +static htab_t modes_by_name; > + > +static __inline__ struct mode_data * > +find_mode (const char *name) > +{ > + struct mode_data key; > + > + key.name = name; > + return (struct mode_data *) htab_find (modes_by_name, &key); > +} > + > +static struct mode_data * > +new_mode (enum mode_class cl, const char *name, > + const char *file, unsigned int line) > +{ > + struct mode_data *m; > + static unsigned int count = 0; > + > + m = find_mode (name); > + if (m) > + { > + error ("%s:%d: duplicate definition of mode \"%s\"", > + trim_filename (file), line, name); > + error ("%s:%d: previous definition here", m->file, m->line); > + return m; > + } > + > + m = ((struct mode_data *) xmalloc (sizeof (struct mode_data))); > + ((__builtin_object_size (m, 0) != (size_t) -1) ? __builtin___memcpy_chk (m, &blank_mode, sizeof (struct mode_data), __builtin_object_size (m, 0)) : __inline_memcpy_chk (m, &blank_mode, sizeof (struct mode_data))); > + m->cl = cl; > + m->name = name; > + if (file) > + m->file = trim_filename (file); > + m->line = line; > + m->counter = count++; > + > + m->next = modes[cl]; > + modes[cl] = m; > + n_modes[cl]++; > + > + *htab_find_slot (modes_by_name, m, INSERT) = m; > + > + return m; > +} > + > +static void > +make_int_mode (const char *name, > + unsigned int precision, unsigned int bytesize, > + const char *file, unsigned int line) > +{ > + struct mode_data *m = new_mode (MODE_INT, name, file, line); > + m->bytesize = bytesize; > + m->precision = precision; > +} > + > +static void > +create_modes (void) > +{ > +make_int_mode ("HI", -1U, 2, "../../work/gcc/machmode.def", 182); > +} > + > +int > +main (int argc, char **argv) > +{ > + create_modes (); > +} >
Index: tree-vrp.c =================================================================== --- tree-vrp.c (revision 161496) +++ tree-vrp.c (working copy) @@ -7315,6 +7315,7 @@ vrp_finalize (void) size_t i; prop_value_t *single_val_range; bool do_value_subst_p; + unsigned num = num_ssa_names; if (dump_file) { @@ -7326,10 +7327,10 @@ vrp_finalize (void) /* We may have ended with ranges that have exactly one value. Those values can be substituted as any other const propagated value using substitute_and_fold. */ - single_val_range = XCNEWVEC (prop_value_t, num_ssa_names); + single_val_range = XCNEWVEC (prop_value_t, num); do_value_subst_p = false; - for (i = 0; i < num_ssa_names; i++) + for (i = 0; i < num; i++) if (vr_value[i] && vr_value[i]->type == VR_RANGE && vr_value[i]->min == vr_value[i]->max @@ -7357,7 +7358,7 @@ vrp_finalize (void) identify_jump_threads (); /* Free allocated memory. */ - for (i = 0; i < num_ssa_names; i++) + for (i = 0; i < num; i++) if (vr_value[i]) { BITMAP_FREE (vr_value[i]->equiv); Index: testsuite/gcc.dg/pr44699.c =================================================================== --- testsuite/gcc.dg/pr44699.c (revision 0) +++ testsuite/gcc.dg/pr44699.c (revision 0) @@ -0,0 +1,157 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +typedef long unsigned int size_t; +typedef long int intmax_t; +typedef long unsigned int uintmax_t; +extern void *xmalloc (size_t) __attribute__ ((__malloc__)); +extern const char *trim_filename (const char *); + +static __inline void * +__inline_memcpy_chk (void *__dest, const void *__src, size_t __len) +{ + return __builtin___memcpy_chk (__dest, __src, __len, __builtin_object_size (__dest, 0)); +} + +typedef unsigned int hashval_t; +typedef hashval_t (*htab_hash) (const void *); +typedef int (*htab_eq) (const void *, const void *); +typedef void (*htab_del) (void *); +typedef int (*htab_trav) (void **, void *); +typedef void *(*htab_alloc) (size_t, size_t); +typedef void (*htab_free) (void *); + +typedef void *(*htab_alloc_with_arg) (void *, size_t, size_t); +typedef void (*htab_free_with_arg) (void *, void *); +struct htab { + htab_hash hash_f; + htab_eq eq_f; + htab_del del_f; + void ** entries; + size_t size; + size_t n_elements; + size_t n_deleted; + unsigned int searches; + unsigned int collisions; + htab_alloc alloc_f; + htab_free free_f; + void * alloc_arg; + htab_alloc_with_arg alloc_with_arg_f; + htab_free_with_arg free_with_arg_f; + unsigned int size_prime_index; +}; + +typedef struct htab *htab_t; +enum insert_option {NO_INSERT, INSERT}; +extern void * htab_find (htab_t, const void *); +extern void ** htab_find_slot (htab_t, const void *, enum insert_option); + +enum mode_class { MODE_RANDOM, MODE_CC, MODE_INT, MODE_PARTIAL_INT, MODE_FRACT, MODE_UFRACT, MODE_ACCUM, MODE_UACCUM, MODE_FLOAT, MODE_DECIMAL_FLOAT, MODE_COMPLEX_INT, MODE_COMPLEX_FLOAT, MODE_VECTOR_INT, MODE_VECTOR_FRACT, MODE_VECTOR_UFRACT, MODE_VECTOR_ACCUM, MODE_VECTOR_UACCUM, MODE_VECTOR_FLOAT, MAX_MODE_CLASS }; + +static const char *const mode_class_names[MAX_MODE_CLASS] = +{ + "MODE_RANDOM", "MODE_CC", "MODE_INT", "MODE_PARTIAL_INT", "MODE_FRACT", "MODE_UFRACT", "MODE_ACCUM", "MODE_UACCUM", "MODE_FLOAT", "MODE_DECIMAL_FLOAT", "MODE_COMPLEX_INT", "MODE_COMPLEX_FLOAT", "MODE_VECTOR_INT", "MODE_VECTOR_FRACT", "MODE_VECTOR_UFRACT", "MODE_VECTOR_ACCUM", "MODE_VECTOR_UACCUM", "MODE_VECTOR_FLOAT" +}; +struct mode_data +{ + struct mode_data *next; + + const char *name; + enum mode_class cl; + unsigned int precision; + unsigned int bytesize; + unsigned int ncomponents; + unsigned int alignment; + const char *format; + + struct mode_data *component; + struct mode_data *wider; + struct mode_data *wider_2x; + + struct mode_data *contained; + + struct mode_data *next_cont; + + const char *file; + unsigned int line; + unsigned int counter; + unsigned int ibit; + unsigned int fbit; +}; + +static struct mode_data *modes[MAX_MODE_CLASS]; +static unsigned int n_modes[MAX_MODE_CLASS]; +static struct mode_data *void_mode; + +static const struct mode_data blank_mode = { + 0, "<unknown>", MAX_MODE_CLASS, + -1U, -1U, -1U, -1U, + 0, 0, 0, 0, 0, 0, + "<unknown>", 0, 0, 0, 0 +}; + +static htab_t modes_by_name; + +static __inline__ struct mode_data * +find_mode (const char *name) +{ + struct mode_data key; + + key.name = name; + return (struct mode_data *) htab_find (modes_by_name, &key); +} + +static struct mode_data * +new_mode (enum mode_class cl, const char *name, + const char *file, unsigned int line) +{ + struct mode_data *m; + static unsigned int count = 0; + + m = find_mode (name); + if (m) + { + error ("%s:%d: duplicate definition of mode \"%s\"", + trim_filename (file), line, name); + error ("%s:%d: previous definition here", m->file, m->line); + return m; + } + + m = ((struct mode_data *) xmalloc (sizeof (struct mode_data))); + ((__builtin_object_size (m, 0) != (size_t) -1) ? __builtin___memcpy_chk (m, &blank_mode, sizeof (struct mode_data), __builtin_object_size (m, 0)) : __inline_memcpy_chk (m, &blank_mode, sizeof (struct mode_data))); + m->cl = cl; + m->name = name; + if (file) + m->file = trim_filename (file); + m->line = line; + m->counter = count++; + + m->next = modes[cl]; + modes[cl] = m; + n_modes[cl]++; + + *htab_find_slot (modes_by_name, m, INSERT) = m; + + return m; +} + +static void +make_int_mode (const char *name, + unsigned int precision, unsigned int bytesize, + const char *file, unsigned int line) +{ + struct mode_data *m = new_mode (MODE_INT, name, file, line); + m->bytesize = bytesize; + m->precision = precision; +} + +static void +create_modes (void) +{ +make_int_mode ("HI", -1U, 2, "../../work/gcc/machmode.def", 182); +} + +int +main (int argc, char **argv) +{ + create_modes (); +}