From 87d9ac4914ff104f8aa94053e34bae1ae0ecba58 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Sat, 26 May 2001 19:20:06 +0000 Subject: [PATCH] re PR c++/2823 (kde2/artsd miscompilation (part 1)) 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 | 5 ++ gcc/cp/semantics.c | 9 ++- gcc/testsuite/ChangeLog | 4 + .../g++.old-deja/g++.other/optimize2.C | 74 +++++++++++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.other/optimize2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e8ab9483fe2..2792f45fd10 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2001-05-26 Nathan Sidwell + + PR g++/2823 + * semantics.c (expand_body): Don't optimize thunks. + 2001-05-25 Sam TH * cp-tree.h lex.h: Fix header include guards. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index fe62bc5420e..7425f98f67c 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4495a34bbef..1b785bc9e18 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-05-26 Nathan Sidwell + + * g++.old-deja/g++.other/optimize2.C: New file. + 2001-05-25 Diego Novillo * 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 index 00000000000..8a62b32233f --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/optimize2.C @@ -0,0 +1,74 @@ +// Special g++ Options: -O2 +// +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 May 2001 + +// Bug 2823. Inlineing the body of a thunk broke things. But that's +// rarely a sensible thing to do anyway. + +#include +#include + +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; +} -- 2.30.2