This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Weird optimization for tuples?


I've answered on gcc-help instead.

On 12 February 2017 at 00:55, David Guillen Fandos <david@davidgf.net> wrote:
> Hello!
>
> I have the following function
> std::tuple<uint32_t, uint8_t> getRawIdx(uint16_t tidx) {
>   return std::make_tuple(localidx.entries[tidx].indx_ptr,
> localidx.entries[tidx].indx_size);
> }
>
> Where s is a struct like
>
> typedef struct __attribute__((packed)) {
>         uint32_t indx_ptr;
>         uint8_t  indx_size;
> } _i_idx_entry ;
>
> The error I get is:
>
>  cannot bind packed field
> ‘((DBIndex*)this)->DBIndex::localidx.DBIndex::_i_idx::entries[((int)tidx)].DBIndex::_i_idx_entry::indx_ptr’
> to ‘unsigned int&’
>
> If extend the tuple to include a 3rd field and I return some other thing
> it just works:
>
> return std::make_tuple(localidx.entries[tidx].indx_ptr,
>                        localidx.entries[tidx].indx_size,
>                        tidx, prefb);
>
> I think gcc is trying to do some smart optimization or something and
> packed does not work because of tuple alignments not being packed.
>
> Any ideas?
> Thanks!
> David
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]