From 21cf0e000ea0b50c022377461a0f41bda1846211 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 12 May 2017 14:43:54 -0400 Subject: [PATCH 09/14] FIXME: WIP on highlights for C bad return types --- gcc/c/c-typeck.c | 21 ++++++++++++++++++--- gcc/testsuite/gcc.dg/bad-return-type.c | 9 +++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/bad-return-type.c diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 129aebb..dd8983c 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -6153,6 +6153,18 @@ inform_for_arg (tree fundecl, location_t ploc, int parmnum, expected_type, actual_type); } +/* FIXME. */ + +static void +inform_about_return_type () +{ + ast_node *asnode = ast_get_node_for_tree (current_function_decl); + if (!asnode) + return; + debug (asnode); + inform (UNKNOWN_LOCATION, "would highlight return type here"); +} + /* Convert value RHS to type TYPE as preparation for an assignment to an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the original type of RHS; this differs from TREE_TYPE (RHS) for enum @@ -6233,7 +6245,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, pedwarn_init (LOCATION, OPT, IN); \ break; \ case ic_return: \ - pedwarn (LOCATION, OPT, RE); \ + if (pedwarn (LOCATION, OPT, RE)) \ + inform_about_return_type (); \ break; \ default: \ gcc_unreachable (); \ @@ -6259,7 +6272,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, pedwarn (LOCATION, OPT, IN, QUALS); \ break; \ case ic_return: \ - pedwarn (LOCATION, OPT, RE, QUALS); \ + if (pedwarn (LOCATION, OPT, RE, QUALS)) \ + inform_about_return_type (); \ break; \ default: \ gcc_unreachable (); \ @@ -6285,7 +6299,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, warning_at (LOCATION, OPT, IN, QUALS); \ break; \ case ic_return: \ - warning_at (LOCATION, OPT, RE, QUALS); \ + if (warning_at (LOCATION, OPT, RE, QUALS)) \ + inform_about_return_type (); \ break; \ default: \ gcc_unreachable (); \ diff --git a/gcc/testsuite/gcc.dg/bad-return-type.c b/gcc/testsuite/gcc.dg/bad-return-type.c new file mode 100644 index 0000000..bb27a94 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bad-return-type.c @@ -0,0 +1,9 @@ +int test (void) +{ + return "hello world"; +} + +void test (void) +{ + return 42; +} -- 1.8.5.3