[patch] Small improvements to coverage info (4/n)

Eric Botcazou ebotcazou@adacore.com
Wed Jul 10 21:18:00 GMT 2019


Hi,

the returns are a little problematic for coverage info because they are 
commonalized in GIMPLE, i.e. turned into gotos to a representative return.
This means that you need to clear the location of the representative return, 
see lower_gimple_return:

	  /* Remove the line number from the representative return statement.
	     It now fills in for many such returns.  Failure to remove this
	     will result in incorrect results for coverage analysis.  */
	  gimple_set_location (tmp_rs.stmt, UNKNOWN_LOCATION);

otherwise the coverage info is blatantly wrong.  But this in turn means that 
such representative returns are vulneable to inheriting random source location 
information in the debug info generated by the compiler.

I have attached an Ada testcase that demonstrates the problem at -O0:

	.loc 1 14 10 discriminator 2
	movl	$0, %r13d
.L12:
	movl	%r13d, %eax
	jmp	.L23

.L12 is what's left at the RTL level of a representative return in GIMPLE and 
it inherits the location directive, which gives wrong coverage info (that's 
not visible with gcov because the instrumentation done by -fprofile-arcs 
papers over the issue, but for example with callgrind).

The proposed fix is attached: it sets the current location to the function's 
end locus when expanding such a representative return to RTL.  That's a bit on 
the kludgy side, but doing something in GIMPLE, e.g. in lower_gimple_return, 
leads to various regressions in terms of quality of diagnostics.

Tested on x86_64-suse-linux, both GCC and GDB, OK for mainline?


2019-07-10  Eric Botcazou  <ebotcazou@adacore.com>

	* cfgexpand.c (expand_gimple_stmt_1) <GIMPLE_RETURN>: If the statement
	doesn't have a location, set the current location to the function's end.

-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-patch
Size: 673 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190710/4fabe978/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ops.adb
Type: text/x-adasrc
Size: 470 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190710/4fabe978/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ops.ads
Type: text/x-adasrc
Size: 517 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190710/4fabe978/attachment-0002.bin>


More information about the Gcc-patches mailing list