[patch] Fix ICEs with functions returning variable-sized array

Eric Botcazou ebotcazou@adacore.com
Tue Jan 10 19:30:00 GMT 2012


This is a couple of regressions present on the mainline.  For the first
testcase at O2 -gnatn:

+===========================GNAT BUG DETECTED==============================+
| 4.7.0 20120102 (experimental) [trunk revision 182780] (i586-suse-linux) GCC 
error:|
| in assign_stack_temp_for_type, at function.c:796                         |
| Error detected around p1.adb:3:4   

For the second testcase:

+===========================GNAT BUG DETECTED==============================+
| 4.7.0 20120102 (experimental) [trunk revision 182780] (i586-suse-linux) GCC 
error:|
| in declare_return_variable, at tree-inline.c:2904                        |
| Error detected around p2.adb:3:4                

Both are caused by the fnsplit IPA pass being run on a function returning a 
variable-sized array.  In both cases, the part that isn't inlined is made 
up of a single "raise" statement, i.e. a no-return call.  So fnsplit rewrites 
the call statement into just:

  f.part (arguments);

In the first case, the compilation aborts when the RTL expander attempts to 
create a temporary for the return value (which would have variable size) 
while, in the second case, it aborts on the assertion:

  gcc_assert (TREE_CODE (TYPE_SIZE_UNIT (callee_type)) == INTEGER_CST);

when the inliner attemps to inline the part that wasn't inlined(!).

The proposed fix is to turn the part that isn't inlined into a function that
returns void.  This involves straightforward adjustments to the two versioning 
machineries (cgraph and tree).

Tested on i586-suse-linux, OK for the mainline?


2012-01-10  Eric Botcazou  <ebotcazou@adacore.com>

	* tree.h (build_function_decl_skip_args): Add boolean parameter.
	(build_function_type_skip_args): Delete.
	* tree.c (build_function_type_skip_args): Make static and add
	SKIP_RETURN parameter.  Fix thinko in the handling of variants.
	(build_function_decl_skip_args): Add SKIP_RETURN parameter and
	pass it to build_function_type_skip_args.
	* cgraph.h (cgraph_function_versioning): Add boolean parameter.
	(tree_function_versioning): Likewise.
	* cgraph.c (cgraph_create_virtual_clone): Adjust call to
	build_function_decl_skip_args.
	* cgraphunit.c (cgraph_function_versioning): Add SKIP_RETURN parameter
	and pass it to build_function_decl_skip_args/tree_function_versioning.
	(cgraph_materialize_clone): Adjust call to tree_function_versioning.
	* ipa-inline-transform.c (save_inline_function_body): Likewise.
	* trans-mem.c (ipa_tm_create_version): Likewise.
	* tree-sra.c (modify_function): Likewise for cgraph_function_versioning.
	* tree-inline.c (declare_return_variable): Remove always-true test.
	(tree_function_versioning): Add SKIP_RETURN parameter.  If the function
	returns non-void and SKIP_RETURN, create a void-typed RESULT_DECL.
	* ipa-split.c (split_function): Skip the return value for the split
	part if it doesn't return.

		
2012-01-10  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt23.ad[sb]: New test.
	* gnat.dg/opt23_pkg.ad[sb]: New helper.
	* gnat.dg/opt24.ad[sb]: New test.
	

-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p1.diff
Type: text/x-diff
Size: 11423 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20120110/5a0115eb/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt23_pkg.ads
Type: text/x-adasrc
Size: 654 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20120110/5a0115eb/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt23.ads
Type: text/x-adasrc
Size: 97 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20120110/5a0115eb/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt23_pkg.adb
Type: text/x-adasrc
Size: 156 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20120110/5a0115eb/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt23.adb
Type: text/x-adasrc
Size: 355 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20120110/5a0115eb/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt24.ads
Type: text/x-adasrc
Size: 97 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20120110/5a0115eb/attachment-0005.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt24.adb
Type: text/x-adasrc
Size: 307 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20120110/5a0115eb/attachment-0006.bin>


More information about the Gcc-patches mailing list