diff options
author | David Malcolm <dmalcolm@redhat.com> | 2017-08-21 17:03:15 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2017-08-21 17:03:15 +0000 |
commit | d5d63263255f0b858bd279a44ca58eb522b83564 (patch) | |
tree | dffd9f4456e124fd12725644bce859641cf32996 /gcc/c/c-tree.h | |
parent | 1f6e64e2b4b0ae46743342f6bb5e1b3aa5fabbb3 (diff) |
C: use full locations within c_parser_expr_list's vec<location_t>
The previous patch uncovered a bug in how c_parser_expr_list builds the
vec<location_t>: it was only using the location of the first token
within each assignment-expression in the expr-list.
This shows up in e.g. this -Wformat warning, where only part of the
2nd param is underlined:
printf("hello %i", (long)0);
~^ ~
%li
This patch fixes c_parser_expr_list to use the full range of
each assignment-expression in the list for the vec<location_t>, so
that for the above we print:
printf("hello %i", (long)0);
~^ ~~~~~~~
%li
gcc/c/ChangeLog:
* c-parser.c (c_parser_expr_list): Use c_expr::get_location ()
rather than peeking the location of the first token.
* c-tree.h (c_expr::get_location): New method.
gcc/testsuite/ChangeLog:
* gcc.dg/format/diagnostic-ranges.c (test_mismatching_types):
Update expected result to show all of "(long)0" being underlined.
* gcc.dg/plugin/diagnostic-test-string-literals-1.c
(test_multitoken_macro): Update expected underlining.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@251239 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c/c-tree.h')
-rw-r--r-- | gcc/c/c-tree.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 92bcc70653e..5182cc539ec 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -147,6 +147,14 @@ struct c_expr location_t get_start () const { return src_range.m_start; } location_t get_finish () const { return src_range.m_finish; } + location_t get_location () const + { + if (CAN_HAVE_LOCATION_P (value)) + return EXPR_LOCATION (value); + else + return make_location (get_start (), get_start (), get_finish ()); + } + /* Set the value to error_mark_node whilst ensuring that src_range is initialized. */ void set_error () |