diff options
author | David Malcolm <dmalcolm@redhat.com> | 2018-08-16 22:33:00 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-08-16 22:33:00 +0000 |
commit | 5c6a2bf2720fd6412a2d63a3a82da5af0c18f824 (patch) | |
tree | 8288ba2c095a7579fae973b7e47977f8190e81d2 | |
parent | 5218dafdc219eb49a0b8d776b99fd7a7afb5be0b (diff) | |
download | gcc-5c6a2bf2720fd6412a2d63a3a82da5af0c18f824.zip gcc-5c6a2bf2720fd6412a2d63a3a82da5af0c18f824.tar.gz gcc-5c6a2bf2720fd6412a2d63a3a82da5af0c18f824.tar.bz2 |
diagnostics: fix bad interaction between line spans and line numbers
Without this patch, the "line span" markers and the line numbering
interacted badly, leading to stray copies of the line-span markers
appearing as prefixes on the first source line in a span:
missing-header-fixit-3.c: In function 'test':
missing-header-fixit-3.c:9:3: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
9 | printf ("%i of %i\n", i, j);
| ^~~~~~
missing-header-fixit-3.c:9:3: warning: incompatible implicit declaration of built-in function 'printf'
missing-header-fixit-3.c:9:3: note: include '<stdio.h>' or provide a declaration of 'printf'
missing-header-fixit-3.c:1:1:
|+#include <stdio.h>
missing-header-fixit-3.c:1:1:1 | /* Example of a fix-it hint that adds a #include directive,
missing-header-fixit-3.c:9:3:
missing-header-fixit-3.c:9:3:9 | printf ("%i of %i\n", i, j);
| ^~~~~~
With this patch, we now correctly print:
missing-header-fixit-3.c: In function 'test':
missing-header-fixit-3.c:9:3: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
9 | printf ("%i of %i\n", i, j);
| ^~~~~~
missing-header-fixit-3.c:9:3: warning: incompatible implicit declaration of built-in function 'printf'
missing-header-fixit-3.c:9:3: note: include '<stdio.h>' or provide a declaration of 'printf'
missing-header-fixit-3.c:1:1:
+ |+#include <stdio.h>
1 | /* Example of a fix-it hint that adds a #include directive,
missing-header-fixit-3.c:9:3:
9 | printf ("%i of %i\n", i, j);
| ^~~~~~
gcc/ChangeLog:
* diagnostic.c (default_diagnostic_start_span_fn): Call pp_string
to emit the span, rather than setting it as the prefix.
gcc/testsuite/ChangeLog:
* gcc.dg/missing-header-fixit-3.c: New test.
From-SVN: r263606
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/diagnostic.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/missing-header-fixit-3.c | 27 |
4 files changed, 39 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c776f6d..146e4e3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2018-08-16 David Malcolm <dmalcolm@redhat.com> + * diagnostic.c (default_diagnostic_start_span_fn): Call pp_string + to emit the span, rather than setting it as the prefix. + +2018-08-16 David Malcolm <dmalcolm@redhat.com> + * diagnostic-show-locus.c (layout::start_annotation_line): Add "margin_char" parameter, defaulting to space. Use it in place of pp_space for the initial part of the margin. diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 59477ce..7e8bcf5 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -629,9 +629,9 @@ void default_diagnostic_start_span_fn (diagnostic_context *context, expanded_location exploc) { - pp_set_prefix (context->printer, - diagnostic_get_location_text (context, exploc)); - pp_string (context->printer, ""); + char *text = diagnostic_get_location_text (context, exploc); + pp_string (context->printer, text); + free (text); pp_newline (context->printer); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 978bd8f..ad2de84 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2018-08-16 David Malcolm <dmalcolm@redhat.com> + * gcc.dg/missing-header-fixit-3.c: New test. + +2018-08-16 David Malcolm <dmalcolm@redhat.com> + * gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c (test_fixit_insert_newline): Update expected output to show '+' characters in margin of line-insertion fix-it hint. diff --git a/gcc/testsuite/gcc.dg/missing-header-fixit-3.c b/gcc/testsuite/gcc.dg/missing-header-fixit-3.c new file mode 100644 index 0000000..8f2fb5b --- /dev/null +++ b/gcc/testsuite/gcc.dg/missing-header-fixit-3.c @@ -0,0 +1,27 @@ +/* Example of a fix-it hint that adds a #include directive, + adding them to the top of the file, given that there is no + pre-existing #include. */ + +/* { dg-options "-fdiagnostics-show-caret -fdiagnostics-show-line-numbers" } */ + +void test (int i, int j) +{ + printf ("%i of %i\n", i, j); /* { dg-warning "implicit declaration" } */ + /* { dg-message "include '<stdio.h>' or provide a declaration of 'printf'" "" { target *-*-* } .-1 } */ +#if 0 +/* { dg-begin-multiline-output "" } +9 | printf ("%i of %i\n", i, j); + | ^~~~~~ + { dg-end-multiline-output "" } */ +/* { dg-regexp ".*missing-header-fixit-3.c:1:1:" } */ +/* { dg-begin-multiline-output "" } ++ |+#include <stdio.h> +1 | /* Example of a fix-it hint that adds a #include directive, + { dg-end-multiline-output "" } */ +/* { dg-regexp ".*missing-header-fixit-3.c:9:3:" } */ +/* { dg-begin-multiline-output "" } +9 | printf ("%i of %i\n", i, j); + | ^~~~~~ + { dg-end-multiline-output "" } */ +#endif +} |