Bug 49585 - need a warning about new/malloc returning unsufficiently aligned memory
Summary: need a warning about new/malloc returning unsufficiently aligned memory
Status: RESOLVED DUPLICATE of bug 36159
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-30 04:47 UTC by Sergey Maslov
Modified: 2011-06-30 04:50 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Maslov 2011-06-30 04:47:02 UTC
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.
Comment 1 H.J. Lu 2011-06-30 04:50:54 UTC
Dup.

*** This bug has been marked as a duplicate of bug 36159 ***