This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [libstdc++/65033] Give alignment info to libatomic
- From: Hans-Peter Nilsson <hp at bitrange dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: Richard Henderson <rth at redhat dot com>, libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 7 Apr 2015 10:51:01 -0400 (EDT)
- Subject: Re: [libstdc++/65033] Give alignment info to libatomic
- Authentication-results: sourceware.org; auth=none
- References: <54DD19B7 dot 6060401 at redhat dot com> <alpine dot BSF dot 2 dot 02 dot 1504022240580 dot 40679 at arjuna dot pair dot com> <alpine dot BSF dot 2 dot 02 dot 1504030518160 dot 69548 at arjuna dot pair dot com> <20150403141333 dot GY9755 at redhat dot com> <alpine dot BSF dot 2 dot 02 dot 1504052052110 dot 29977 at arjuna dot pair dot com> <20150407094458 dot GA9755 at redhat dot com> <alpine dot BSF dot 2 dot 02 dot 1504070641560 dot 16304 at arjuna dot pair dot com> <20150407131252 dot GB9755 at redhat dot com>
On Tue, 7 Apr 2015, Jonathan Wakely wrote:
> On 07/04/15 06:51 -0400, Hans-Peter Nilsson wrote:
> > On Tue, 7 Apr 2015, Jonathan Wakely wrote:
> > > On 05/04/15 21:07 -0400, Hans-Peter Nilsson wrote:
> > > > We did specify that with the alignas. Is the alignof always
> > > > exactly the same as an alignas, if one is specified? (And will
> > > > that not change in a future amendment, standard and/or
> > > > implementation?) Either way, is there a test-case to guard all
> > > > this?
> > >
> > > The language guarantees that's what alignas() does, if the argument is
> > > a valid alignment (which it must be if we derive it from some other
> > > type's alignment).
> >
> > I'm more worried about alignof reporting a higher value for a
> > specific object than alignas to be wrong.
>
> That shouldn't be possible because the C++ standard says it's an error
> to use alignas with a less strict alignment than would be used if it
> was omitted, i.e. an error to use alignas with a value less than the
> result alignof would give. However, G++ doesn't reject it (PR65685).
>
> It still won't be possible here, because the alignas value we use is
> not less than alignof(_Tp).
That's not what I meant. My worry is there being a case where
alignof yields a *higher* value than the one that the alignas
specified.
> > Your question quoted just below seems to indicate a similar
> > worry.
>
> I was thinking about cases like this:
>
> struct __attribute__((packed)) Bad {
> char c;
> std::atomic<long long> a;
> };
>
> But G++ ignores the packed attribute here, which is good (Clang
> doesn't seem to ignore it, and mis-aligns the atomic).
I was more thinking of something like:
#include <atomic>
#include <iostream>
using std::cout;
using std::endl;
struct SoSo {
double d;
int x alignas(sizeof(int));
};
SoSo s __attribute__((__aligned__(16)));
int main(void)
{
cout << "alignof(s): " << alignof(s) << endl;
cout << "alignof(s.d): " << alignof(s.d) << endl;
cout << "alignof(s.x): " << alignof(s.x) << endl;
}
in which I fear s.x would get an alignof the same as the s.d or
s, now or after a while, i.e. higher than specified.
(I get for cris-elf at revision 221891:
alignof(s): 16
alignof(s.d): 1
alignof(s.x): 4
which is kind-of-expected except I thought s.d would get the s
alignment so that just leaves it open whether that could
possibly change.)
brgds, H-P