Improve location information of -Wcoverage-mismatch.

Message ID 2068f6e1-5f4a-6ae5-e298-1bd3b86666b0@suse.cz
State New
Headers show
Series
  • Improve location information of -Wcoverage-mismatch.
Related show

Commit Message

Martin Liška Sept. 12, 2018, 12:37 p.m.
Hi.

The patch improves locations of the warning in following way:

sample.c: In function ‘main’:
sample.c:16:1: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]
16 | }
   | ^
sample.c:16:1: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]
cc1: some warnings being treated as errors

into:

sample.c: In function ‘main’:
sample.c:10:5: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]
10 | int main()
   |     ^~~~
sample.c:10:5: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Thanks,
Martin

gcc/ChangeLog:

2018-09-12  Martin Liska  <mliska@suse.cz>

	* coverage.c (get_coverage_counts): Use warning_at
	with current_function_decl location. Use %qD in warning
	message.
---
 gcc/coverage.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

Comments

Martin Liška Sept. 21, 2018, 9:04 a.m. | #1
PING^1

On 9/12/18 2:37 PM, Martin Liška wrote:
> Hi.

> 

> The patch improves locations of the warning in following way:

> 

> sample.c: In function ‘main’:

> sample.c:16:1: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]

> 16 | }

>    | ^

> sample.c:16:1: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]

> cc1: some warnings being treated as errors

> 

> into:

> 

> sample.c: In function ‘main’:

> sample.c:10:5: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]

> 10 | int main()

>    |     ^~~~

> sample.c:10:5: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]

> 

> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

> 

> Thanks,

> Martin

> 

> gcc/ChangeLog:

> 

> 2018-09-12  Martin Liska  <mliska@suse.cz>

> 

> 	* coverage.c (get_coverage_counts): Use warning_at

> 	with current_function_decl location. Use %qD in warning

> 	message.

> ---

>  gcc/coverage.c | 18 ++++++++++--------

>  1 file changed, 10 insertions(+), 8 deletions(-)

> 

> 

>
Jeff Law Sept. 21, 2018, 7:46 p.m. | #2
On 9/12/18 6:37 AM, Martin Liška wrote:
> Hi.

> 

> The patch improves locations of the warning in following way:

> 

> sample.c: In function ‘main’:

> sample.c:16:1: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]

> 16 | }

>    | ^

> sample.c:16:1: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]

> cc1: some warnings being treated as errors

> 

> into:

> 

> sample.c: In function ‘main’:

> sample.c:10:5: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]

> 10 | int main()

>    |     ^~~~

> sample.c:10:5: error: source locations for function ‘main’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]

> 

> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

> 

> Thanks,

> Martin

> 

> gcc/ChangeLog:

> 

> 2018-09-12  Martin Liska  <mliska@suse.cz>

> 

> 	* coverage.c (get_coverage_counts): Use warning_at

> 	with current_function_decl location. Use %qD in warning

> 	message.

OK.
jeff

Patch

diff --git a/gcc/coverage.c b/gcc/coverage.c
index bae6f5cafac..71f2c59e5a7 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -374,12 +374,13 @@  get_coverage_counts (unsigned counter, unsigned expected,
     {
       static int warned = 0;
       bool warning_printed = false;
-      tree id = DECL_ASSEMBLER_NAME (current_function_decl);
 
       warning_printed =
-	warning_at (input_location, OPT_Wcoverage_mismatch,
-		    "the control flow of function %qE does not match "
-		    "its profile data (counter %qs)", id, ctr_names[counter]);
+	warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+		    OPT_Wcoverage_mismatch,
+		    "the control flow of function %qD does not match "
+		    "its profile data (counter %qs)", current_function_decl,
+		    ctr_names[counter]);
       if (warning_printed && dump_enabled_p ())
 	{
 	  dump_user_location_t loc
@@ -408,10 +409,11 @@  get_coverage_counts (unsigned counter, unsigned expected,
     }
   else if (entry->lineno_checksum != lineno_checksum)
     {
-      warning (OPT_Wcoverage_mismatch,
-               "source locations for function %qE have changed,"
-	       " the profile data may be out of date",
-	       DECL_ASSEMBLER_NAME (current_function_decl));
+      warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+		  OPT_Wcoverage_mismatch,
+		  "source locations for function %qD have changed,"
+		  " the profile data may be out of date",
+		  current_function_decl);
     }
 
   if (summary)