This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [lto/pph] Do not pack more bits than requested (issue4415044)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Diego Novillo <dnovillo at google dot com>
- Cc: reply at codereview dot appspotmail dot com, rguenther at suse dot de, gcc-patches at gcc dot gnu dot org
- Date: Thu, 14 Apr 2011 21:28:53 +0200
- Subject: Re: [lto/pph] Do not pack more bits than requested (issue4415044)
- References: <20110414185053.6C532A00D@topo.tor.corp.google.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Apr 14, 2011 at 02:50:53PM -0400, Diego Novillo wrote:
> @@ -1190,8 +1190,19 @@ bitpack_create (struct lto_output_stream *s)
> static inline void
> bp_pack_value (struct bitpack_d *bp, bitpack_word_t val, unsigned nbits)
> {
> - bitpack_word_t word = bp->word;
> + bitpack_word_t mask, word;
> int pos = bp->pos;
> +
> + word = bp->word;
> +
> + gcc_assert (nbits > 0 && nbits <= BITS_PER_BITPACK_WORD);
> +
> + /* Make sure that VAL only has the lower NBITS set. Generate a
> + mask with the lower NBITS set and use it to filter the upper
> + bits from VAL. */
> + mask = ((bitpack_word_t) 1 << nbits) - 1;
If bitpack_word_t has BITS_PER_BITPACK_WORD bits, then for
nbits = BITS_PER_BITPACK_WORD this will be undefined.
Use say
mask = ((bitpack_word_t) 2 << (nbits - 1)) - 1;
or something similar (assertion ensures that nbits isn't 0).
Jakub