-
C: underline parameters in mismatching function calls · 8139a48e
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
David Malcolm committed
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
ChangeLog | Loading commit data... | |
Make-lang.in | Loading commit data... | |
c-array-notation.c | Loading commit data... | |
c-aux-info.c | Loading commit data... | |
c-convert.c | Loading commit data... | |
c-decl.c | Loading commit data... | |
c-errors.c | Loading commit data... | |
c-fold.c | Loading commit data... | |
c-lang.c | Loading commit data... | |
c-lang.h | Loading commit data... | |
c-objc-common.c | Loading commit data... | |
c-objc-common.h | Loading commit data... | |
c-parser.c | Loading commit data... | |
c-parser.h | Loading commit data... | |
c-tree.h | Loading commit data... | |
c-typeck.c | Loading commit data... | |
config-lang.in | Loading commit data... | |
gccspec.c | Loading commit data... | |
gimple-parser.c | Loading commit data... | |
gimple-parser.h | Loading commit data... |