Bug 69951 - wrong code at -O1 and above on x86_64-linux-gnu
Summary: wrong code at -O1 and above on x86_64-linux-gnu
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2016-02-25 01:25 UTC by Qirun Zhang
Modified: 2016-03-14 09:46 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.6, 6.0
Known to fail: 4.0.0
Last reconfirmed: 2016-02-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Qirun Zhang 2016-02-25 01:25:14 UTC
The current gcc trunk mis-compiles the following code on x86_64-linux-gnu at -O1 and above in both 32-bit and 64-bit modes.

It affects as early as gcc-4.4.3 (I don't have earlier gcc on my machine).


$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/absozero/trunk/root-gcc/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/absozero/trunk/root-gcc --enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 6.0.0 20160224 (experimental) [trunk revision 233678] (GCC) 




$ gcc-trunk abc.c
$ ./a.out 
$ gcc-trunk -O1 abc.c
$ ./a.out 
Aborted (core dumped)



$ cat abc.c
int a = 1, c = 1;
extern int b __attribute__((alias("a")));
extern int d __attribute__((alias("c")));
int main(int argc) {
  int *p, *q;
  if (argc)
    p = &c, q = &d;
  else
    p = &b, q = &d;
  *p = 1;
  *q = 2;
  if (*p == 1)
    __builtin_abort();
  return 0;
}
Comment 1 Marek Polacek 2016-02-25 09:13:03 UTC
Hm, this really seems like a wrong code.  Started a looooong time ago, before r104500.
Comment 2 Richard Biener 2016-02-25 10:22:43 UTC
We have a duplicate for this - basically (most) of alias analysis doesn't handle aliases (hah).

In this case it's points-to I think and then FRE facing

  # p_1 = PHI <&c(2), &b(3)>
  *p_1 = 1;
  d = 2;
  _11 = *p_1;

and optimizing the load to 1.  Honza has fixed some cases for GCC 6 but appearantly not points-to.

See tree-ssa-structalias.c, lookup_vi_for_tree should probably canonicalize
to the ultimate alias.  pt_solution_set_var and pt_solution_includes_1
need to be adjusted accordingly as well.

-fno-tree-pta fixes this bug (on trunk).

Honza - I'd need sth like equal_address_to (as used in compare_base_decls)
but "one sided" so that if two decls have the same address they get
canonicalized to the same decl so I can continue to use DECL_UID equality
for the alias check.
Comment 3 Richard Biener 2016-02-25 11:28:27 UTC
3.x worked.
Comment 4 Richard Biener 2016-02-26 08:35:44 UTC
Fixed for GCC 6.
Comment 5 Chengnian Sun 2016-03-14 01:18:42 UTC
(In reply to Richard Biener from comment #4)
> Fixed for GCC 6.

Hi Richard, 

Is there any way to get the id of the revision that fixed this issue?

Thanks.
Comment 6 Richard Biener 2016-03-14 09:34:59 UTC
Seems I typoed the PR reference in the commit:

Author: rguenth
Date: Fri Feb 26 08:34:58 2016
New Revision: 233734

URL: https://gcc.gnu.org/viewcvs?rev=233734&root=gcc&view=rev
Log:
2016-02-26  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/69551
	* tree-ssa-structalias.c (get_constraint_for_ssa_var): When
	looking through aliases adjust DECL_PT_UID to refer to the
	ultimate alias target.

	* gcc.dg/torture/pr69951.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr69951.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-structalias.c
Comment 7 Chengnian Sun 2016-03-14 09:46:41 UTC
(In reply to Richard Biener from comment #6)
> Seems I typoed the PR reference in the commit:
> 
> Author: rguenth
> Date: Fri Feb 26 08:34:58 2016
> New Revision: 233734
> 
> URL: https://gcc.gnu.org/viewcvs?rev=233734&root=gcc&view=rev
> Log:
> 2016-02-26  Richard Biener  <rguenther@suse.de>
> 
> 	PR tree-optimization/69551
> 	* tree-ssa-structalias.c (get_constraint_for_ssa_var): When
> 	looking through aliases adjust DECL_PT_UID to refer to the
> 	ultimate alias target.
> 
> 	* gcc.dg/torture/pr69951.c: New testcase.
> 
> Added:
>     trunk/gcc/testsuite/gcc.dg/torture/pr69951.c
> Modified:
>     trunk/gcc/ChangeLog
>     trunk/gcc/testsuite/ChangeLog
>     trunk/gcc/tree-ssa-structalias.c

Thank you so much, Richard.