This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49585] New: need a warning about new/malloc returning unsufficiently aligned memory
- From: "sergey.v.maslov at intel dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 30 Jun 2011 04:47:04 +0000
- Subject: [Bug c++/49585] New: need a warning about new/malloc returning unsufficiently aligned memory
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49585
Summary: need a warning about new/malloc returning
unsufficiently aligned memory
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: sergey.v.maslov@intel.com
Consider the following test case:
#define alignement 64
struct test {
public:
int toto[100] __attribute__((aligned(alignement)));
};
int main () {
test* t = new test();
printf("%ld\n",(unsigned long)(&(t->toto[0])) % alignement);
return 0;
}
This program typically prints a non-zero value, whereas customers would
actually expect 0. This is due to default "new" (presumably doing malloc) only
gurantees 16 byte alignment.
Compiler should detect when a default new operator is used to allocate
unsufficiently aligned memory, and issue a relevent user diagnostics.
BTW, this issues can cause severe stability problems in AVX compilation, where
32-byte is the typical requirement for 256-bit AVX data types.