David Malcolm 8139a48e67 C: underline parameters in mismatching function calls
In r253096
  ("C++: underline parameters in mismatching function calls"
  aka 5d78d423a5f7a1d135c7bb678e82007678d1313c
    https://gcc.gnu.org/ml/gcc-patches/2017-09/msg01546.html )
I updated the C++ FE's handling of mismatched types in function calls
so that it underlines the pertinent param of the callee, rather than
just the function name.

The following patch does the same for the C frontend.

Given e.g. this type mismatch:

  extern int callee (int one, const char *two, float three);

  int caller (int first, int second, float third)
  {
    return callee (first, second, third);
  }

the C FE currently emits (trunk):

  test.c: In function 'caller':
  test.c:5:25: warning: passing argument 2 of 'callee' makes pointer from
  integer without a cast [-Wint-conversion]
     return callee (first, second, third);
                           ^~~~~~
  test.c:1:12: note: expected 'const char *' but argument is of type 'int'
   extern int callee (int one, const char *two, float three);
              ^~~~~~

whereas with this patch the note underlines the pertinent param of
the callee:

  test.c: In function 'caller':
  test.c:5:25: warning: passing argument 2 of 'callee' makes pointer from
  integer without a cast [-Wint-conversion]
     return callee (first, second, third);
                           ^~~~~~
  test.c:1:41: note: expected 'const char *' but argument is of type 'int'
   extern int callee (int one, const char *two, float three);
                               ~~~~~~~~~~~~^~~

making the problem more obvious to the user.

As with the C++ patch, the patch:

(a) updates the locations of the params to cover the range of all
of their tokens, putting the caret on the first character of the
param name (if present), otherwise at the start of the first token
(doing so requires adding a last_token_location to the c_parser, so
we can determine the location of the last consumed token).

(b) updates the "note" to use the param location, rather than the
fndecl location

gcc/c/ChangeLog:
	* c-decl.c (push_parm_decl): Store c_parm's location into the
	PARAM_DECL.
	(build_c_parm): Add "loc" param and store it within the c_parm.
	* c-parser.c (struct c_parser): Add "last_token_location" field.
	(c_parser_consume_token): Store location of the token into the
	new field.
	(c_parser_declaration_or_fndef): Store params into DECL_ARGUMENTS
	when handling a FUNCTION_DECL, if it doesn't already have them.
	(c_parser_parameter_declaration): Generate a location for the
	parameter, and pass it to the call to build_c_parm.
	* c-tree.h (struct c_parm): Add field "loc".
	(build_c_parm): Add location_t param.
	* c-typeck.c (get_fndecl_argument_location): New function.
	(inform_for_arg): New function.
	(convert_for_assignment): Use inform_for_arg when dealing with
	ic_argpass.

gcc/testsuite/ChangeLog:
	* gcc.dg/diagnostic-range-bad-called-object.c: Update expected
	underlining for param.
	* gcc.dg/param-type-mismatch.c: Update expected results to reflect
	highlighting of parameters; add test coverage for trivial
	parameter decls, and for callback parameters.
	* gcc.dg/pr68533.c: Update location of two errors to reflect
	location of params.

From-SVN: r253411
2017-10-04 14:10:59 +00:00
2017-09-19 07:51:49 +00:00
2017-10-03 02:27:33 +00:00
2017-07-21 00:27:51 +00:00
2017-09-15 23:16:37 +02:00

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.
Description
No description provided
Readme 3.1 GiB
Languages
C 48%
Ada 18.3%
C++ 14.1%
Go 7%
GCC Machine Description 4.6%
Other 7.7%