Fix miscompilation of gnatmake on x86-64

Eric Botcazou ebotcazou@adacore.com
Sun Dec 7 13:23:00 GMT 2008


Restoring the bitfield comparison optimization has triggered a miscompilation 
of gnatmake on x86-64.  The compiler now issues a bogus warning at -O2 on the 
attached reduced testcase:

p.adb: In function 'P.Get_Sources_From_File':
p.adb:14: warning: comparison always false due to limited range of data type

It comes from VRP on:

  UNSIGNED_64 SR.5;
  <unnamed-signed:64> D.2186;

[...]

  D.2186_1 = SR.5_39;
  if (D.2186_1 == -9223372036554775808)
    goto <bb 3>;
  else
    goto <bb 7>;

The mismatched assignment is generated by the use_all && !is_output bitfield 
case of tree-sra.c:scalarize_use:

	  tree type = TREE_TYPE (bfexpr);
	  tree var, vpos;

	  if (!TYPE_UNSIGNED (type))
	    type = unsigned_type_for (type);

	  var = make_rename_temp (type, "SR");

	  gimple_assign_set_rhs1 (stmt, var);

It turns out that the use_all && is_output bitfield case just above deals with 
the same problem just fine:

	  tree type = TREE_TYPE (bfexpr);
	  tree var = make_rename_temp (type, "SR"), tmp, vpos;
          gimple st;

	  gimple_assign_set_lhs (stmt, var);
	  update = true;

	  if (!TYPE_UNSIGNED (type))
	    {
	      type = unsigned_type_for (type);
	      tmp = make_rename_temp (type, "SR");
	      st = gimple_build_assign (tmp, fold_convert (type, var));
	      gimple_seq_add_stmt (&seq_after, st);
	      var = tmp;
	    }

so the attached patch just adapts the latter correct logic to the former case.

Tested on x86_64-suse-linux, applied on the mainline as obvious.

The issue is latent on the 4.3 branch, should I backport the fix to it?


2008-12-07  Eric Botcazou  <ebotcazou@adacore.com>

	* tree-sra.c (scalarize_use): Create another temporary with the proper
	type for signed types in the use_all && !is_output bitfield case.


2008-12-07  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/aggr10.adb: New test.
	* gnat.dg/aggr10_pkg.ads: New helper.


-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sra_missing_cast.diff
Type: text/x-diff
Size: 1189 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20081207/4b7a5b16/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: q.ads
Type: text/x-adasrc
Size: 442 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20081207/4b7a5b16/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.adb
Type: text/x-adasrc
Size: 481 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20081207/4b7a5b16/attachment-0002.bin>


More information about the Gcc-patches mailing list