re PR c++/2823 (kde2/artsd miscompilation (part 1))
authorNathan Sidwell <nathan@codesourcery.com>
Sat, 26 May 2001 19:20:06 +0000 (19:20 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Sat, 26 May 2001 19:20:06 +0000 (19:20 +0000)
cp:
PR g++/2823
* semantics.c (expand_body): Don't optimize thunks.
testsuite:
* g++.old-deja/g++.other/optimize2.C: New file.

From-SVN: r42650

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.other/optimize2.C [new file with mode: 0644]

index e8ab948..2792f45 100644 (file)
@@ -1,3 +1,8 @@
+2001-05-26  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR g++/2823
+       * semantics.c (expand_body): Don't optimize thunks.
+
 2001-05-25  Sam TH  <sam@uchicago.edu>
 
        * cp-tree.h lex.h: Fix header include guards.
index fe62bc5..7425f98 100644 (file)
@@ -2397,8 +2397,13 @@ expand_body (fn)
 
   timevar_push (TV_INTEGRATION);
 
-  /* Optimize the body of the function before expanding it.  */
-  optimize_function (fn);
+  /* 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);
index 4495a34..1b785bc 100644 (file)
@@ -1,3 +1,7 @@
+2001-05-26  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.old-deja/g++.other/optimize2.C: New file.
+
 2001-05-25  Diego Novillo  <dnovillo@redhat.com>
 
        * gcc.c-torture/compile/20010518-2.c: New file.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/optimize2.C b/gcc/testsuite/g++.old-deja/g++.other/optimize2.C
new file mode 100644 (file)
index 0000000..8a62b32
--- /dev/null
@@ -0,0 +1,74 @@
+// 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;
+}