1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
3
4 /* Test provided by Brian Ryner in PR 14511. The alias analyzer was
5 not handling structures containing arrays properly. In this case,
6 the static cast was introducing two assignments of the form
7
8 this_6->_vptr.IFoo = &_ZTV4IFoo[2];
9 this_4->_vptr.IFoo = &_ZTV3Bar[2];
10
11 which were not considered to alias each other because the alias
12 analyzer was not computing a proper pointer to array elements.
13 Another related bug was the type based alias analyzer not computing
14 alias relations to _ZTV4IFoo and _ZTV3Bar. Since those variables
15 are read-only, it was disregarding alias information for them.
16 So, the memory tags for the two 'this' variables were not being
17 marked as aliased with these variables. Resulting in the two
18 assignments not aliasing each other.
19
20 This was causing the optimizers to generate a call to the virtual
21 method Foo() instead of the overloaded version. */
22
23 struct IFoo
24 {
25 virtual void Foo() = 0;
26 };
27
28 struct Bar : IFoo
29 {
FooBar30 void Foo() { }
31 };
32
main(int argc,char ** argv)33 int main(int argc, char **argv)
34 {
35 Bar* b = new Bar();
36 static_cast<IFoo*>(b)->Foo();
37 return 0;
38 }
39