Bug 27768 - [4.1 regression] wrong-code with vectors
Summary: [4.1 regression] wrong-code with vectors
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P1 critical
Target Milestone: 4.1.2
Assignee: Jason Merrill
Keywords: alias, monitored, wrong-code
Depends on: 19817
  Show dependency treegraph
Reported: 2006-05-25 08:29 UTC by Volker Reichelt
Modified: 2006-06-30 15:25 UTC (History)
6 users (show)

See Also:
Target: x86_64-unknown-linux-gnu
Known to work: 4.0.0
Known to fail: 4.1.0 4.1.1
Last reconfirmed: 2006-06-26 22:24:39

reduced testcase (253 bytes, text/x-c++src)
2006-05-30 16:02 UTC, Volker Reichelt
modified testcase (264 bytes, text/x-c++src)
2006-05-31 11:07 UTC, Volker Reichelt

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2006-05-25 08:29:40 UTC
The following code crashes when I compile it with -O2 (mainline)


struct A
    std::vector<int> v;
    char             c;

struct B {};

int main()
    A a;
    A a2(a);
    std::vector<B*> b;
    return 0;

The program dies with:

*** glibc detected *** free(): invalid pointer: 0x00002aaaaabc0c60 ***
zsh: 13987 abort      a.out

I'll come up with a reduced testcase next week if nobody beats me.

Happens only with mainline, -O1 is not affected.
Comment 1 Volker Reichelt 2006-05-25 08:30:12 UTC
Btw, this is on x86_64-unknown-linux-gnu.
Comment 2 Andrew Pinski 2006-05-28 20:47:33 UTC
Something is removing the store to _M_start.

  this_252 = (struct _Vector_base<B*,std::allocator<B*> > *) &b;
  this_253 = this_252;
  #   VUSE <SMT.84_402>;
  D.13530_256 = this_252->_M_impl._M_start;

I think the cast there is causing the problem.
Comment 3 Andrew Pinski 2006-05-28 20:50:10 UTC
This is related to PR 19817, the C++ front-end is producing that construct which causes us not to constant prop zero.
Comment 4 Andrew Pinski 2006-05-28 20:52:11 UTC
But even without fixing PR 19817, it seems like the cast should be valid, or maybe not someone who knows if the cast is valid in C++ where the struct is not an inheirtance.
Comment 5 Volker Reichelt 2006-05-30 16:02:46 UTC
Created attachment 11539 [details]
reduced testcase
Comment 6 Volker Reichelt 2006-05-30 16:05:20 UTC
I think there's something hosed with aliasing.
The code crashes with -O2, but runs fine with -O2 -fno-strict-aliasing.
Comment 7 Andrew Pinski 2006-05-30 16:06:59 UTC
I already mentioned this is most likely a C++ front-end.
Comment 8 Volker Reichelt 2006-05-31 11:07:17 UTC
Created attachment 11550 [details]
modified testcase
Comment 9 Volker Reichelt 2006-05-31 11:13:00 UTC
The modified testcase from comment #8 should return 0,
but returns 255 (a.k.a -1) when compiled with -O2.

The bad news is that this also affects the 4.1 branch (4.1.0 and later).
The failure on the 4.1 branch is not reproducible with -m32
whereas mainline also crashes with -m32.

The testcase from comment #5 also crashes with 4.1.0 (without -m32),
but not with 4.1.1.
Comment 10 Wolfgang Bangerth 2006-06-15 03:45:16 UTC
This problem persists with gcc4.1.x from 2006-06-13. I believe I get the
same glibc fault in one of my codes, which isn't particularly surprising
given that Volker used widely used std:: components in his program as well...

Definitely an important bug!

Comment 11 Jason Merrill 2006-06-28 19:12:42 UTC
Turns out to be a bug in alias grouping.  Patch in testing.
Comment 12 Jason Merrill 2006-06-29 01:12:28 UTC
Subject: Bug 27768

Author: jason
Date: Thu Jun 29 01:12:20 2006
New Revision: 115062

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115062
        PR c++/27768
        * tree-ssa-alias.c (compute_flow_insensitive_aliasing): Add
        may_aliases already in the tag's annotations to the bitmap.


Comment 13 Andrew Pinski 2006-06-29 13:49:40 UTC
Fixed on the mainline at least.
Comment 14 Jason Merrill 2006-06-30 15:19:58 UTC
Subject: Bug 27768

Author: jason
Date: Fri Jun 30 15:19:50 2006
New Revision: 115090

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115090
        PR c++/27768
        * tree-ssa-alias.c (compute_flow_insensitive_aliasing): Add
        may_aliases already in the tag's annotations to the bitmap.

      - copied unchanged from r115062, trunk/gcc/testsuite/g++.dg/opt/alias4.C

Comment 15 Andrew Pinski 2006-06-30 15:25:45 UTC