https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83339
Bug ID: 83339 Summary: missing warning on a invalid attribute specified for a builtin Product: gcc Version: 8.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 patch for pr81544 enhanced GCC to detect declarations of functions with conflicting attributes such as const and pure. However, the enhancement fails to detect attributes on explicit declarations of standard library functions that conflict with GCC's internal declarations of the same functions that do not specify an attribute that's mutually exclusive with the explicit declaration. For instance, declaring the function puts() with either the const or pure attribute makes no sense because puts() has side-effects. Yet GCC silently accepts such declarations and makes use of the incorrect attribute to emit bad code. For instance, GCC eliminates the calls to the function in the following program: $ gcc -O -S -Wall -fdump-tree-optimized=/dev/stdout d.c int __attribute__ ((const)) puts (const char*); int main () { (void)puts ("foo"); // eliminated (void)puts ("bar"); // eliminated } ;; Function main (main, funcdef_no=0, decl_uid=1893, cgraph_uid=0, symbol_order=0) (executed once) main () { <bb 2> [local count: 1073741825]: return 0; } Besides detecting conflicts between two attributes, at least for built-in functions, GCC should also detect conflicts between an explicit declaration with an attribute and an implicit declaration without one.