This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] libstdc++/66017 Avoid bad casts and fix alignment of _Rb_tree_node<long long>::_M_storage
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: Jason Merrill <jason at redhat dot com>, libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 22 May 2015 17:13:42 +0200
- Subject: Re: [patch] libstdc++/66017 Avoid bad casts and fix alignment of _Rb_tree_node<long long>::_M_storage
- Authentication-results: sourceware.org; auth=none
- References: <20150522141510 dot GN30202 at redhat dot com> <20150522142944 dot GM10247 at tucnak dot redhat dot com> <20150522145947 dot GO30202 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Fri, May 22, 2015 at 03:59:47PM +0100, Jonathan Wakely wrote:
> >>+ alignas(alignof(_Tp2)) unsigned char _M_storage[sizeof(_Tp)];
> >
> >Is alignof(_Tp2) always the same as alignof(_Tp2::_M_t) on all targets
> >(I mean, won't some target align the structure more than its only field)?
>
> Hmm, maybe. I don't know.
>
> >Wouldn't it be safer to use alignof(_Tp2::_M_t) here?
>
> Yes.
>
> >Though, apparently that is a GNU extension, so you'd need to use __alignof__
> >instead.
>
> Yes, that's what I did in an earlier version of the patch, so I'll go
> back to that.
Just grepped around, and e.g. on powerpc64le-linux -std=c++11 -malign-power -O2
typedef double _Tp;
struct _Tp2 { _Tp _M_t; };
extern _Tp2 tp2e;
int a = alignof(_Tp2);
int b = __alignof__(_Tp2::_M_t);
int c = alignof(_Tp);
int d = __alignof__(tp2e._M_t);
int e = alignof(_Tp2::_M_t);
we have a = 8, b = 4, c = 8, d = 4, e = 4.
Note clang++ with -pedantic-errors errors out on alignof(_Tp2::_M_t) though.
Jakub