This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[C++ PATCH]: Fix bug 2823


Hi,
I've committed this patch as the obvious fix for bug 2823. Installed on both
mainline and branch, as this is a regression.

We did tree based inlining on a thunk, and then an optimization in rtl
generation went awry and caused a TARGET_EXPR's cleanup to be erroneously
expanded. Fixed by not doing tree optimization on a thunk for reasons given
in the patch.

booted and tested on i686-pc-linux-gnu.

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-05-26  Nathan Sidwell  <nathan@codesourcery.com>

	PR g++/2823
	* semantics.c (expand_body): Don't optimize thunks.

Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/semantics.c,v
retrieving revision 1.189.2.11
diff -c -3 -p -r1.189.2.11 semantics.c
*** semantics.c	2001/05/13 07:10:21	1.189.2.11
--- semantics.c	2001/05/26 16:23:25
*************** expand_body (fn)
*** 2411,2418 ****
  
    timevar_push (TV_INTEGRATION);
  
!   /* Optimize the body of the function before expanding it.  */
!   optimize_function (fn);
  
    timevar_pop (TV_INTEGRATION);
    timevar_push (TV_EXPAND);
--- 2411,2423 ----
  
    timevar_push (TV_INTEGRATION);
  
!   /* Optimize the body of the function before expanding it.  We do not
!      optimize thunks, as (1) the backend tries to optimize the call to
!      the thunkee, (b) the tree based inliner breaks that optimization,
!      (c) virtual functions are rarely inlineable, and (d)
!      ASM_OUTPUT_MI_THUNK is there to DTRT anyway.  */
!   if (!DECL_THUNK_P (fn))
!     optimize_function (fn);
  
    timevar_pop (TV_INTEGRATION);
    timevar_push (TV_EXPAND);
// Special g++ Options: -O2
// 
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 26 May 2001 <nathan@codesourcery.com>

// Bug 2823. Inlineing the body of a thunk broke things. But that's
// rarely a sensible thing to do anyway.

#include <cstdio>
#include <cstdlib>

int objCount = 0;

struct Thing
{
  int count;

  Thing ();
  Thing (Thing const &src);
  
  ~Thing ();
  
};

Thing::Thing ()
  :count (0)
{
  objCount++;
  std::printf ("%p %s\n", (void *)this,__PRETTY_FUNCTION__);
}

Thing::Thing (Thing const &src)
  :count (0)
{
  objCount++;
  std::printf ("%p %s\n", (void *)this, __PRETTY_FUNCTION__);
}

Thing::~Thing ()
{
  std::printf ("%p %s\n", (void *)this, __PRETTY_FUNCTION__);
  if (count)
    std::abort ();
  count--;
  objCount--;
}

void x(Thing name)
{
  // destruct name here
}

class Base
{
  public:
  virtual void test(const Thing& s) = 0;
};

class Impl : virtual public Base
{
  public:
  virtual void test(const Thing& s)
  {
    x(s); // copy construct temporary
  }
};

int main()
{
  Impl *impl = new Impl();
  
  impl->test( Thing ());	// This will use a thunk
  return objCount != 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]