[Bug c/86125] missing -Wbuiltin-declaration-mismatch on a mismatched return type

2019-01-28 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86125

--- Comment #7 from Jakub Jelinek  ---
Author: jakub
Date: Mon Jan 28 23:21:10 2019
New Revision: 268348

URL: https://gcc.gnu.org/viewcvs?rev=268348&root=gcc&view=rev
Log:
PR c/86125
* c-decl.c (last_fileptr_type): Remove.
(last_structptr_types): New variable.
(match_builtin_function_types): Compare TYPE_MAIN_VARIANT of
{old,new}rettype instead of the types themselves.  Assert
last_structptr_types array has the same number of elements
as builtin_structptr_types array.  Use TYPE_MAIN_VARIANT for
argument oldtype and newtype.  Instead of handling
just fileptr_type_node specially, handle all builtin_structptr_types
pointer nodes.  Formatting fix.

* c-common.c (c_common_nodes_and_builtins): Build type variants for
builtin_structptr_types types even for C.

* gcc.dg/Wbuiltin-declaration-mismatch-7.c: Guard testcase for
lp64, ilp32 and llp64 only.
(fputs): Use unsigned long long instead of size_t for return type.
(vfprintf, vfscanf): Accept arbitrary target specific type for
va_list.

Added:
trunk/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-11.c
Modified:
trunk/gcc/c-family/ChangeLog
trunk/gcc/c-family/c-common.c
trunk/gcc/c/ChangeLog
trunk/gcc/c/c-decl.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-7.c

[Bug c/86125] missing -Wbuiltin-declaration-mismatch on a mismatched return type

2019-01-24 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86125

Martin Sebor  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
  Known to work||9.0
 Resolution|--- |FIXED
   Target Milestone|--- |9.0
  Known to fail||8.2.0

--- Comment #6 from Martin Sebor  ---
The warning has been enhanced to detect the strlen mismatch in r268251, but it
requires -Wextra.  This was done to avoid diagnosing some more-or-less benign
mismatches (like in const qualifiers) but I don't think it applies as well when
the mismatch is between an integer and pointer.  But I suppose tightening that
up will need to wait for the future.  Let me resolve this as fixed and think
about opening a new bug for that.

$ gcc -S -Wall -Wextra pr86125.c
pr86125.c:1:7: warning: conflicting types for built-in function ‘strdup’;
expected ‘char *(const char *)’ [-Wbuiltin-declaration-mismatch]
1 | char* strdup (int);// warning (good)
  |   ^~
pr86125.c:2:7: warning: mismatch in return type of built-in function ‘strlen’;
expected ‘long unsigned int’ [-Wbuiltin-declaration-mismatch]
2 | char* strlen (const char*);// missing warning
  |   ^~

[Bug c/86125] missing -Wbuiltin-declaration-mismatch on a mismatched return type

2019-01-24 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86125

--- Comment #5 from Martin Sebor  ---
Author: msebor
Date: Thu Jan 24 21:06:01 2019
New Revision: 268251

URL: https://gcc.gnu.org/viewcvs?rev=268251&root=gcc&view=rev
Log:
PR c/86125 - missing -Wbuiltin-declaration-mismatch on a mismatched return type
PR middle-end/86308 - ICE in verify_gimple calling index() with an invalid
declaration
PR c/86125 - missing -Wbuiltin-declaration-mismatch on a mismatched return type
PR c/6 - [9 Regression] ice in get_constant, at c-family/c-format.c:292

gcc/c/ChangeLog:

PR c/86125
PR c/6
PR middle-end/86308
* c-decl.c (match_builtin_function_types): Add arguments.
(diagnose_mismatched_decls): Diagnose mismatched declarations
of built-ins more strictly.

gcc/testsuite/ChangeLog:

PR c/86125
PR c/6
PR middle-end/86308
* gcc.dg/Wbuiltin-declaration-mismatch-6.c: New test.
* gcc.dg/Wbuiltin-declaration-mismatch-7.c: New test.
* gcc.dg/Wbuiltin-declaration-mismatch-8.c: New test.
* gcc.dg/Wbuiltin-declaration-mismatch-9.c: New test.
* gcc.dg/Wbuiltin-declaration-mismatch-10.c: New test.
* gcc.dg/builtins-69.c: New test.
* gcc.dg/Wint-conversion-2.c: Add expected warning.
* gcc.c-torture/execute/eeprof-1.c: Adjust function signatures.


Added:
trunk/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-10.c
trunk/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-6.c
trunk/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-7.c
trunk/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-8.c
trunk/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-9.c
trunk/gcc/testsuite/gcc.dg/builtins-69.c
Modified:
trunk/gcc/c/ChangeLog
trunk/gcc/c/c-decl.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.c-torture/execute/eeprof-1.c
trunk/gcc/testsuite/gcc.dg/Wint-conversion-2.c

[Bug c/86125] missing -Wbuiltin-declaration-mismatch on a mismatched return type

2019-01-16 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86125

Martin Sebor  changed:

   What|Removed |Added

   Keywords||patch

--- Comment #4 from Martin Sebor  ---
Patch: https://gcc.gnu.org/ml/gcc-patches/2019-01/msg00969.html

[Bug c/86125] missing -Wbuiltin-declaration-mismatch on a mismatched return type

2018-06-12 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86125

Martin Sebor  changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2018-06-13
   Assignee|unassigned at gcc dot gnu.org  |msebor at gcc dot 
gnu.org
 Ever confirmed|0   |1

--- Comment #3 from Martin Sebor  ---
Testing a patch.

[Bug c/86125] missing -Wbuiltin-declaration-mismatch on a mismatched return type

2018-06-12 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86125

--- Comment #2 from Martin Sebor  ---
It looks like this is on purpose.  match_builtin_function_types, the function
that determines whether a declaration of a built-in matches its expected type,
has the following comment:

  /* Subroutine of compare_decls.  Allow harmless mismatches in return
 and argument types provided that the type modes match.  This function
 returns a unified type given a suitable match, and 0 otherwise.  */

and it uses TYPE_MODE (type) to decide whether return and argument types are
compatible.  That makes size_t and char* match on targets where they are the
same size, and ditto for int and char*.

C++, on the other hand, handles this more sanely and diagnoses the mismatch in
both cases:

c.c:2:7: warning: declaration of ‘char* strdup(int)’ conflicts with built-in
declaration ‘char* strdup(const char*)’ [-Wbuiltin-declaration-mismatch]
 char* strdup (int);// warning
   ^~
c.c:3:7: warning: declaration of ‘char* strlen(const char*)’ conflicts with
built-in declaration ‘long unsigned int strlen(const char*)’
[-Wbuiltin-declaration-mismatch]
 char* strlen (const char*);// warning
   ^~

[Bug c/86125] missing -Wbuiltin-declaration-mismatch on a mismatched return type

2018-06-12 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86125

Martin Sebor  changed:

   What|Removed |Added

   Keywords||diagnostic
   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=83656,
   ||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=86114

--- Comment #1 from Martin Sebor  ---
See also pr83656 and pr86114.