On Wed, Nov 14, 2018 at 7:08 PM Jeff Law <l...@redhat.com> wrote: > > On 11/6/18 4:56 PM, Martin Sebor wrote: > > In response to Joseph's comment I've removed the interaction > > with -Wpedantic from the updated patch. > > > > In addition, to help detect bugs like the one in the test case > > for pr87886, I have also enhanced the detection of incompatible > > calls to include integer/real type mismatches so that calls like > > the one below are diagnosed: > > > > extern double sqrt (); > > int f (int x) > > { > > return sqrt (x); // passing int where double is expected > > } > > > > With the removal of the -Wpedantic interaction declaring abort() > > without a prototype is no longer diagnosed and so the test suite > > changes to add the prototype are not necessary. I decided not > > to back them out because Jeff indicated a preference for making > > these kinds of improvements in general in an unrelated > > discussion. > > > > > > > > gcc-83656.diff > > > > PR c/83656 - missing -Wbuiltin-declaration-mismatch on declaration without > > prototype > > > > gcc/c/ChangeLog: > > > > PR c/83656 > > * c-decl.c (header_for_builtin_fn): Declare. > > (diagnose_mismatched_decls): Diagnose declarations of built-in > > functions without a prototype. > > * c-typeck.c (maybe_warn_builtin_no_proto_arg): New function. > > (convert_argument): Same. > > (convert_arguments): Factor code out into convert_argument. > > Detect mismatches between built-in formal arguments in calls > > to built-in without prototype. > > (build_conditional_expr): Same. > > (type_or_builtin_type): New function. > > (convert_for_assignment): Add argument. Conditionally issue > > warnings instead of errors for mismatches. > > > > gcc/testsuite/ChangeLog: > > > > PR c/83656 > > * gcc.dg/20021006-1.c > > * gcc.dg/Wbuiltin-declaration-mismatch.c: New test. > > * gcc.dg/Wbuiltin-declaration-mismatch-2.c: New test. > > * gcc.dg/Wbuiltin-declaration-mismatch-3.c: New test. > > * gcc.dg/Wbuiltin-declaration-mismatch-4.c: New test. > > * gcc.dg/Walloca-16.c: Adjust. > > * gcc.dg/Wrestrict-4.c: Adjust. > > * gcc.dg/Wrestrict-5.c: Adjust. > > * gcc.dg/atomic/stdatomic-generic.c: Adjust. > > * gcc.dg/atomic/stdatomic-lockfree.c: Adjust. > > * gcc.dg/initpri1.c: Adjust. > > * gcc.dg/pr15698-1.c: Adjust. > > * gcc.dg/pr69156.c: Adjust. > > * gcc.dg/pr83463.c: Adjust. > > * gcc.dg/redecl-4.c: Adjust. > > * gcc.dg/tls/thr-init-2.c: Adjust. > > * gcc.dg/torture/pr55890-2.c: Adjust. > > * gcc.dg/torture/pr55890-3.c: Adjust. > > * gcc.dg/torture/pr67741.c: Adjust. > > * gcc.dg/torture/stackalign/sibcall-1.c: Adjust. > > * gcc.dg/torture/tls/thr-init-1.c: Adjust. > > * gcc.dg/tree-ssa/builtins-folding-gimple-ub.c: Adjust. > > > > > > @@ -3547,8 +3598,24 @@ convert_arguments (location_t loc, vec<location_t> > > arg_loc, tree typelist, > > if (parmval == error_mark_node) > > error_args = true; > > > > + if (!type && builtin_type && TREE_CODE (builtin_type) != VOID_TYPE) > > + { > > + /* For a call to a built-in function declared without a prototype, > > + perform the coversions from the argument to the expected type > > + but issue warnings rather than errors for any mismatches. > > + Ignore the converted argument and use the PARMVAL obtained > > + above by applying default coversions instead. */ > s/coversions/conversions/ > > Two of 'em in that comment. OK with that nit fixed.
I once had -Wunprototyped-calls... (attached). Because the issue doesn't exist only for builtins... (originally inspired by a Xorg bug) Richard. > jeff > >
Index: gcc/c-family/c.opt =================================================================== --- gcc/c-family/c.opt.orig 2014-11-11 09:38:31.286867405 +0100 +++ gcc/c-family/c.opt 2014-11-17 16:38:44.438078729 +0100 @@ -868,6 +868,10 @@ Wunused-local-typedefs C ObjC C++ ObjC++ Var(warn_unused_local_typedefs) Warning EnabledBy(Wunused) Warn when typedefs locally defined in a function are not used +Wunprototyped-calls +C Var(warn_unprototyped_calls) Warning LangEnabledBy(C,Wall) +Warn about calls to unprototyped functions with at least one argument + Wunused-macros C ObjC C++ ObjC++ CppReason(CPP_W_UNUSED_MACROS) Var(cpp_warn_unused_macros) Warning Warn about macros defined in the main file that are not used Index: gcc/c/c-typeck.c =================================================================== --- gcc/c/c-typeck.c.orig 2014-11-11 09:38:32.068867371 +0100 +++ gcc/c/c-typeck.c 2014-11-17 16:38:44.442078729 +0100 @@ -2957,6 +2957,19 @@ build_function_call_vec (location_t loc, && !check_builtin_function_arguments (fundecl, nargs, argarray)) return error_mark_node; + /* If we cannot check function arguments because a prototype is + missing for the callee, warn here. */ + if (warn_unprototyped_calls + && nargs > 0 && !TYPE_ARG_TYPES (fntype) + && fundecl && !DECL_BUILT_IN (fundecl) && !C_DECL_IMPLICIT (fundecl) + && !DECL_ARGUMENTS (fundecl)) + { + if (warning (OPT_Wunprototyped_calls, + "call to function %qD without a real prototype", fundecl)) + inform (DECL_SOURCE_LOCATION (fundecl), "%qD was declared here", + fundecl); + } + /* Check that the arguments to the function are valid. */ check_function_arguments (fntype, nargs, argarray); Index: gcc/testsuite/gcc.dg/cleanup-1.c =================================================================== --- gcc/testsuite/gcc.dg/cleanup-1.c.orig 2010-02-23 12:43:21.000000000 +0100 +++ gcc/testsuite/gcc.dg/cleanup-1.c 2014-11-17 16:38:44.442078729 +0100 @@ -6,7 +6,7 @@ #define C(x) __attribute__((cleanup(x))) static int f1(void *x U) { return 0; } -static void f2() { } +static void f2() { } /* { dg-message "declared here" "" } */ static void f3(void) { } /* { dg-message "note: declared here" } */ static void f4(void *x U) { } static void f5(int *x U) { } @@ -18,7 +18,7 @@ static void f9(int x U) { } /* { dg-mess void test(void) { int o1 C(f1); - int o2 C(f2); + int o2 C(f2); /* { dg-warning "without a real prototype" } */ int o3 C(f3); /* { dg-error "too many arguments" } */ int o4 C(f4); int o5 C(f5);