From db1d09b049a9388c481ff76aa00fe74734cce1c8 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Fri, 23 Nov 2018 18:23:31 +0000 Subject: [PATCH] PR testsuite/88098 - FAIL: gcc.dg/Wbuiltin-declaration-mismatch-4.c gcc/c/ChangeLog: PR testsuite/88098 * c-typeck.c (convert_arguments): Call builtin_decl_explicit instead. (maybe_warn_builtin_no_proto_arg): Handle short enum to int promotion. gcc/testsuite/ChangeLog: PR testsuite/88098 * gcc.dg/Wbuiltin-declaration-mismatch-4.c: Adjust. * gcc.dg/Wbuiltin-declaration-mismatch-5.c: New test. * gcc.dg/torture/pr67222.c: Adjust. From-SVN: r266417 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-typeck.c | 9 +++++++-- gcc/testsuite/ChangeLog | 7 +++++++ .../gcc.dg/Wbuiltin-declaration-mismatch-4.c | 7 ++++--- .../gcc.dg/Wbuiltin-declaration-mismatch-5.c | 19 +++++++++++++++++++ gcc/testsuite/gcc.dg/torture/pr67222.c | 8 +++++++- 6 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-5.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 0b73df94db1..bcb282c084e 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2018-11-23 Martin Sebor + + PR testsuite/88098 + * c-typeck.c (convert_arguments): Call builtin_decl_explicit instead. + (maybe_warn_builtin_no_proto_arg): Handle short enum to int promotion. + 2018-11-20 Martin Sebor * c-parser.c (c_parser_has_attribute_expression): New function. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index bdfcb53c9fd..81c520ade39 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -3422,7 +3422,10 @@ convert_arguments (location_t loc, vec arg_loc, tree typelist, built_in_function code = DECL_FUNCTION_CODE (fundecl); if (C_DECL_BUILTIN_PROTOTYPE (fundecl)) { - if (tree bdecl = builtin_decl_implicit (code)) + /* For a call to a built-in function declared without a prototype + use the types of the parameters of the internal built-in to + match those of the arguments to. */ + if (tree bdecl = builtin_decl_explicit (code)) builtin_typelist = TYPE_ARG_TYPES (TREE_TYPE (bdecl)); } @@ -6461,7 +6464,9 @@ maybe_warn_builtin_no_proto_arg (location_t loc, tree fundecl, int parmnum, && TYPE_MODE (parmtype) == TYPE_MODE (argtype)) return; - if (parmcode == argcode + if ((parmcode == argcode + || (parmcode == INTEGER_TYPE + && argcode == ENUMERAL_TYPE)) && TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (promoted)) return; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3652268e82d..0338c9aeedc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-11-23 Martin Sebor + + PR testsuite/88098 + * gcc.dg/Wbuiltin-declaration-mismatch-4.c: Adjust. + * gcc.dg/Wbuiltin-declaration-mismatch-5.c: New test. + * gcc.dg/torture/pr67222.c: Adjust. + 2018-11-23 Richard Biener PR tree-optimization/88149 diff --git a/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-4.c b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-4.c index 3c82e9d7a05..856166c6673 100644 --- a/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-4.c +++ b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-4.c @@ -77,9 +77,9 @@ void test_integer_conversion_memset (void *d) /* Passing a ptrdiff_t where size_t is expected may not be unsafe but because GCC may emits suboptimal code for such calls warning for them helps improve efficiency. */ - memset (d, 0, diffi); /* { dg-warning ".memset. argument 3 promotes to .ptrdiff_t. {aka .long int.} where .long unsigned int. is expected" } */ + memset (d, 0, diffi); /* { dg-warning ".memset. argument 3 promotes to .ptrdiff_t. {aka .\(long \)?int.} where .\(long \)?unsigned int. is expected" } */ - memset (d, 0, 2.0); /* { dg-warning ".memset. argument 3 type is .double. where 'long unsigned int' is expected" } */ + memset (d, 0, 2.0); /* { dg-warning ".memset. argument 3 type is .double. where '\(long \)?unsigned int' is expected" } */ /* Verify that the same call as above but to the built-in doesn't trigger a warning. */ @@ -108,7 +108,8 @@ void test_real_conversion_fabs (void) /* In C, the type of an enumeration constant is int. */ d = fabs (e0); /* { dg-warning ".fabs. argument 1 type is .int. where .double. is expected in a call to built-in function declared without prototype" } */ - d = fabs (e); /* { dg-warning ".fabs. argument 1 type is .enum E. where .double. is expected in a call to built-in function declared without prototype" } */ + d = fabs (e); /* { dg-warning ".fabs. argument 1 type is .enum E. where .double. is expected in a call to built-in function declared without prototype" "ordinary enum" { target { ! short_enums } } } */ + /* { dg-warning ".fabs. argument 1 promotes to .int. where .double. is expected in a call to built-in function declared without prototype" "size 1 enum" { target short_enums } .-1 } */ /* No warning here since float is promoted to double. */ d = fabs (f); diff --git a/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-5.c b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-5.c new file mode 100644 index 00000000000..9cac9277750 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-5.c @@ -0,0 +1,19 @@ +/* PR testsuite/88098 - FAIL: gcc.dg/Wbuiltin-declaration-mismatch-4.c + { dg-do compile } + { dg-options "-Wbuiltin-declaration-mismatch -fshort-enums" } */ + +int abs (); +double fabs (); /* { dg-message "built-in .fabs. declared here" } */ + +enum E { e0 } e; + +int i; +double d; + +void test_short_enums (void) +{ + /* enum e promotes to int. */ + i = abs (e); + + d = fabs (e); /* { dg-warning ".fabs. argument 1 promotes to .int. where .double. is expected in a call to built-in function declared without prototype" } */ +} diff --git a/gcc/testsuite/gcc.dg/torture/pr67222.c b/gcc/testsuite/gcc.dg/torture/pr67222.c index 739f8698526..1beba6dd22c 100644 --- a/gcc/testsuite/gcc.dg/torture/pr67222.c +++ b/gcc/testsuite/gcc.dg/torture/pr67222.c @@ -1,4 +1,4 @@ -/* PR middle-end/67222 */ +/* PR middle-end/67222 - ICE in gimple_call_arg with bogus posix_memalign */ /* { dg-do compile } */ void @@ -17,3 +17,9 @@ foo (void **p) posix_memalign (p, "qui", 3); posix_memalign (p, 1, 2); } + +/* Prune warnings: + { dg-prune-output "call to built-in function declared without prototype" } + { dg-prune-output "too few arguments to built-in function" } + { dg-prune-output "incompatible pointer type" } + { dg-prune-output "\\\[-Wint-conversion]" } */ -- 2.30.2