On Thu, Sep 16, 2021 at 12:41:20PM +0200, Richard Biener wrote:
> On Thu, 16 Sep 2021, Jakub Jelinek wrote:
> 
> > On Thu, Sep 16, 2021 at 11:48:49AM +0200, Richard Biener via Gcc-patches 
> > wrote:
> > > 2021-09-16  Richard Biener  <rguent...@suse.de>
> > > 
> > >   PR middle-end/102360
> > >   * internal-fn.c (expand_DEFERRED_INIT): Make pattern-init
> > >   of non-memory more robust.
> > > 
> > >   * g++.dg/pr102360.C: New testcase.
> > > +   if (can_native_interpret_type_p (var_type))
> > > +     init = native_interpret_expr (var_type, buf, total_bytes);
> > > +   else
> > > +     {
> > > +       tree itype = build_nonstandard_integer_type (total_bytes * 8, 1);
> > 
> > Shouldn't that 8 be BITS_PER_UNIT ?
> > I know we have tons of problems with BITS_PER_UNIT is not 8, but adding
> > further ones is unnecessary.
> 
> Well, a byte is 8 bits and we do
> 
>       unsigned HOST_WIDE_INT total_bytes
>         = tree_to_uhwi (TYPE_SIZE_UNIT (var_type));
> 
>       if (init_type == AUTO_INIT_PATTERN)
>         {
>           unsigned char *buf = (unsigned char *) xmalloc (total_bytes);
>           memset (buf, INIT_PATTERN_VALUE, total_bytes);
> 
> and thus mix host and target here.  I suppose it should be instead
> 
>    unsigned HOST_WIDE_INT total_bytes
>      = tree_to_uhwi (TYPE_SIZE (var_type)) / (BITS_PER_UNIT / 8);
> 
> or so...  in this light * 8 for the build_nonstandard_integer_type
> use is correct, no?  If total_bytes is really _bytes_.

Typically for the native_interpret/native_encode we punt if
BITS_PER_UNIT != 8 || CHAR_BIT != 8 because nobody had the energy
to deal with the weird platforms (especially if we have currently
none, I believe dsp16xx that had 16-bit bytes had been removed in 4.0
and c4x that had 32-bit bytes had been removed in 4.3)
- dunno if the DEFERRED_INIT etc. code has those guards or not
and it clearly documents that this code is not ready for other
configurations.
A byte is not necessarily 8 bits, that is just the most common
size for it, and TYPE_SIZE_UNIT is number of BITS_PER_UNIT bit units.

        Jakub

Reply via email to