Bug 19817 - C++ front-end produces a cast instead of just &a.b (when call the destructor)
Summary: C++ front-end produces a cast instead of just &a.b (when call the destructor)
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: 27768
  Show dependency treegraph
 
Reported: 2005-02-08 05:46 UTC by Andrew Pinski
Modified: 2017-07-10 07:13 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-03-05 17:32:53


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-02-08 05:46:40 UTC
The following code should be optimizated out on the tree level but is not because we have a cast 
involved when calling the deconstuctor.
int t;
struct base { int i; ~base(){t = i;}};
struct vector : public base { vector(){ i = 2; }};
int f() { vector v; return t;}

extern "C" void abort ();

int main(void)
{
  t = 2;
  if (f() != 2)
   link_error ();
  if (t!= 2)
   link_error ();
  return 0;
}

This might be the case for PR 19786 but I don't know for sure.
Comment 1 Andrew Pinski 2005-02-20 14:18:33 UTC
Confirmed,  This seems stupid the front-end is doing this as casts get in the way of optimizations now.
Comment 2 Andrew Pinski 2005-03-10 18:17:13 UTC
The bug is in convert_to_base_statically.
Comment 3 Andrew Pinski 2007-04-15 01:05:31 UTC
Note this was fixed at the tree level by:
2007-04-08  Jan Hubicka  <jh@suse.cz>

        * tree.h (maybe_fold_offset_to_component_ref): Declare.
        * tree-ssa-ccp.c (maybe_fold_offset_to_component_ref): Export.
        * fold-const.c (fold_unary): Use it.

But The C++ front-end should not produce this to begin with.
Comment 4 Paolo Carlini 2013-08-27 09:59:21 UTC
Andrew, any idea about the current status of this? Note that maybe_fold_offset_to_component_ref doesn't exist anymore
Comment 5 Andrew Pinski 2017-07-10 07:13:42 UTC
This is not needed any more due to MEM_REF.