This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Weird optimization for tuples?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: Gcc Mailing List <gcc at gcc dot gnu dot org>
- Date: Sun, 12 Feb 2017 12:36:34 +0000
- Subject: Re: Weird optimization for tuples?
- Authentication-results: sourceware.org; auth=none
- References: <3ac600d5-84e1-cc5e-e739-760d15453f98@davidgf.net>
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
>