On Wed, Oct 15, 2025 at 01:03:57PM +0100, Yury Khrustalev wrote:
> On Wed, Oct 15, 2025 at 01:48:49PM +0200, Richard Biener wrote:
> > On Wed, 15 Oct 2025, Yury Khrustalev wrote:
> > 
> > > Lack of DW_AT_bit_stride in a DW_TAG_array_type entry causes GDB to infer
> > > incorrect element size for vector types. The causes incorrect display of
> > > SVE predicate variables as well as out of bounds memory access when 
> > > reading
> > > contents of SVE predicates from memory in GDB.
> > > 
> > > We also locate DIE referenced by DW_AT_type and set DW_AT_bit_size 1 in 
> > > it.
> > >
> > > ...
> > > +  /* Add bit stride information to boolean vectors of single bits so that
> > > +     elements can be correctly read and displayed by a debugger.  */
> > > +  if (VECTOR_BOOLEAN_TYPE_P (type)
> > > +    && GET_MODE_CLASS (TYPE_MODE_RAW (type)) == MODE_VECTOR_BOOL)
> > > +    {
> > > +      /* MODE_VECTOR_BOOL implies that bit stride and bit size
> > > +  for element type must be 1.  */
> > 
> > Is that so?  I thought it wasn't.
> 
> In the gcc/mode-classes.def there is:
> 
> DEF_MODE_CLASS (MODE_VECTOR_BOOL),    /* vectors of single bits */
> 
> So, I interpreted "vector of single bits" as bit size=1 and stride=1.

That is not the case.
E.g. machmode.def says
     VECTOR_BOOL_MODE (NAME, COUNT, COMPONENT, BYTESIZE)
        Create a vector mode called NAME that contains COUNT boolean
        elements and occupies BYTESIZE bytes in total.  Each boolean
        element is of COMPONENT type and occupies (COUNT * BITS_PER_UNIT) /
        BYTESIZE bits, with the element at index 0 occupying the lsb of the
        first byte in memory.  Only the lowest bit of each element is
        significant.
So, either you decide on TYPE_MODE_RAW, and then it should support
all the different strides that are possible, i.e. query the mode
properties.  Or it should use a target hook where the backend decides
what stride and bit size to use for a particular type (or 0 for no
special handling), and in that case the backend can limit to types
that actually could appear in debug info.  So say if the 2/4/8-bit strides
are only possible on some temporary expressions and
variables/members/template arguments/function parameters etc. never have
such types, perhaps it can only handle what can appear there.

        Jakub

Reply via email to