diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-01-29 00:21:10 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-01-29 00:21:10 +0100 |
commit | 6a335b9669b174c14a7811e967d199f2418e5f61 (patch) | |
tree | 85cea92aec24ac255926d31ec171d13aee1f49b4 /gcc/c | |
parent | ab1be99f2b005cb5b8b0b3caac19ab2edb0dd6f3 (diff) | |
download | gcc-6a335b9669b174c14a7811e967d199f2418e5f61.zip gcc-6a335b9669b174c14a7811e967d199f2418e5f61.tar.gz gcc-6a335b9669b174c14a7811e967d199f2418e5f61.tar.bz2 |
re PR c/86125 (missing -Wbuiltin-declaration-mismatch on a mismatched return type)
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.
From-SVN: r268348
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 70 |
2 files changed, 56 insertions, 27 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index cb89cd8..e6bff9c 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,16 @@ +2019-01-29 Jakub Jelinek <jakub@redhat.com> + + 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. + 2019-01-24 Martin Sebor <msebor@redhat.com> PR c/86125 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index b60f155..593b34e 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -1632,13 +1632,13 @@ c_bind (location_t loc, tree decl, bool is_global) } -/* Stores the first FILE* argument type (whatever it is) seen in - a declaration of a file I/O built-in. Subsequent declarations - of such built-ins are expected to refer to it rather than to - fileptr_type_node which is just void* (or to any other type). +/* Stores the first FILE*, const struct tm* etc. argument type (whatever it + is) seen in a declaration of a file I/O etc. built-in. Subsequent + declarations of such built-ins are expected to refer to it rather than to + fileptr_type_node etc. which is just void* (or to any other type). Used only by match_builtin_function_types. */ -static GTY(()) tree last_fileptr_type; +static GTY(()) tree last_structptr_types[6]; /* Subroutine of compare_decls. Allow harmless mismatches in return and argument types provided that the type modes match. Set *STRICT @@ -1660,13 +1660,18 @@ match_builtin_function_types (tree newtype, tree oldtype, if (TYPE_MODE (oldrettype) != TYPE_MODE (newrettype)) return NULL_TREE; - if (!comptypes (oldrettype, newrettype)) + if (!comptypes (TYPE_MAIN_VARIANT (oldrettype), + TYPE_MAIN_VARIANT (newrettype))) *strict = oldrettype; tree oldargs = TYPE_ARG_TYPES (oldtype); tree newargs = TYPE_ARG_TYPES (newtype); tree tryargs = newargs; + gcc_checking_assert ((sizeof (last_structptr_types) + / sizeof (last_structptr_types[0])) + == (sizeof (builtin_structptr_types) + / sizeof (builtin_structptr_types[0]))); for (unsigned i = 1; oldargs || newargs; ++i) { if (!oldargs @@ -1675,8 +1680,8 @@ match_builtin_function_types (tree newtype, tree oldtype, || !TREE_VALUE (newargs)) return NULL_TREE; - tree oldtype = TREE_VALUE (oldargs); - tree newtype = TREE_VALUE (newargs); + tree oldtype = TYPE_MAIN_VARIANT (TREE_VALUE (oldargs)); + tree newtype = TYPE_MAIN_VARIANT (TREE_VALUE (newargs)); /* Fail for types with incompatible modes/sizes. */ if (TYPE_MODE (TREE_VALUE (oldargs)) @@ -1684,28 +1689,39 @@ match_builtin_function_types (tree newtype, tree oldtype, return NULL_TREE; /* Fail for function and object pointer mismatches. */ - if (FUNCTION_POINTER_TYPE_P (oldtype) != FUNCTION_POINTER_TYPE_P (newtype) + if ((FUNCTION_POINTER_TYPE_P (oldtype) + != FUNCTION_POINTER_TYPE_P (newtype)) || POINTER_TYPE_P (oldtype) != POINTER_TYPE_P (newtype)) return NULL_TREE; - if (oldtype == fileptr_type_node) - { - /* Store the first FILE* argument type (whatever it is), and - expect any subsequent declarations of file I/O built-ins - to refer to it rather than to fileptr_type_node which is - just void*. */ - if (last_fileptr_type) - { - if (!comptypes (last_fileptr_type, newtype)) - { - *argno = i; - *strict = last_fileptr_type; - } - } - else - last_fileptr_type = newtype; - } - else if (!*strict && !comptypes (oldtype, newtype)) + unsigned j = (sizeof (builtin_structptr_types) + / sizeof (builtin_structptr_types[0])); + if (POINTER_TYPE_P (oldtype)) + for (j = 0; j < (sizeof (builtin_structptr_types) + / sizeof (builtin_structptr_types[0])); ++j) + { + if (TREE_VALUE (oldargs) != builtin_structptr_types[j].node) + continue; + /* Store the first FILE* etc. argument type (whatever it is), and + expect any subsequent declarations of file I/O etc. built-ins + to refer to it rather than to fileptr_type_node etc. which is + just void* (or const void*). */ + if (last_structptr_types[j]) + { + if (!comptypes (last_structptr_types[j], newtype)) + { + *argno = i; + *strict = last_structptr_types[j]; + } + } + else + last_structptr_types[j] = newtype; + break; + } + if (j == (sizeof (builtin_structptr_types) + / sizeof (builtin_structptr_types[0])) + && !*strict + && !comptypes (oldtype, newtype)) { *argno = i; *strict = oldtype; |