C++ aliasing rules
Dan Nicolaescu
dann@godzilla.ICS.UCI.EDU
Wed Apr 3 11:03:00 GMT 2002
Hi!
I would need some expert C++ advice.
struct first { int i; char a; int f1; char f2; double d;};
struct second { char b; int f2; int f3;};
void f (struct first * ps1, struct second * ps2)
{
ps1->f1++;
ps2->f2++;
ps1->f1++;
ps2->f2++;
}
can it be assumed that given that "first" and "second" are
incompatible then ps1.f1 and ps2.f2 don't alias and we can generate
code like the following: (SPARC assembly)
!#PROLOGUE# 0
!#PROLOGUE# 1
ld [%o1+8], %o0
ld [%o2+4], %o3
add %o0, 2, %o0
add %o3, 2, %o3
st %o0, [%o1+8]
retl
st %o3, [%o2+4]
instead of what is generated now:
!#PROLOGUE# 0
!#PROLOGUE# 1
ld [%o0+8], %o3
add %o3, 1, %o3
st %o3, [%o0+8]
ld [%o1+4], %o2
add %o2, 1, %o2
st %o2, [%o1+4]
ld [%o0+8], %o3
add %o3, 1, %o3
st %o3, [%o0+8]
ld [%o1+4], %o0
add %o0, 1, %o0
retl
st %o0, [%o1+4]
The more general question is if 2 COMPONENT_REFs that refer to classes
that are in conflicting alias sets (ie alias_sets_conflict_p) can
alias in C++. I have a hunch that this might be true, but I want to
make sure... If the above is not true, is there a restricted case
when it is true?
(for the curious this is related to the patch at
http://gcc.gnu.org/ml/gcc-patches/2002-03/msg01869.html that proved to
not be needed for java, but the framework might be used for C++.
For some reason it is not totally correct for C, but I have a hunch
that it might be OK for C++.
Thanks.
--dan
More information about the Libstdc++
mailing list