aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2021-04-29 00:50:35 +0000
committerJoseph Myers <joseph@codesourcery.com>2021-04-29 00:50:35 +0000
commitcc806126215c3f4dc187eff3bf923458d8cc6b4f (patch)
tree385f40e18a505a514b5cb9d3b074c6afc6e67d42 /gcc/c
parente4ff4ffb43d3d8520f1c106e04421f2e6a021c39 (diff)
downloadgcc-cc806126215c3f4dc187eff3bf923458d8cc6b4f.zip
gcc-cc806126215c3f4dc187eff3bf923458d8cc6b4f.tar.gz
gcc-cc806126215c3f4dc187eff3bf923458d8cc6b4f.tar.bz2
c: C2x changes to function type compatibility
WG14 N2432, the C2x removal of old-style function definitions, also changed the function type compatibility rules so that an unprototyped declaration can be compatible with a non-variadic prototyped declaration even if some function arguments are changed by the default argument promotions. I missed that change in the initial implementation for GCC of the rest of the N2432 changes, but discussion on the WG14 reflector in February suggests that this is indeed an intended change. Implement this in the C front end. Note that while this may be of use in some cases for use of pointers to unprototyped function types as a kind of generic function pointer, it's *not* possible to call such a function without a prototype visible, without getting runtime undefined behavior from the (promoted) type used in the call being incompatible with the (unpromoted) type in the prototype. Note also that GCC has a longstanding extension to allow compatibility of such a prototype with an old-style definition specifying the same type as in the prototype (which is not valid in ISO C, before old-style definitions were removed in C2x). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/c/ * c-typeck.c (function_types_compatible_p): For C2X, treat unprototyped function as compatible with non-variadic prototyped function even if some argument types are changed by the default argument promotions. gcc/testsuite/ * gcc.dg/c11-unproto-1.c, gcc.dg/c11-unproto-2.c, gcc.dg/c2x-unproto-1.c, gcc.dg/c2x-unproto-2.c: New tests.
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/c-typeck.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 51a62c8..3b45cfd 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -1692,7 +1692,7 @@ function_types_compatible_p (const_tree f1, const_tree f2,
if (args1 == NULL_TREE)
{
- if (!self_promoting_args_p (args2))
+ if (flag_isoc2x ? stdarg_p (f2) : !self_promoting_args_p (args2))
return 0;
/* If one of these types comes from a non-prototype fn definition,
compare that with the other type's arglist.
@@ -1705,7 +1705,7 @@ function_types_compatible_p (const_tree f1, const_tree f2,
}
if (args2 == NULL_TREE)
{
- if (!self_promoting_args_p (args1))
+ if (flag_isoc2x ? stdarg_p (f1) : !self_promoting_args_p (args1))
return 0;
if (TYPE_ACTUAL_ARG_TYPES (f2)
&& type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2),