This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/22486] New: Upcasts are not folded away
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Jul 2005 13:19:11 -0000
- Subject: [Bug tree-optimization/22486] New: Upcasts are not folded away
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
In C++, a common idiom is to use upcasting to traverse the inheritance
hierarchy "backwards". F.i. the following simple code
template <class T>
struct Base {
const T& unwrap() const { return *(static_cast<const T *>(this)); }
int data[2];
};
struct Object;
struct Object : Base<Object>
{
int get(int i) const { return data[i]; }
};
int foo(const Base<Object>& o)
{
return o.unwrap().get(0) + o.unwrap().get(1);
}
which currently is (not) optimized to
;; Function int foo(const Base<Object>&) (_Z3fooRK4BaseI6ObjectE)
int foo(const Base<Object>&) (o)
{
struct Object & D.1752;
<bb 0>:
D.1752 = (struct Object *) o;
return D.1752->D.1743.data[0] + D.1752->D.1743.data[1];
}
should not have the cast and just access o->data[0] and o->data[1]
directly.
--
Summary: Upcasts are not folded away
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P2
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rguenth at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22486