https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88506
Bug ID: 88506 Summary: missing warning assigning to a pointer with incompatible attributes Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- Similar to bug 88505, GCC silently accepts assignments of addresses of functions to pointers declared with incompatible attributes. See the test case below. GCC should check the attributes on pointer initialization and assignment for compatibility and issue a warning if the destination is more restrictive than the source. $ cat u.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout u.c #include <stdlib.h> __attribute__ ((alloc_align (2), alloc_size (1))) void* (*paligned_alloc)(size_t, size_t) = aligned_alloc; size_t f (void) { size_t align = 16; void *p = paligned_alloc (48, align); return __builtin_object_size (p, 0); // bad alloc_size used } void g (void) { size_t align = 32; void *p = paligned_alloc (4, align); if ((long)p & (align - 1)) // bad alloc_align used __builtin_abort (); } ;; Function f (f, funcdef_no=10, decl_uid=2495, cgraph_uid=11, symbol_order=11) f () { void * (*<T46a>) (size_t, size_t) paligned_alloc.0_1; <bb 2> [local count: 1073741824]: paligned_alloc.0_1 = paligned_alloc; paligned_alloc.0_1 (48, 16); return 48; } ;; Function g (g, funcdef_no=11, decl_uid=2500, cgraph_uid=12, symbol_order=12) g () { void * (*<T46a>) (size_t, size_t) paligned_alloc.1_1; <bb 2> [local count: 1073741824]: paligned_alloc.1_1 = paligned_alloc; paligned_alloc.1_1 (4, 32); [tail call] return; } tmp$ cat u.c && /ssd/build/gcc-svn/gcc/xgcc -B /ssd/build/gcc-svn/gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout u.c