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: unassig...@gcc.gnu.org
        ReportedBy: sergey.v.mas...@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.

Reply via email to