On 03/12/2013 07:21 PM, Krzysztof Parzyszek wrote:> On 3/12/2013 12:13 PM, Manman Ren wrote: > > > > Given > > struct A { > > int x; > > int y; > > }; > > struct B { > > A a; > > int z; > > }; > > struct C { > > B b1; > > B b2; > > }; > > struct D { > > C c; > > }; > > > > with struct-access-path aware TBAA, C::b1.a.x does not alias with > D::c.b2.a.x. > > without it, the 2 scalar accesses can alias since both have int type. > > I browsed the 2012 standard for a while and I didn't see anything that > would make this illegal: > > char *p = malloc(enough_bytes); > intptr_t x = reinterpret_cast<intptr_t>(p); > x += offsetof(C, b2); > D &vd = *reinterpret_cast<D*>(p); > C &vc = *reinterpret_cast<C*>(x); > vd.c.b2.a.x = 1; // ..accessing the same > int t = vc.b1.a.x; // ..storage > > I don't think that the path through the type structure is really > sufficient. > > -Krzysztof >Not 100% sure your point here, but I think you are likely arguing TBAA is not sufficiently safe. True for this case. However, in this case, TBAA is not supposed to kick in to disambiguate these two access because the base/offset/size rule is supposed to give a definite answer if these two access *definitely* alias or *definitely* not alias. Note that, to make base/offset/size more effective, analyzer need to track the base along the UD chains as far as possible. In this case, the "bases" for the memory are "p", instead of &vd and &vc, respectively.
Krzysztof Parzyszek
2013-Mar-13 02:48 UTC
[LLVMdev] PROPOSAL: struct-access-path aware TBAA
On 3/12/2013 9:43 PM, Shuxin Yang wrote:> > Note that, to make base/offset/size more effective, analyzer need to > track the base along the UD chains > as far as possible. In this case, the "bases" for the memory are "p", > instead of &vd and &vc, respectively.If the base pointers are the same, then offset+length for each access is sufficient to determine aliasing. No type information is needed for this. I'm still not sure exactly what this proposal is supposed to address, but yes---given two base pointers (possibly not equal), the structural paths to the accessed objects are not sufficient. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Krzysztof Parzyszek
2013-Mar-13 02:52 UTC
[LLVMdev] PROPOSAL: struct-access-path aware TBAA
On 3/12/2013 9:48 PM, Krzysztof Parzyszek wrote:> > [...] the structural paths to the accessed objects are not sufficient.This is assuming that there isn't anything in the C++ standard that I missed. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Based on my understanding of her design, following is one obtuse motivating example: -------------------------- class A; class B; int foo(A* p, B* q) { p->a_int_field = 2; q->another_int_field = 3; return p->a_int_field; // !!!!! } ---------------------------------- the *-statement can be optimized into "return 2" if optimizer can prove type-A does not include type-B, and type-B does not include type-A either. On 03/12/2013 07:48 PM, Krzysztof Parzyszek wrote:> On 3/12/2013 9:43 PM, Shuxin Yang wrote: >> >> Note that, to make base/offset/size more effective, analyzer need to >> track the base along the UD chains >> as far as possible. In this case, the "bases" for the memory are "p", >> instead of &vd and &vc, respectively. > > If the base pointers are the same, then offset+length for each access > is sufficient to determine aliasing. No type information is needed > for this. I'm still not sure exactly what this proposal is supposed > to address, but yes---given two base pointers (possibly not equal), > the structural paths to the accessed objects are not sufficient. > > -Krzysztof > >