This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: DWARF question/inlining/local classes




--On Wednesday, October 30, 2002 04:44:12 PM -0800 Geoff Keating <geoffk@geoffk.org> wrote:

Mark Mitchell <mark@codesourcery.com> writes:

PR 8391 contains this code:

   inline void h(const Outer &o)
   {
     struct Local : public Outer::Inner {
	 virtual bool f() {};
     };
     Local l;
     o.g(l);
   }

When we try to emit the body of Local::f (the function in the struct
inside h), we don't actually emit assembly code because of this code
in rest_of_compilation:

      /* If this is nested inside an inlined external function, pretend
	 it was only declared.  Since we cannot inline such functions,
	 generating code for this one is not only not necessary but will
	 confuse some debugging output writers.  */
      for (parent = DECL_CONTEXT (current_function_decl);
	   parent != NULL_TREE;
	   parent = get_containing_scope (parent))
	if (TREE_CODE (parent) == FUNCTION_DECL
	    && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
	  {
	    DECL_INITIAL (decl) = 0;
	    goto exit_rest_of_compilation;
	  }

This logic is wrong for C++; we need to emit Local::f.
I believe the rationale behind this code is that Local::f can't be
used from this translation unit, since the function won't be inlined.
It will be emitted when the out-of-line copy of the function is emitted.

Will this function really not be inlined?
The function will indeed be inlined in this translation unit.

That is consistent with the GNU C "extern inline" extension; the
definition will be used *only* for inlining.

However, Local::f is not a "nested function" in the GNU C sense; while
it is lexically scoped within h, it is not in any way dependent on
the stack frame of h as it operates.

--
Mark Mitchell                mark@codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com


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