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: GCC tree linkage types


On Sun, 26 Oct 2003, Richard Henderson wrote:
> On Sun, Oct 26, 2003 at 02:34:40PM -0600, Chris Lattner wrote:
> > Given a FUNCTION_DECL, how do I tell if it is "linkonce"?
> DECL_ONE_ONLY.
> > Is there any way to tell if something is an explicitly instantiated
> > template...
> Yes, but I'm not sure what it is.  It might be !linkonce.

Ok, it looks like my problems are due to a combination of explicitly
instantiated templates and "external" templates.  It looks like I need to
be able to tell when a DECL_ONE_ONLY function is part of an explicit
template instantiation of an external template.  (gack)!

For example, take this translation unit:

---
template<class T>
struct Test {
  void func() {}
};

extern template class Test<int>;

extern Test<int> X;
int test() {
  X.func();
}
---

For this translation unit, the 'func' function is assumed to be externally
available, due to the 'extern template', so no inline version of the
function is emitted.  Consider the explicit instantiation now:

---
template<class T>
struct Test {
  void func() {}
};

extern template class Test<int>;
template struct Template<int>;
---

Here we recognize that we have to emit the function in this translation
unit, but DECL_ONE_ONLY is set on the function, so it is marked link-once,
and deleted by the optimizer (it is not used in this translation unit).
It looks like I have to recognize the fact that this is an explicit
instantiation of an external'ed template, so the otherwise DECL_ONE_ONLY
function should really be defined with normal, strong, external linkage.

Do you happen to know how to detect this?  :)

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/




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