Bug 19163 - __attribute__((aligned)) not working in template
Summary: __attribute__((aligned)) not working in template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Jason Merrill
URL:
Keywords: patch, wrong-code
Depends on:
Blocks: 17743
  Show dependency treegraph
 
Reported: 2004-12-27 11:24 UTC by Paolo Carlini
Modified: 2007-09-22 14:28 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.0
Known to fail:
Last reconfirmed: 2007-09-06 06:11:31


Attachments
Untested patch (357 bytes, patch)
2004-12-27 13:21 UTC, Giovanni Bajo
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paolo Carlini 2004-12-27 11:24:55 UTC
Unfortunately, it looks like even the very limited functionality of aligned vs
template (see, e.g., c++/17743) is broken and I cannot even attempt implementing
tr1::type_traits::aligned_storage: the attribute seems completely ignored,
otherwise I could at least provide specializations for Align = 1,2,4,8,16...

Needless to say, Icc seems ok :(

Testcase (but, in case please test partial specializations too!):

//////////////

struct A
{ typedef char type[4] __attribute__((aligned(4))); };

template<unsigned _Len>
  struct B
  { typedef char type[_Len] __attribute__((aligned(4))); };

template<bool> struct StaticAssert;
template<> struct StaticAssert<true> {};

StaticAssert<__alignof__(A::type) == __alignof__(B<4>::type)> a1;
StaticAssert<__alignof__(B<4>::type) == 4> a2;

/////////////////

Giovanni can you please have a look?!? Thanks!
Comment 1 Giovanni Bajo 2004-12-27 13:18:18 UTC
We lose the alignment while tsubsting. This is a quick patch for this, I'm not 
sure if there are other information we should propagate from the original array 
type to the new array type, I guess the reviewer will know.

Meanwhile, Paolo, mind if I ask you to test this patch for me? You can also 
test the partial specialization, it looks like it works for me.
Comment 2 Giovanni Bajo 2004-12-27 13:21:17 UTC
Created attachment 7828 [details]
Untested patch

Here is the patch
Comment 3 Paolo Carlini 2004-12-27 13:24:33 UTC
> Meanwhile, Paolo, mind if I ask you to test this patch for me? You can also 
> test the partial specialization, it looks like it works for me.

Sure, I will: expect some feedback from me before the end of the day! Thank
you very much for the quick help!!

Comment 4 Paolo Carlini 2004-12-27 15:45:03 UTC
Hi again! Yes, I can confirm that the patch works fine here: regtests ok and
both the above testcase and the below pass with it, which basically amounts
to making possible a decent implementation of tr1::type_traits::aligned_storage
Thanks Giovanni! Please post your complete work ASAP and let's have this fixed
for 4.0 too, if possible!

//////////////////

struct A
{ typedef char type[4] __attribute__((aligned(4))); };

template<unsigned, unsigned>
  struct B;

template<unsigned _Len>
  struct B<_Len, 4>
  { typedef char type[_Len] __attribute__((aligned(4))); };

template<bool> struct StaticAssert;
template<> struct StaticAssert<true> {};

StaticAssert<__alignof__(A::type) == __alignof__(B<4, 4>::type)> a1;
StaticAssert<__alignof__(B<4, 4>::type) == 4> a2;

//////////////////
Comment 5 Paolo Carlini 2004-12-27 15:46:38 UTC
... forgot to specify: regtested on x86_64-linux.
Comment 6 Giovanni Bajo 2004-12-27 22:07:45 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01975.html
Comment 7 Gabriel Dos Reis 2004-12-29 18:57:23 UTC
Subject: Re:  New: __attribute__((aligned)) not working in template

"pcarlini at suse dot de" <gcc-bugzilla@gcc.gnu.org> writes:

| Unfortunately, it looks like even the very limited functionality of aligned vs
| template (see, e.g., c++/17743) is broken and I cannot even attempt implementing
| tr1::type_traits::aligned_storage: the attribute seems completely ignored,
| otherwise I could at least provide specializations for Align = 1,2,4,8,16...

Did I already open a PR for this misbehaviour in the past?  What
happened?

-- Gaby
Comment 8 Paolo Carlini 2004-12-29 19:05:44 UTC
> Did I already open a PR for this misbehaviour in the past?  What
> happened?

Yes, Gaby, the issue at large is clear, by now: see c++/17743. Here, we are
just trying to achieve *minimal* functionality, when the espression in the
attribute is not dependent: among other things (currently __align__ inside
templates is *totally* broken :( this would allow me to provide a decent first
implementation of aligned_storage via specializations for Align=1,2,4,8,16
There is an updated patch ready, which seems to me rather safe

  http://gcc.gnu.org/ml/gcc-patches/2004-12/msg02003.html

Paolo.
Comment 9 Giovanni Bajo 2005-10-06 06:44:08 UTC
The patch was rejected. Not working on this anymore.
Comment 10 Jason Merrill 2007-09-06 05:50:40 UTC
Vague references:

http://gcc.gnu.org/ml/gcc-patches/2005-10/msg00247.html
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17743

Seems like Mark and/or Nathan have/had state on this that they haven't shared with the lists.
Comment 11 Mark Mitchell 2007-09-06 06:16:54 UTC
Subject: Re:  __attribute__((aligned)) not working in template

jason at gcc dot gnu dot org wrote:
> ------- Comment #10 from jason at gcc dot gnu dot org  2007-09-06 05:50 -------
> Vague references:
> 
> http://gcc.gnu.org/ml/gcc-patches/2005-10/msg00247.html
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17743
> 
> Seems like Mark and/or Nathan have/had state on this that they haven't shared
> with the lists.

I don't think so, but I'm not quite sure I understand.  Anyhow, I'm sure
I don't have any uncontributed patches for this, and I don't think
Nathan has either.

Comment 12 Nathan Sidwell 2007-09-06 08:15:39 UTC
Subject: Re:  __attribute__((aligned)) not working in template

mark at codesourcery dot com wrote:

> I don't think so, but I'm not quite sure I understand.  Anyhow, I'm sure
> I don't have any uncontributed patches for this, and I don't think
> Nathan has either.

I do not.  I remember looking at it, but didn't get anywhere.

nathan
Comment 13 Benjamin Kosnik 2007-09-06 21:00:40 UTC
Yo!

Jason, fixing this would be most appreciated by the library hackers. This is one of those things that I would really like to see implemented before C++0x gets too far down the road... there is a bunch of stuff depending on this, from both C++0x and TR1.

Also, I believe that the deprecated attribute issue is also related to some of these issues.

Those bugzilla numbas are:

15269
16370

best,
benjamin



Comment 14 Jason Merrill 2007-09-22 14:28:22 UTC
Fixed for 4.3.0.