From patchwork Tue Jun 29 15:45:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 57284 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 755B3B6EF0 for ; Wed, 30 Jun 2010 01:46:03 +1000 (EST) Received: (qmail 10168 invoked by alias); 29 Jun 2010 15:46:01 -0000 Received: (qmail 10155 invoked by uid 22791); 29 Jun 2010 15:46:00 -0000 X-SWARE-Spam-Status: No, hits=-5.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor.suse.de (HELO mx1.suse.de) (195.135.220.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 29 Jun 2010 15:45:53 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 6294590975 for ; Tue, 29 Jun 2010 17:45:49 +0200 (CEST) Date: Tue, 29 Jun 2010 17:45:48 +0200 (CEST) From: Michael Matz To: gcc-patches@gcc.gnu.org Subject: [rfa] Fix PR44699: bootstrap problem Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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? Ciao, Michael. 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, "", MAX_MODE_CLASS, + -1U, -1U, -1U, -1U, + 0, 0, 0, 0, 0, 0, + "", 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 (); +}