From 7345c89ecb1a31ce96c6789bffc7183268a040b3 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 6 Oct 2020 16:58:00 -0400 Subject: [PATCH] Add -fdiagnostics-path-format=separate-events to -fdiagnostics-plain-output The path-printing default of -fdiagnostics-path-format=inline-events interacted poorly with -fdiagnostics-plain-output, so it makes most sense to add -fdiagnostics-path-format=separate-events to -fdiagnostics-plain-output. Seen when adding an experimental analyzer plugin to gcc.dg/plugin.exp. gcc/ChangeLog: * doc/invoke.texi (-fdiagnostics-plain-output): Add -fdiagnostics-path-format=separate-events to list of options injected by -fdiagnostics-plain-output. * opts-common.c (decode_cmdline_options_to_array): Likewise. gcc/testsuite/ChangeLog: * g++.dg/analyzer/analyzer.exp (DEFAULT_CXXFLAGS): Remove -fdiagnostics-path-format=separate-events. * gcc.dg/analyzer/analyzer.exp (DEFAULT_CFLAGS): Likewise. * gcc.dg/plugin/diagnostic-path-format-default.c: Rename to... * gcc.dg/plugin/diagnostic-path-format-plain.c: ...this. Remove dg-options directive. Copy remainder of test from diagnostic-path-format-separate-events.c. * gcc.dg/plugin/diagnostic-test-paths-2.c: Add -fdiagnostics-path-format=inline-events to options. Fix expected output for location of conditional within "for" loop. * gcc.dg/plugin/plugin.exp (plugin_test_list): Update for renaming. * gfortran.dg/analyzer/analyzer.exp (DEFAULT_FFLAGS): Remove -fdiagnostics-path-format=separate-events. --- gcc/doc/invoke.texi | 3 +- gcc/opts-common.c | 1 + gcc/testsuite/g++.dg/analyzer/analyzer.exp | 2 +- gcc/testsuite/gcc.dg/analyzer/analyzer.exp | 2 +- .../gcc.dg/plugin/diagnostic-path-format-default.c | 142 --------------------- .../gcc.dg/plugin/diagnostic-path-format-plain.c | 42 ++++++ .../gcc.dg/plugin/diagnostic-test-paths-2.c | 8 +- gcc/testsuite/gcc.dg/plugin/plugin.exp | 2 +- gcc/testsuite/gfortran.dg/analyzer/analyzer.exp | 2 +- 9 files changed, 53 insertions(+), 151 deletions(-) delete mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic-path-format-default.c create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic-path-format-plain.c diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 7c81d7f..c177496 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -4345,7 +4345,8 @@ options: @gccoptlist{-fno-diagnostics-show-caret @gol -fno-diagnostics-show-line-numbers @gol -fdiagnostics-color=never @gol --fdiagnostics-urls=never} +-fdiagnostics-urls=never @gol +-fdiagnostics-path-format=separate-events} In the future, if GCC changes the default appearance of its diagnostics, the corresponding option to disable the new behavior will be added to this list. diff --git a/gcc/opts-common.c b/gcc/opts-common.c index 237e4ce..8ec8c1e 100644 --- a/gcc/opts-common.c +++ b/gcc/opts-common.c @@ -1000,6 +1000,7 @@ decode_cmdline_options_to_array (unsigned int argc, const char **argv, "-fno-diagnostics-show-line-numbers", "-fdiagnostics-color=never", "-fdiagnostics-urls=never", + "-fdiagnostics-path-format=separate-events", }; const int num_expanded = ARRAY_SIZE (expanded_args); opt_array_len += num_expanded - 1; diff --git a/gcc/testsuite/g++.dg/analyzer/analyzer.exp b/gcc/testsuite/g++.dg/analyzer/analyzer.exp index 60262f6..78edff2 100644 --- a/gcc/testsuite/g++.dg/analyzer/analyzer.exp +++ b/gcc/testsuite/g++.dg/analyzer/analyzer.exp @@ -29,7 +29,7 @@ if [info exists DEFAULT_CXXFLAGS] then { } # If a testcase doesn't have special options, use these. -set DEFAULT_CXXFLAGS " -fanalyzer -fdiagnostics-path-format=separate-events -Wanalyzer-too-complex -fanalyzer-call-summaries" +set DEFAULT_CXXFLAGS " -fanalyzer -Wanalyzer-too-complex -fanalyzer-call-summaries" # Initialize `dg'. dg-init diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp index ac9c495..d72fef3 100644 --- a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp +++ b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp @@ -30,7 +30,7 @@ if [info exists DEFAULT_CFLAGS] then { } # If a testcase doesn't have special options, use these. -set DEFAULT_CFLAGS "-fanalyzer -fdiagnostics-path-format=separate-events -Wanalyzer-too-complex -fanalyzer-call-summaries" +set DEFAULT_CFLAGS "-fanalyzer -Wanalyzer-too-complex -fanalyzer-call-summaries" # Initialize `dg'. dg-init diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-path-format-default.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-path-format-default.c deleted file mode 100644 index 5712dbd..0000000 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-path-format-default.c +++ /dev/null @@ -1,142 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdiagnostics-show-caret" } */ - -#include - -void *wrapped_malloc (size_t size) -{ - return malloc (size); -} - -void wrapped_free (void *ptr) -{ - free (ptr); /* { dg-warning "double-free of 'ptr' \\\[CWE-415\\]" } */ - /* { dg-begin-multiline-output "" } - free (ptr); - ^~~~~~~~~~ - 'test': events 1-2 - | - | { - | ^ - | | - | (1) entering 'test' - | boxed_int *obj = make_boxed_int (i); - | ~~~~~~~~~~~~~~~~~~ - | | - | (2) calling 'make_boxed_int' - | - +--> 'make_boxed_int': events 3-4 - | - | { - | ^ - | | - | (3) entering 'make_boxed_int' - | boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - | | - | (4) calling 'wrapped_malloc' - | - +--> 'wrapped_malloc': events 5-6 - | - | { - | ^ - | | - | (5) entering 'wrapped_malloc' - | return malloc (size); - | ~~~~~~~~~~~~~ - | | - | (6) calling 'malloc' - | - <-------------+ - | - 'test': event 7 - | - | free_boxed_int (obj); - | ^~~~~~~~~~~~~~~~~~~~ - | | - | (7) calling 'free_boxed_int' - | - +--> 'free_boxed_int': events 8-9 - | - | { - | ^ - | | - | (8) entering 'free_boxed_int' - | wrapped_free (bi); - | ~~~~~~~~~~~~~~~~~ - | | - | (9) calling 'wrapped_free' - | - +--> 'wrapped_free': events 10-11 - | - | { - | ^ - | | - | (10) entering 'wrapped_free' - | free (ptr); - | ~~~~~~~~~~ - | | - | (11) calling 'free' - | - <-------------+ - | - 'test': event 12 - | - | free_boxed_int (obj); - | ^~~~~~~~~~~~~~~~~~~~ - | | - | (12) calling 'free_boxed_int' - | - +--> 'free_boxed_int': events 13-14 - | - | { - | ^ - | | - | (13) entering 'free_boxed_int' - | wrapped_free (bi); - | ~~~~~~~~~~~~~~~~~ - | | - | (14) calling 'wrapped_free' - | - +--> 'wrapped_free': events 15-16 - | - | { - | ^ - | | - | (15) entering 'wrapped_free' - | free (ptr); - | ~~~~~~~~~~ - | | - | (16) calling 'free' - | - { dg-end-multiline-output "" } */ -} - -typedef struct boxed_int -{ - int i; -} boxed_int; - -boxed_int * -make_boxed_int (int i) -{ - boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int)); - result->i = i; - return result; -} - -void -free_boxed_int (boxed_int *bi) -{ - wrapped_free (bi); -} - -void test (int i) -{ - boxed_int *obj = make_boxed_int (i); - - free_boxed_int (obj); - - free_boxed_int (obj); -} - diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-path-format-plain.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-path-format-plain.c new file mode 100644 index 0000000..75acd25 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-path-format-plain.c @@ -0,0 +1,42 @@ +/* { dg-do compile } */ + +#include + +void *wrapped_malloc (size_t size) +{ + return malloc (size); +} + +void wrapped_free (void *ptr) +{ + free (ptr); /* { dg-warning "double-free of 'ptr' \\\[CWE-415\\]" } */ +} + +typedef struct boxed_int +{ + int i; +} boxed_int; + +boxed_int * +make_boxed_int (int i) +{ + boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int)); + result->i = i; + return result; +} + +void +free_boxed_int (boxed_int *bi) +{ + wrapped_free (bi); +} + +void test (int i) +{ /* { dg-message "\\(1\\) entering 'test'" } */ + boxed_int *obj = make_boxed_int (i); /* { dg-message "\\(2\\) calling 'make_boxed_int'" } */ + /* etc */ + + free_boxed_int (obj); + + free_boxed_int (obj); +} diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.c index 946a234..b2b269a 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fdiagnostics-show-caret -fdiagnostics-show-line-numbers" } */ +/* { dg-options "-fdiagnostics-show-caret -fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events" } */ #include #include @@ -43,9 +43,9 @@ make_a_list_of_random_ints_badly(PyObject *self, | | (1) when 'PyList_New' fails, returning NULL | 26 | | 27 | for (i = 0; i < count; i++) { - | | ~~~ - | | | - | | (2) when 'i < count' + | | ~~~~~~~~~ + | | | + | | (2) when 'i < count' | 28 | item = PyLong_FromLong(random()); | 29 | PyList_Append(list, item); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/gcc/testsuite/gcc.dg/plugin/plugin.exp b/gcc/testsuite/gcc.dg/plugin/plugin.exp index c02b008..5dd102a 100644 --- a/gcc/testsuite/gcc.dg/plugin/plugin.exp +++ b/gcc/testsuite/gcc.dg/plugin/plugin.exp @@ -100,7 +100,7 @@ set plugin_test_list [list \ diagnostic-test-paths-2.c \ diagnostic-test-paths-3.c \ diagnostic-test-paths-4.c \ - diagnostic-path-format-default.c \ + diagnostic-path-format-plain.c \ diagnostic-path-format-none.c \ diagnostic-path-format-separate-events.c \ diagnostic-path-format-inline-events-1.c \ diff --git a/gcc/testsuite/gfortran.dg/analyzer/analyzer.exp b/gcc/testsuite/gfortran.dg/analyzer/analyzer.exp index 00edfa5..462395c 100644 --- a/gcc/testsuite/gfortran.dg/analyzer/analyzer.exp +++ b/gcc/testsuite/gfortran.dg/analyzer/analyzer.exp @@ -33,7 +33,7 @@ if [info exists DEFAULT_FFLAGS] then { } # If a testcase doesn't have special options, use these. -set DEFAULT_FFLAGS "-fanalyzer -fdiagnostics-path-format=separate-events -Wanalyzer-too-complex -fanalyzer-call-summaries" +set DEFAULT_FFLAGS "-fanalyzer -Wanalyzer-too-complex -fanalyzer-call-summaries" # Initialize `dg'. dg-init -- 2.7.4