public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/38455] New: aligned struct members in heap-allocated code
@ 2008-12-09 17:02 tim at klingt dot org
2008-12-09 17:16 ` [Bug c++/38455] " brian at dessent dot net
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: tim at klingt dot org @ 2008-12-09 17:02 UTC (permalink / raw)
To: gcc-bugs
the following code works on x86_64 as 64-bit binary, but the alignment
constraints of heap-allocated structs are not matched, when compiling 32-bit
code:
#include <assert.h>
template <int size = 4>
struct aligned_buffer
{
char padding;
float data[size] __attribute__((aligned((16))));
};
struct my_struct
{
aligned_buffer<> buf1;
char padding;
aligned_buffer<> buf2;
};
int main()
{
{
aligned_buffer<> ab;
assert((long)&ab.data % 16 == 0);
}
{
my_struct m;
assert((long)&m.buf1.data % 16 == 0);
assert((long)&m.buf2.data % 16 == 0);
}
{
aligned_buffer<> * ab = new aligned_buffer<>();
assert((long)&ab->data % 16 == 0); /* fails */
}
{
my_struct * m = new my_struct();
assert((long)&m->buf1.data % 16 == 0); /* fails */
assert((long)&m->buf2.data % 16 == 0); /* fails */
delete m;
}
}
g++ -m32: int main(): Assertion `(long)&ab->data % 16 == 0' failed.
g++ -m64: works fine
when changing the alignment from 16 to 64, the alignment constraints for
heap-allocated structs fail with both -m32 and -m64.
--
Summary: aligned struct members in heap-allocated code
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tim at klingt dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38455
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/38455] aligned struct members in heap-allocated code
2008-12-09 17:02 [Bug c++/38455] New: aligned struct members in heap-allocated code tim at klingt dot org
@ 2008-12-09 17:16 ` brian at dessent dot net
2008-12-09 17:24 ` tim at klingt dot org
2008-12-09 17:56 ` rguenth at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: brian at dessent dot net @ 2008-12-09 17:16 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from brian at dessent dot net 2008-12-09 17:14 -------
Subject: Re: New: aligned struct members in heap-allocated code
This is a dup of pr15795. Basically, operator new is just a wrapper
around malloc from the libc, and malloc returns an allocation with a
fixed alignment (8 for x86 and 16 for x86_64 in the case of glibc.)
There is no way to communicate any alignment requirement to malloc(), so
you'd have to override operator new to use posix_memalign() or something
in this case.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38455
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/38455] aligned struct members in heap-allocated code
2008-12-09 17:02 [Bug c++/38455] New: aligned struct members in heap-allocated code tim at klingt dot org
2008-12-09 17:16 ` [Bug c++/38455] " brian at dessent dot net
@ 2008-12-09 17:24 ` tim at klingt dot org
2008-12-09 17:56 ` rguenth at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: tim at klingt dot org @ 2008-12-09 17:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from tim at klingt dot org 2008-12-09 17:23 -------
well, would be nice to read something like that in the attribute documentation
...
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38455
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/38455] aligned struct members in heap-allocated code
2008-12-09 17:02 [Bug c++/38455] New: aligned struct members in heap-allocated code tim at klingt dot org
2008-12-09 17:16 ` [Bug c++/38455] " brian at dessent dot net
2008-12-09 17:24 ` tim at klingt dot org
@ 2008-12-09 17:56 ` rguenth at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-12-09 17:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2008-12-09 17:43 -------
*** This bug has been marked as a duplicate of 15795 ***
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38455
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-12-09 17:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-09 17:02 [Bug c++/38455] New: aligned struct members in heap-allocated code tim at klingt dot org
2008-12-09 17:16 ` [Bug c++/38455] " brian at dessent dot net
2008-12-09 17:24 ` tim at klingt dot org
2008-12-09 17:56 ` rguenth at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).