http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56434



             Bug #: 56434

           Summary: document that __attribute__((__malloc__)) assumes

                    returned pointer has BIGGEST_ALIGNMENT

    Classification: Unclassified

           Product: gcc

           Version: 4.7.2

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: c

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: c...@pobox.com





The docs say that __attribute__((__malloc__)) only has one effect: informing

the compiler that returned pointers do not alias other pointers.  But reading

the compiler output, and then reading gcc source code, proves that it also has

a second effect: informing the compiler that returned pointers are aligned to

BIGGEST_ALIGNMENT.  To quote expand_call:



          /* The return value from a malloc-like function is a pointer.  */

          if (TREE_CODE (rettype) == POINTER_TYPE)

            mark_reg_pointer (temp, BIGGEST_ALIGNMENT);



This should be added to the documentation.



As a side issue, BIGGEST_ALIGNMENT changes on the i386 target depending on

whether -mavx is specified (128 vs. 256).  Is it really a good idea for gcc to

assume different things about the behavior of malloc() depending on -mavx?  It

seems that perhaps an alignment of 128 should always be conferred on malloc on

the i386 platform, regardless of -mavx?



What would the new target macro be?  SMALLEST_BIGGEST_ALIGNMENT?  :)

Reply via email to