https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87533
Bug ID: 87533 Summary: bogus assume_aligned attribute silently accepted Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The manual describes the assume_aligned attribute as follows: The assume_aligned attribute is used to tell the compiler that the function return value points to memory, where the returned pointer minimum alignment is given by the first argument. If the attribute has two arguments, the second argument is misalignment offset. Clearly, the first argument must be a power of two, and second argument should presumably be greater than (or perhaps equal to) zero and less than the value of the first argument. Finally, the attribute only makes sense on functions that return a pointer. Yet GCC silently accepts the following non-sensical declaration: $ cat c.c && gcc -S -Wall c.c __attribute ((assume_aligned (-1, -2))) void f (void) { } Clang, on the other hand, issues: c.c:1:15: warning: 'assume_aligned' attribute only applies to return values that are pointers or references [-Wignored-attributes] __attribute ((assume_aligned (-1, -2))) void f (void) { } ^~~~~~~~~~~~~~~~~~~~~~~ ~~~~ After the return type is changed to void*, Clang then issues the following: c.c:1:15: error: requested alignment is not a power of 2