[patch] Fix type merging deficiency during WPA

Eric Botcazou ebotcazou@adacore.com
Tue Jul 5 10:57:00 GMT 2016


Hi,

the deficiency comes from a chicken-and-egg problem during WPA: DECL nodes 
merging depends on type merging, but type merging also depends on DECL nodes 
merging for dynamic types declared at file scope, which easily occurs in Ada.

For the attached trivial testcase, the compiler issues:

/home/eric/svn/gcc/gcc/testsuite/gnat.dg/lto18_pkg1.ads:12:13: warning: type 
of 'lto18_pkg1__proc' does not match original declaration [-Wlto-type-
mismatch]
/home/eric/svn/gcc/gcc/testsuite/gnat.dg/lto18_pkg1.adb:3:3: note: 
'lto18_pkg1__proc' was previously declared here
/home/eric/svn/gcc/gcc/testsuite/gnat.dg/lto18_pkg1.adb:3:3: note: code may be 
misoptimized unless -fno-strict-aliasing is used

The proposed fix is to add a special processing in operand_equal_p/add_expr 
for DECL nodes during WPA.  It contains a tweak for lto_fixup_prevailing_decls 
for the sake of completeness, but it is not necessary for fixing the problem.

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


2016-07-05  Eric Botcazou  <ebotcazou@adacore.com>

	* cgraph.h (symbol_table::decl_assembler_name_hash): Make public.
	* fold-const.c (operand_equal_p) <tcc_declaration>: Add special
	processing during WPA.
	* tree.c (add_expr) <tcc_declaration>: Likewise.
lto/
	* lto.c (walk_simple_constant_arithmetic): New function.
	(LTO_SET_PREVAIL): Use it to fix up DECL nodes in simple expressions.


2016-07-05  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/lto18.adb: New test.
	* gnat.dg/lto18_pkg1.ad[sb]: New helper.
	* gnat.dg/lto18_pkg2.ad[sb]: Likewise.

-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-patch
Size: 4665 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160705/23bcde7e/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lto18.adb
Type: text/x-adasrc
Size: 208 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160705/23bcde7e/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lto18_pkg1.adb
Type: text/x-adasrc
Size: 92 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160705/23bcde7e/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lto18_pkg1.ads
Type: text/x-adasrc
Size: 206 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160705/23bcde7e/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lto18_pkg2.ads
Type: text/x-adasrc
Size: 70 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160705/23bcde7e/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lto18_pkg2.adb
Type: text/x-adasrc
Size: 98 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160705/23bcde7e/attachment-0005.bin>


More information about the Gcc-patches mailing list